gsearlyFit: Fit a generalized least squares model

gsearlyFitR Documentation

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, method="ML",
      full=FALSE)

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.

method

Either "ML" for maximum likelihood or "REML" for restricted maximum likelihood estimation; with default "ML"

full

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

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 the data sample size N, number of estimated gls model parameters p, estimated correlations (estcorr) and standard deviations (estsd), which will vary depending on the select covariance model.

See Also

gsearlySimulate, simdataExtract, modelParameters

Examples


 # 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]


gsearly documentation built on July 10, 2026, 5:09 p.m.