long2matrices: From data in the long format to data in array format

Description Usage Arguments Value Author(s) Examples

View source: R/long2matrices.R

Description

Function that transforms data in the long format to data in array format.

Usage

1
long2matrices(id, time = NULL, X = NULL, Y)

Arguments

id

vector of subjects id

time

vector of time occasions

X

matrix of covariates in long format

Y

matrix of responses in long format

Value

XX

array of covariates (n x TT x nc)

YY

array of responses (n x TT x r)

Author(s)

Francesco Bartolucci, Silvia Pandolfi, University of Perugia (IT), http://www.stat.unipg.it/bartolucci

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Example based on SRHS data

# load SRHS data
data(data_SRHS_long)
dataSRHS <- data_SRHS_long[1:1600,]
head(dataSRHS)
X <- cbind(dataSRHS$gender-1, dataSRHS$race == 2 | dataSRHS$race == 3,
dataSRHS$education == 4,dataSRHS$education == 5, dataSRHS$age-50,
(dataSRHS$age-50)^2/100)
Y <- dataSRHS$srhs
res <- long2matrices(dataSRHS$id, X = X, Y = Y)

Example output

Package 'LMest' version 3.0.0
  t id gender race education age srhs
1 1  1      1    1         3  56    4
2 2  1      1    1         3  58    4
3 3  1      1    1         3  60    3
4 4  1      1    1         3  62    3
5 5  1      1    1         3  64    4
6 6  1      1    1         3  66    3

LMest documentation built on Oct. 10, 2021, 1:09 a.m.