Learn R Programming

r2glmm (version 0.1.3)

cmp_R2: Compute R2 with a specified C matrix

Description

Compute R2 with a specified C matrix

Usage

cmp_R2(c, x, SigHat, beta, method, obsperclust = NULL, nclusts = NULL)

Value

A vector with the Wald statistic (ncp), approximate Wald F statistic (F), numerator degrees of freedom (v1), denominator degrees of freedom (v2), and the specified r squared value (Rsq)

Arguments

c

Contrast matrix for fixed effects

x

Fixed effects design matrix

SigHat

estimated model covariance (matrix or scalar)

beta

fixed effects estimates

method

the method for computing r2beta

obsperclust

number of observations per cluster (i.e. subject)

nclusts

number of clusters (i.e. subjects)

Examples

Run this code
library(nlme)
library(lme4)
library(mgcv)
lmemod = lme(distance ~ age*Sex, random = ~1|Subject, data = Orthodont)
X = model.matrix(lmemod, data = Orthodont)
SigHat = extract.lme.cov(lmemod, data = Orthodont)
beta = fixef(lmemod)
p = length(beta)
obsperclust = as.numeric(table(lmemod$data[,'Subject']))
nclusts = length(obsperclust)
C = cbind(rep(0, p-1),diag(p-1))
partial.c = make.partial.C(p-1,p,2)

cmp_R2(c=C, x=X, SigHat=SigHat, beta=beta, obsperclust = obsperclust,
nclusts = nclusts, method = 'sgv')
cmp_R2(c=partial.c, x=X, SigHat=SigHat, beta=beta, obsperclust = obsperclust,
nclusts = nclusts, method = 'sgv')

Run the code above in your browser using DataLab