Learn R Programming

BaSTA (version 1.3)

MakeCovMat: Function to build a matrix of covariates (i.e. design matrix) for a Bayesian Survival Trajectory Analysis (BaSTA) analysis.

Description

This function creates a matrix of covariates or design matrix appropriate for BaSTA from raw individual level covariate data. The function identifies categorical and continuous covariates and organizes them accordingly.

Usage

MakeCovMat(x, data)

Arguments

x
A character string vector or a numerical vector indicating the columns to be included or an object of class formula.
data
A data frame of n rows (n = number of individuals in dataset) and nz columns (number of general covariates) including categorical covariates as factors (e.g. sex with individual labels "f","m", location, etc.) and/or continuous individual covariates (e.g.

Value

  • The function returns a new covariate matrix to be collated to a matrix that includes a column for individual ID, a column for time of birth, and a column for times of death, plus the full recapture matrix.

Details

The x argument can be of class character, numeric or formula as long as the elements described correspond to the column names in the data data frame. The data frame specified in argument data needs to explicitly differentiate between categorical and numerical variables. The elements in the column of a categorical variable must be coerced to be factors.

See Also

basta

Examples

Run this code
## Simulated sex and weight data for 5 individuals:
sex        <- sample(c("f", "m"), 5, replace = TRUE)
weight     <- rnorm(5, mean = 10, sd = 1)
raw.mat    <- data.frame(sex, weight)
new.mat    <- MakeCovMat(~sex + weight, data = raw.mat)

Run the code above in your browser using DataLab