matrices2long | R Documentation |
Function to convert data with array format in data with long format.
matrices2long(Y, X1 = NULL, X2 = NULL)
Y |
array of responses ( |
X1 |
array of covariates ( |
X2 |
array of covariates ( |
Y
, X1
and X2
must have the same number of observations.
Returns a data.frame
with data in long format. The first column indicates the name of the unit identifier, and the second column indicates the time occasions.
Francesco Bartolucci, Silvia Pandolfi, Fulvia Pennoni, Alessio Farcomeni, Alessio Serafini
### Example with data on self rated health
data(data_SRHS_long)
SRHS <- data_SRHS_long[1:1600,]
# Covariates
X <- cbind(SRHS$gender-1,
SRHS$race == 2 | SRHS$race == 3,
SRHS$education == 4,
SRHS$education == 5,
SRHS$age-50,
(SRHS$age-50)^2/100)
# Responses
Y <- SRHS$srhs
res <- long2matrices(SRHS$id, X = X, Y = Y)
long <- matrices2long(Y = res$YY, X1 = res$XX)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.