Learn R Programming

gsearly (version 1.0.0)

gsearlyFit: Fit a generalized least squares model

Description

Fits a generalized least squares model using function gls (from package nlme)

Usage

gsearlyFit(data, datanames = c("id","atime","catime",
      "intervention","outcome"), cmodel=FALSE, vmodel=TRUE, full=FALSE)

Value

Either a gls model (full=TRUE) or a summary of the model fit (full=FALSE), which is a list with the components.

parameters

Estimates of variance of beta (vbeta), beta and z (z=beta/sqrt(vbeta)).

model

A list comprised of data sample size N, number of estimated gls model parameters, estimated covariance (vcovmat), correlation (corrmat) and standard deviation (sdmat) matrices.

Arguments

data

A data frame structured as function simdataExtract.

datanames

Names of the five required data variables; participant, time-point, standardized (continuous) time-point (see tfuStandard), intervention arm and outcome, in that order; e.g. c("id","atime","catime","intervention","outcome")).

cmodel

The correlation model is set to FALSE, for an unstructured model or to either "uniform" or "exponential", with default FALSE.

vmodel

The variance model is set to either FALSE or TRUE, where the latter allows variances to vary by assessment occasion; default is vmodel=TRUE.

full

Either FALSE, which provides model details and parameters only or TRUE which provides full gls model details.

See Also

gsearlySimulate, simdataExtract, modelParameters

Examples

Run this code

 # Model for full data set
 data(qol)
 mod.fulldata <- nlme::gls(QoL~(Weeks-1)+(Weeks-1):Treat, data=qol,
    correlation=nlme::corSymm(form=~1|Subject),
    weights=nlme::varIdent(form =~1|Weeks), method="ML")
 summary(mod.fulldata)

 # Use data available at day 150
 data.interim1 <- qol[qol$Day<=150,]
 mod.interim1 <- nlme::gls(QoL~(Weeks-1)+(Weeks-1):Treat, data=data.interim1,
    correlation=nlme::corSymm(form=~1|Subject),
    weights=nlme::varIdent(form=~1|Weeks), method="ML")
 summary(mod.interim1)

 # Use glsFit
 gsearlyFit(qol, datanames=c("Subject","Weeks","STime","Treat","QoL"))
 # vbeta
 vcov(mod.fulldata)[6,6]
 # beta
 coef(mod.fulldata)[6]

Run the code above in your browser using DataLab