cmp_R2: Compute R2 with a specified C matrix

Description Usage Arguments Value Examples

View source: R/cmpR2_Function.R

Description

Compute R2 with a specified C matrix

Usage

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

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)

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)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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')

r2glmm documentation built on May 1, 2019, 9:09 p.m.