tvar {mra} | R Documentation |
Expands a vector of time-varying values into a 2-d matrix for use in MRA model formulas.
tvar(x, nan=attr(x,"nan"), drop.levels=attr(x,"drop.levels"))
x |
The vector of time varying values to expand. This can be
a factor (see |
nan |
Number of individuals. Default is to use the 'nan' attribute
of |
drop.levels |
A vector of integers specifying which levels of a factor
to drop. Only applicable if |
A 2-d matrix of size nan
x length(x)
suitable for passing to the
Fortran DLL of MRA for estimation. Values within columns are constant, values
across columns vary according to x
. If x
is a factor, this matrix
contains 0-1 indicator functions necessary to fit the factor.
If x
is a factor, attributes of the returned matrix are
"levels" = levels of the factor and "contr" = contrasts used in the coding (always
contr.treatment
). For other contrast coding of factors, make your own
2-d matrix with a call to the appropriate function (like contr.poly
).
Trent McDonald, WEST-INC, tmcdonald@west-inc.com
nan <- 30 ns <- 5 time.occ <- as.factor(paste("T",1:ns, sep="")) attr(time.occ,"nan") <- nan attr(time.occ,"drop.levels") <- ns time.mat <- tvar(time.occ) # Last occasion is the reference, the SAS and MARK default. time.mat <- tvar(as.factor(1:ns),nan,ns) #equivalent to above. # Look at 3-d matrix produced when called with factors dim(time.mat) <- c(nan,ns,length(levels(time.occ))-1) print(time.mat) # each page is the 2-d matrix used in the fit. print(time.mat[1,,]) # compare above to tvar( 1:ns, nan )