# Expand Individual-varying covariates in models

### Description

Expands a vector of individual-varying values into a 2-d matrix of the appropriate size for use in MRA model formulas.

### Usage

1 |

### Arguments

`x` |
The vector of individual varying values to expand. This can be
a factor (see |

`ns` |
Number of sampling occasions. Default is to use the 'ns' attribute
of |

`drop.levels` |
A vector of integers specifying which levels of a factor
to drop. Only applicable if |

### Value

A 2-d matrix of size `length(x)`

x `ns`

suitable for passing to the
Fortran DLL of MRA for estimation. Values within rows are contant, values
across rows 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`

).

### Author(s)

Trent McDonald, WEST-INC, tmcdonald@west-inc.com

### See Also

`F.cjs.estim`

, `tvar`

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ```
nan <- 30
ns <- 5
age <- as.factor(sample( c("J","S1","S2","Adult"), size=nan, replace=TRUE ))
attr(age,"ns") <- ns
# Note that levels get reordered (by R default, alphabetically)
attr(age,"drop.levels") <- (1:length(levels(age)))[ levels(age) == "J" ]
age.mat <- ivar(age) # level J is the reference
age.mat <- ivar(age, drop=4) # level S2 is the reference
# Look at 3-D matrix produced when called with a factor.
dim(age.mat) <- c(nan,ns,length(levels(age))-1)
print(age.mat) # each page is the 2-d matrix used in the fit.
print(age.mat[1,,])
age.mat <- ivar(age, drop=c(3,4)) # level S1 and S2 are combined and are the reference
# compare above to
ivar( c(1,1,2,2,3,3), 5 )
``` |