mkterm                  package:gss                  R Documentation

_A_s_s_e_m_b_l_i_n_g _M_o_d_e_l _T_e_r_m_s _f_o_r _S_m_o_o_t_h_i_n_g _S_p_l_i_n_e _A_N_O_V_A _M_o_d_e_l_s

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

     Assemble numerical functions for calculating model terms in a
     smoothing spline ANOVA model.

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

     mkterm(mf, type)

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

      mf: Model frame of the model formula.

    type: List specifying the type of spline for each variable.

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

     For a *factor* 'x', 'type$x' is ignored; 'mkrk.ordinal' is used if
     'is.ordered(x)==TRUE' and 'mkrk.nominal' is used otherwise. 
     Factors with 3 or more levels are penalized.

     For a *numerical vector* 'x', 'type$x' is of the form 'type.x' for
     'type.x'='"cubic"', '"linear"', or of the form 'list(type.x,
     range)' for 'type.x'='"per"', '"cubic.per"', '"linear.per"',
     '"cubic"', '"linear"'; '"per"' is short for '"cubic.per"'.  See
     'mkfun.poly' for the functions used.  For 'type.x' missing, the
     *default* is '"cubic"'. For 'range' missing with
     'type.x'='"cubic"', '"linear"', the *default* is
     'c(min(x),max(x))+c(-1,1)*(max(x)-mimn(x))*.05'.

     For a *numerical matrix* 'x', 'type$x' is of the form 'type.x' or
     'list(type.x, order)' for 'type.x'='"tp"', '"sphere"', or of the
     form 'list("tp",list(order=order,mesh=mesh,weight=weight))'.  See
     'mkfun.tp' for the functions used.  For 'type.x' missing, the
     *default* is '"tp"'.  For 'order' missing, the *default* is '2'. 
     For 'mesh' and 'weight' missing with 'type.x'='"tp"' and 'order'
     given, the *defaults* are 'mesh'='x' and 'weight'='1'.

     For a *numerical vector* or *numerical matrix* 'x', one may also
     use 'type$x' of the form
     'list("custom",list(nphi=nphi,mkphi=mkphi,mkrk=mkrk,env=env))';
     'nphi' is the null space dimension _excluding the constant_, and
     'mkphi' is ignored if 'nphi'=0.  See examples below.  This feature
     allows the use of other marginal constructions; one may modify
     'mkphi.cubic' or 'mkphi.tp.p' for 'mkphi' and modify 'mkrk.cubic'
     or 'mkrk.sphere' for 'mkrk'.

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

     A list object with a component 'labels' containing the labels of
     all model terms.  For each of the model terms, there is a
     component holding the numerical functions for calculating the
     unpenalized and penalized parts within the term.

_B_a_c_k_g_r_o_u_n_d:

     Tensor-product splines are constructed based on the model formula
     and the marginal reproducing kernels, as described in Gu (2002,
     Sec. 2.4).  The marginal variables can be factors, numerical
     vectors, and numerical matrices, as specified in the details
     section.

     One-way ANOVA decompositions are built in the supported marginal
     constructions, in which one has the constant, a "nonparametric
     contrast," and possibly also a "parametric contrast."  To the
     "nonparametric contrast" there corresponds a reproducing kernal
     'rk', and to a "parametric contrast" there corresponds a set of
     null space basis 'phi'.  The reproducing kernels and null space
     basis on the product domain can be constructed from the marginal
     'rk' and 'phi' in a systematic manner.

     The marginal one-way ANOVA structures induce a multi-way ANOVA
     structure on the product domain, with model terms consisting of
     unpenalized "parametric contrasts" and/or penalized "nonparametric
     contrasts."  One only needs to construct 'rk''s and 'phi''s
     associated with the model terms implied by the model formula.

_N_o_t_e:

     For a *numerical vector* 'x' in 'ssden', the default 'range' is
     'domain$x'.

     For a *numerical matrix* 'x' with 'type.x'='"sphere"', it is
     assumed that 'dim(x)[2]==2', 'x[,1]' between [-90,90] the latitude
     in degrees, and 'x[,2]' between [-180,180] the longitude in
     degrees.

     For *backward compatibility*, one may set 'type="cubic"',
     '"linear"', or '"tp"', but then the default parameters can not be
     overridden; the type is simply duplicated for each variable.

_A_u_t_h_o_r(_s):

     Chong Gu, chong@stat.purdue.edu

_R_e_f_e_r_e_n_c_e_s:

     Gu, C. (2002), _Smoothing Spline ANOVA Models_.  New York:
     Springer-Verlag.

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

     ## cubic marginals
     x1 <- rnorm(100); x2 <- rnorm(100); y <- 3+5*sin(x1-2*x2)+rnorm(x1)
     fit <- ssanova0(y~x1*x2)
     ## the same fit
     fit1 <- ssanova0(y~x1*x2,type=list(x1="cubic"))
     ## the same fit one more time
     par <- list(nphi=1,mkphi=mkphi.cubic,mkrk=mkrk.cubic,
                 env=c(min(x2),max(x2))+c(-1,1)*(max(x2)-min(x2))*.05)
     fit2 <- ssanova0(y~x1*x2,type=list(x2=list("custom",par)))
     ## Clean up
     ## Not run: rm(x1,x2,y,fit,fit1,par,fit2)

     ## cubic and thin-plate marginals
     x1 <- rnorm(100); x2 <- matrix(rnorm(200),100,2)
     y <- 3+5*sin(x1-2*x2[,1]*x2[,2])+rnorm(x1)
     fit <- ssanova0(y~x1*x2)
     ## the same fit
     fit1 <- ssanova0(y~x1*x2,type=list(x2="tp"))
     ## the same fit one more time
     mkphi.tp1 <- function(x) mkphi.tp(x$dm,x$ord,x$mesh,x$wt)
     mkrk.tp1 <- function(x) mkrk.tp(x$dm,x$ord,x$mesh,x$wt)
     env <- list(dm=2,ord=2,mesh=x2,wt=1)
     par <- list(nphi=2,mkphi=mkphi.tp1,mkrk=mkrk.tp1,env=env)
     fit2 <- ssanova0(y~x1*x2,type=list(x2=list("custom",par)))
     ## Clean up
     ## Not run: rm(x1,x2,y,fit,fit1,mkphi.tp1,mkrk.tp1,env,par,fit2)

