transformCatCov: Transform covariates

View source: R/SaemixData.R

transformCatCovR Documentation

Transform covariates

Description

Regroup categorical covariates

Usage

transformCatCov(object, covariate, group, reference, verbose = FALSE)

Arguments

object

saemixData object

covariate

name of the covariate

group

a vector giving the categories to which the initial values of the covariates should be mapped. If the resulting covariate is binary, it will be stored as 0/1. If it has more than 2 categories, dummy covariates will be created for the analysis.

reference

the reference group

verbose

a boolean, prints messages during the execution of the function if TRUE. Defaults to FALSE.

Value

an object of class "SaemixData"

Examples

data(cow.saemix)
saemix.data<-saemixData(name.data=cow.saemix,header=TRUE,name.group=c("cow"),
                   name.predictors=c("time"),name.response=c("weight"),
                   name.covariates=c("birthyear","twin","birthrank"),
                   units=list(x="days",y="kg",covariates=c("yr","-","-")))
unique(saemix.data@data$birthrank) # 5 categories, 3 4 5 6 7
# create 2 dummy variables regrouping 4 and 5, and 6 and 7
cowt <- transformCatCov(saemix.data, covariate=birthrank, group=c(1,2,2,3,3), verbose=TRUE) 
head(saemix.data@data) # the original covariate is birthrank
head(cowt@data) 
# the new covariates are birthrank.G2 (regrouping 4 and 5) and birthrank.G3 (6 and 7)


saemix documentation built on May 29, 2024, 10:43 a.m.