tvctomat               package:rmutil               R Documentation

_C_r_e_a_t_e _a _T_i_m_e-_v_a_r_y_i_n_g, _I_n_t_r_a-_i_n_d_i_v_i_d_u_a_l _C_o_v_a_r_i_a_t_e (_t_v_c_o_v) _O_b_j_e_c_t

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

     'tvctovmat' creates an object of class, 'tvcov', from a list of
     matrices with time-varying or intra-individual covariates for each
     individual or one matrix or dataframe of such covariate values. It
     can also combine two such objects or add interactions among
     covariates.

     Such objects can be printed. Methods are available for extracting
     the covariates and their names: 'covariates' and 'names'. The
     method, 'transform', can transform variables in place or by adding
     new variables to the object.

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

     tvctomat(tvcov, names=NULL, units=NULL, interaction=NULL, ccov=NULL,
             oldtvcov=NULL, dataframe=TRUE, description=NULL)

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

   tvcov: Either (1) if unbalanced, a list of matrices or dataframes
          with time-varying or intra-individual covariate values for
          each individual (one column per variable), (2) if balanced,
          one matrix or dataframe of such covariate values (when there
          is only one such covariate) with dimensions: number of
          individuals by number of observations/individual, or (3) an
          object of class, 'tvcov'. In the first two cases, the
          variables may be factors; if 'dataframe=FALSE', these are
          transformed to indicator variables.

   names: The names of the time-varying or intra-individual covariates
          in 'tvcov' (if the matrices do not have column names) or the
          names of the time-constant covariates for which interactions
          are to be created.

   units: Optional character vector specifying units of measurements of
          covariates.

interaction: A pair of index numbers or names of variables in 'tvcov',
          with that class, for which an interaction is to be added or,
          if 'ccov' is provided, a set of such names of time-varying or
          intra-individual covariates for creating interactions with
          the time-constant covariates.

    ccov: Time-constant or inter-individual covariates for which an
          interaction is to be introduced with time-varying or
          intra-individual covariates in 'tvcov'.

oldtvcov: An object of class, 'tvcov', to which 'tvcov' is to be added.

dataframe: If TRUE and factor variables are present, the covariates are
          stored as a dataframe; if FALSE, they are expanded to
          indicator variables. If no factor variables are present,
          covariates are always stored as a matrix.

description: An optional named list of character vectors with names of
          some or all covariates containing their descriptions.

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

     Returns an object of class, 'tvcov', containing a matrix or
     dataframe for the covariates ('z$tvcov') with one row per response
     per individual and a vector giving the number of observations per
     individual ('z$nobs').

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

     J.K. Lindsey

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

     'DataMethods', 'covariates', 'description', 'formula', 'gettvc',
     'lvna', 'names', 'restovec', 'rmna', 'tcctomat', 'transform',
     'units'

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

     z <- matrix(rpois(20,5),ncol=5)
     print(tvc <- tvctomat(z, units="days"))
     covariates(tvc)
     names(tvc)
     v <- data.frame(matrix(rep(c("a","b","c","d","e"),4),ncol=5))
     print(tvc2 <- tvctomat(v, oldtvc=tvc, units=NA))
     covariates(tvc2)
     print(tvc3 <- tvctomat(v, oldtvc=tvc, dataframe=FALSE, units=NA))
     covariates(tvc3)
     print(tvc4 <- tvctomat(tvc2, interaction=c("z","v")))
     covariates(tvc4)
     x1 <- 1:4
     x2 <- gl(4,1)
     xx <- tcctomat(data.frame(x1,x2), dataframe=FALSE)
     tvctomat(tvc3, interaction="z", ccov=xx)
     tvctomat(tvc3, interaction="z", ccov=xx, names="x1")
     tvctomat(tvc3, interaction="z", ccov=xx, names=c("x22","x23","x24"))
     xx <- tcctomat(data.frame(x1,x2), dataframe=TRUE)
     tvctomat(tvc2, interaction="z", ccov=xx)
     tvctomat(tvc2, interaction="z", ccov=xx, names="x1")
     tvctomat(tvc2, interaction="z", ccov=xx, names="x2")

