Learn R Programming

predictmeans (version 0.97)

Kmatrix: Matrix of Coefficients in a Linear Model

Description

This function obtains a matrix of coefficients for parametric models such as aov, lm, glm, gls, lme, and lmer.

Usage

Kmatrix(model, modelterm, covariate, prtnum=FALSE)

Arguments

model
Model object returned by aov, lm, glm, gls, lme, and lmer.
modelterm
Name (in "quotes") for indicating which model term's predicted mean to be calculated. The modelterm must be given exactly as it appears in the printed model, e.g. "A" or "A:B".
covariate
A numerical vector to specify values of covariates for calculating predicted means, default values are the means of the associated covariates. It also can be the name of covariate in the model.
prtnum
An option for printing covariate info on the screen or not. The default is FALSE.

Value

  • KCoefficients matrix
  • fctnamesA model frame contains factor(s) info in the model.
  • responseThe name of response variable in the model.

References

Welham, S., Cullis, B., Gogel, B., Gilmour, A., & Thompson, R. (2004), Prediction in linear mixed models, Australian and New Zealand Journal of Statistics, 46(3), 325-347.

Examples

Run this code
library(predictmeans)
# library(lme4)
# fm <- lmer(yield ~ nitro*Variety+(1|Block/Variety), data=Oats)
  fm <- lme(yield ~ nitro*Variety, random=~1|Block/Variety, data=Oats)
  Kmatrix(fm, "Variety", prtnum=TRUE)
  Kmatrix(fm, "Variety", 0.5, prtnum=TRUE)
#  Kmatrix(fm, "Variety", "nitro")

Run the code above in your browser using DataLab