restovec | R Documentation |
restovec
can produce an object of class, response
, from
a vector of (1) independent univariate responses or (2) a single time
series.
It can produce such an object from repeated measurements in the form of (1) a list of vectors of event histories, (2) a list of two or more column matrices with times, response values, and and other information or (3) a matrix or dataframe of response values. The first two are for unbalanced data and the third for balanced data.
Multivariate responses can be supplied as (1) a three-dimensional array of balanced repeated measurements, (2) lists of matrices for unbalanced repeated measurements, or (3) a matrix with either (a) several time series or (b) single observations per individual on several variables.
In formula and functions, the key words, times
can be used to
refer to the response times from the data object as a covariate,
individuals
to the index for individuals as a factor covariate,
and nesting
the index for nesting as a factor covariate. The
latter two only work for W&R notation.
NAs can be detected with lvna
or removed with
rmna
(where necessary, in coordination with the
appropriate covariates) to create a repeated
object.
response
objects can be printed and plotted. Methods are
available for extracting the response, the numbers of observations per
individual, the times, the weights, the units of measurement/Jacobian,
and the nesting variable: response
,
nobs
, times
,
weights
, delta
, and
nesting
.
The response and or the times may be transformed using
transform(z, newy=fcn1(y), times=fcn2(times))
where
fcn1
and fcn2
are transformations and y
is the
name of a response variable. When the response is
transformed, the Jacobian is automatically calculated. Note that, if
the unit of precision/Jacobian (delta
) is available in
the response
object, this is automatically included in the
calculation of the likelihood function in all library model functions.
restovec(response=NULL, times=NULL, nest=NULL, coordinates=NULL, censor=NULL, totals=NULL, weights=NULL, delta=NULL, type=NULL, names=NULL, units=NULL, oldresponse=NULL, description=NULL)
response |
For (1) independent univariate responses with one observation per individual or (2) a single time series, one vector may be supplied (in the latter case, the times must be given even if equally spaced). Univariate repeated measurements responses can be given (1) if
balanced, as a matrix or dataframe of response values with dimensions:
number of individuals by number of responses/individual, (2) a list of
vectors of event histories, or (3) a list of one or more column
matrices, for each individual, with response values in the first
column and times in the second (if there are no times, set
Multivariate responses can be supplied as (1) a three-dimensional
array of balanced repeated measurements with dimensions: number of
individuals by number of responses/individual by number of variables,
(2) a list of matrices for unbalanced repeated measurements each with
dimensions: number of responses on that individual by number of
variables, plus a column for times if available (otherwise set
|
times |
When |
nest |
This is the second level of nesting, with the individual being the first level. Values for an individual must be consecutive increasing integers with all responses in the same cluster grouped together. For example, with three clusters of four observations each, the code would be 1,1,1,1,2,2,2,2,3,3,3,3. When If When |
coordinates |
When |
censor |
When When If For event history data, even with no censoring, an appropriate vector of ones must be supplied. When |
totals |
If the response is a matrix of binomial counts, this can be (1) a corresponding vector (one total per individual) or (2) a matrix of totals. When If When |
weights |
A vector, matrix, array, or list of vectors of
frequencies or weights, with one value per |
delta |
For continuous measurements, the unit of precision (if
not equal to unity) for each response: a scalar, vector, matrix,
array, or list of the same dimensions as |
type |
The type(s) of observations: nominal, ordinal, discrete,
duration, continuous, or unknown. If not specified otherwise, those
responses with |
names |
Optional name(s) of the response variable(s). |
units |
Optional character vector giving units of measurement of response(s). |
oldresponse |
An existing |
description |
An optional named list of character vectors with names of some or all response variables containing their descriptions. |
Returns an object of class, response
, containing a vector with the
responses (z$y
), a corresponding vector of times (z$times
) if
applicable, a vector giving the number of observations per individual
(z$nobs
, set to a scalar 1 if observations are independent),
type (z$delta
), and possibly binomial totals (z$n
),
nesting (clustering, z$nest
), censoring (z$censor
),
weights (z$wt
), unit of precision/Jacobian (z$delta
),
units of measurement (z$units
), and description
(z$description
) information.
J.K. Lindsey
DataMethods
, covind
,
delta
, description
,
lvna
, names
,
nesting
, nobs
,
read.list
, read.surv
,
response
, resptype
,
rmna
, tcctomat
,
times
, transform
,
tvctomat
, units
,
weights
# #continuous response y <- matrix(rnorm(20),ncol=5) # times assumed to be 1:5 restovec(y, units="m") #unequally-spaced times tt <- c(1,3,6,10,15) print(resp <- restovec(y, times=tt, units="m", description=list(y="Response measured in metres"))) response(resp) response(resp, nind=2:3) response(transform(resp, y=1/y)) transform(resp, y=1/y, units="1/m") units(resp) description(resp) times(resp) times(transform(resp, times=times-6)) nobs(resp) weights(resp) nesting(resp) # because individuals are the only nesting, this is the same as covind(resp) # # binomial response y <- matrix(rpois(20,5),ncol=5) # responses summarized as relative frequencies print(respb <- restovec(y, totals=y+matrix(rpois(20,5),ncol=5), times=tt)) response(respb) # # censored data y <- matrix(rweibull(20,2,5),ncol=5) print(respc <- restovec(y, censor=matrix(rbinom(20,1,0.9),ncol=5), times=tt)) # if there is no censoring, censor indicator is not printed response(respc) # nesting clustered within individuals nest <- c(1,1,2,2,2) print(respn <- restovec(y, censor=matrix(rbinom(20,1,0.9),ncol=5), times=tt,nest=nest)) response(respn) times(respn) nesting(respn) # # multivariate response restovec(y, censor=matrix(rbinom(20,1,0.9),ncol=5), units=c("m","days","l","cm","mon"), type=c("continuous","duration","continuous","continuous","duration"), description=list(y1="First continuous variable", y2="First duration variable",y3="Second continuous variable", y4="Third continuous variable",y5="Second duration variable")) restovec(y, censor=matrix(rbinom(20,1,0.9),ncol=5), names=c("a","b","c","d","e"), units=c("m","days","l","cm","mon"), type=c("continuous","duration","continuous","continuous","duration"), description=list(a="First continuous variable", b="First duration variable",c="Second continuous variable", d="Third continuous variable",e="Second duration variable"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.