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' and 'ns' in package
     'splines', 'cars'

_E_x_a_m_p_l_e_s:

     ## using poly: this did not work in R < 1.5.0
     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.

