makepredictcall            package:stats            R Documentation

_U_t_i_l_i_t_y _F_u_n_c_t_i_o_n _f_o_r _S_a_f_e _P_r_e_d_i_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     A utility to help 'model.frame.default' create the right matrices
     when predicting from models with terms like 'poly' or 'ns'.

_U_s_a_g_e:

     makepredictcall(var, call)

_A_r_g_u_m_e_n_t_s:

     var: A variable.

    call: The term in the formula, as a call.

_D_e_t_a_i_l_s:

     This is a generic function with methods for 'poly', 'bs' and 'ns':
     the default method handles 'scale'.  If 'model.frame.default'
     encounters such a term when creating a model frame, it modifies
     the 'predvars' attribute of the terms supplied to replace the term
     with one that will work for predicting new data.  For example
     'makepredictcall.ns' adds arguments for the knots and intercept.

     To make use of this, have your model-fitting function return the
     'terms' attribute of the model frame, or copy the 'predvars'
     attribute of the 'terms' attribute of the model frame to your
     'terms' object.

     To extend this, make sure the term creates variables with a class,
     and write a suitable method for that class.

_V_a_l_u_e:

     A replacement for 'call' for the 'predvars' attribute of the
     terms.

_S_e_e _A_l_s_o:

     'model.frame', 'poly', 'scale', 'bs', 'ns', 'cars'

_E_x_a_m_p_l_e_s:

     ## using poly: this did not work in R < 1.5.0
     data(women)
     fm <- lm(weight ~ poly(height, 2), data = women)
     plot(women, xlab = "Height (in)", ylab = "Weight (lb)")
     ht <- seq(57, 73, len = 200)
     lines(ht, predict(fm, data.frame(height=ht)))

     ## see also example(cars)

     ## see bs and ns for spline examples.

