Title: | Linear and Nonlinear Mixed Effects Models |
---|---|
Description: | Fit and compare Gaussian linear and nonlinear mixed-effects models. |
Authors: | José Pinheiro [aut] (S version), Douglas Bates [aut] (up to 2007), Saikat DebRoy [ctb] (up to 2002), Deepayan Sarkar [ctb] (up to 2005), EISPACK authors [ctb] (src/rs.f), Siem Heisterkamp [ctb] (Author fixed sigma), Bert Van Willigen [ctb] (Programmer fixed sigma), Johannes Ranke [ctb] (varConstProp()), R Core Team [aut, cre] |
Maintainer: | R Core Team <[email protected]> |
License: | GPL (>= 2) |
Version: | 3.1-166 |
Built: | 2024-11-19 06:45:31 UTC |
Source: | CRAN |
This method function extracts sub-matrices from the positive-definite
matrix represented by x
.
## S3 method for class 'pdMat' x[i, j, drop = TRUE] ## S3 replacement method for class 'pdMat' x[i, j] <- value
## S3 method for class 'pdMat' x[i, j, drop = TRUE] ## S3 replacement method for class 'pdMat' x[i, j] <- value
x |
an object inheriting from class |
i , j
|
optional subscripts applying respectively to the rows
and columns of the positive-definite matrix represented by
|
drop |
a logical value. If |
value |
a vector, or matrix, with the replacement values for the
relevant piece of the matrix represented by |
if i
and j
are identical, the returned value will be
pdMat
object with the same class as x
. Otherwise, the
returned value will be a matrix. In the case a single row (or column)
is selected, the returned value may be converted to a vector,
according to the rules above.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdSymm(diag(3)) pd1[1, , drop = FALSE] pd1[1:2, 1:2] <- 3 * diag(2)
pd1 <- pdSymm(diag(3)) pd1[1, , drop = FALSE] pd1[1:2, 1:2] <- 3 * diag(2)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: gls
and lme
.
ACF(object, maxLag, ...)
ACF(object, maxLag, ...)
object |
any object from which an autocorrelation function can be obtained. Generally an object resulting from a model fit, from which residuals can be extracted. |
maxLag |
maximum lag for which the autocorrelation should be calculated. |
... |
some methods for this generic require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
## see the method function documentation
## see the method function documentation
This method function calculates the empirical autocorrelation function
for the residuals from a gls
fit. If a grouping variable is
specified in form
, the autocorrelation values
are calculated using pairs of residuals within the same group;
otherwise all possible residual pairs are used. The autocorrelation
function is useful for investigating serial correlation models for
equally spaced data.
## S3 method for class 'gls' ACF(object, maxLag, resType, form, na.action, ...)
## S3 method for class 'gls' ACF(object, maxLag, resType, form, na.action, ...)
object |
an object inheriting from class |
maxLag |
an optional integer giving the maximum lag for which the autocorrelation should be calculated. Defaults to maximum lag in the residuals. |
resType |
an optional character string specifying the type of
residuals to be used. If |
form |
an optional one sided formula of the form |
na.action |
a function that indicates what should happen when the
data contain |
... |
some methods for this generic require additional arguments. |
a data frame with columns lag
and ACF
representing,
respectively, the lag between residuals within a pair and the corresponding
empirical autocorrelation. The returned value inherits from class
ACF
.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) ACF(fm1, form = ~ 1 | Mare) # Pinheiro and Bates, p. 255-257 fm1Dial.gls <- gls(rate ~ (pressure+I(pressure^2)+I(pressure^3)+I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) ACF(fm2Dial.gls, form = ~ 1 | Subject)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) ACF(fm1, form = ~ 1 | Mare) # Pinheiro and Bates, p. 255-257 fm1Dial.gls <- gls(rate ~ (pressure+I(pressure^2)+I(pressure^3)+I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) ACF(fm2Dial.gls, form = ~ 1 | Subject)
This method function calculates the empirical autocorrelation function
for the within-group residuals from an lme
fit. The
autocorrelation values are calculated using pairs of residuals within
the innermost group level. The autocorrelation function is useful for
investigating serial correlation models for equally spaced data.
## S3 method for class 'lme' ACF(object, maxLag, resType, ...)
## S3 method for class 'lme' ACF(object, maxLag, resType, ...)
object |
an object inheriting from class |
maxLag |
an optional integer giving the maximum lag for which the autocorrelation should be calculated. Defaults to maximum lag in the within-group residuals. |
resType |
an optional character string specifying the type of
residuals to be used. If |
... |
some methods for this generic require additional arguments – not used. |
a data frame with columns lag
and ACF
representing,
respectively, the lag between residuals within a pair and the corresponding
empirical autocorrelation. The returned value inherits from class
ACF
.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, random = ~ sin(2*pi*Time) | Mare) ACF(fm1, maxLag = 11) # Pinheiro and Bates, p240-241 fm1Over.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data=Ovary, random=pdDiag(~sin(2*pi*Time)) ) (ACF.fm1Over <- ACF(fm1Over.lme, maxLag=10)) plot(ACF.fm1Over, alpha=0.01)
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, random = ~ sin(2*pi*Time) | Mare) ACF(fm1, maxLag = 11) # Pinheiro and Bates, p240-241 fm1Over.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data=Ovary, random=pdDiag(~sin(2*pi*Time)) ) (ACF.fm1Over <- ACF(fm1Over.lme, maxLag=10)) plot(ACF.fm1Over, alpha=0.01)
The Alfalfa
data frame has 72 rows and 4 columns.
This data frame contains the following columns:
a factor with levels
Cossack
,
Ladak
, and
Ranger
a factor with levels
None
S1
S20
O7
a factor with levels
1
2
3
4
5
6
a numeric vector
These data are described in Snedecor and Cochran (1980) as
an example of a split-plot design. The treatment structure used in the
experiment was a 34 full factorial, with three varieties of
alfalfa and four dates of third cutting in 1943. The experimental
units were arranged into six blocks, each subdivided into four plots.
The varieties of alfalfa (Cossac, Ladak, and
Ranger) were assigned randomly to the blocks and the dates of
third cutting (None, S1—September 1,
S20—September 20, and O7—October 7) were randomly
assigned to the plots. All four dates were used on each block.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.1)
Snedecor, G. W. and Cochran, W. G. (1980), Statistical Methods (7th ed), Iowa State University Press, Ames, IA
The extractor function is applied to each object in ...
, with
the result being converted to a vector. A map
attribute is
included to indicate which pieces of the returned vector correspond to
the original objects in dots
.
allCoef(..., extract)
allCoef(..., extract)
... |
objects to which |
extract |
an optional extractor function. Defaults to |
a vector with all elements, generally coefficients, obtained by
applying extract
to the objects in ...
.
José' Pinheiro and Douglas Bates
cs1 <- corAR1(0.1) vf1 <- varPower(0.5) allCoef(cs1, vf1)
cs1 <- corAR1(0.1) vf1 <- varPower(0.5) allCoef(cs1, vf1)
When only one fitted model object is present, a data frame with the
numerator degrees of freedom, F-values, and P-values
for Wald tests for the terms in the model (when Terms
and
L
are NULL
), a combination of model terms (when
Terms
in not NULL
), or linear combinations of the model
coefficients (when L
is not NULL
). Otherwise, when
multiple fitted objects are being compared, a data frame with
the degrees of freedom, the (restricted) log-likelihood, the
Akaike Information Criterion (AIC), and the Bayesian Information
Criterion (BIC) of each object is returned. If test=TRUE
,
whenever two consecutive objects have different number of degrees of
freedom, a likelihood ratio statistic with the associated p-value is
included in the returned data frame.
## S3 method for class 'gls' anova(object, ..., test, type, adjustSigma, Terms, L, verbose)
## S3 method for class 'gls' anova(object, ..., test, type, adjustSigma, Terms, L, verbose)
object |
an object inheriting from class |
... |
other optional fitted model objects inheriting from
classes |
test |
an optional logical value controlling whether likelihood
ratio tests should be used to compare the fitted models represented
by |
type |
an optional character string specifying the type of sum of
squares to be used in F-tests for the terms in the model. If
|
adjustSigma |
an optional logical value. If |
Terms |
an optional integer or character vector specifying which
terms in the model should be jointly tested to be zero using a Wald
F-test. If given as a character vector, its elements must correspond
to term names; else, if given as an integer vector, its elements must
correspond to the order in which terms are included in the
model. This argument is only used when a single fitted object is
passed to the function. Default is |
L |
an optional numeric vector or array specifying linear
combinations of the coefficients in the model that should be tested
to be zero. If given as an array, its rows define the linear
combinations to be tested. If names are assigned to the vector
elements (array columns), they must correspond to coefficients
names and will be used to map the linear combination(s) to the
coefficients; else, if no names are available, the vector elements
(array columns) are assumed in the same order as the coefficients
appear in the model. This argument is only used when a single fitted
object is passed to the function. Default is |
verbose |
an optional logical value. If |
a data frame inheriting from class "anova.lme"
.
Likelihood comparisons are not meaningful for objects fit using restricted maximum likelihood and with different fixed effects.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
gls
, gnls
, nlme
,
lme
, logLik.gls
,
AIC
, BIC
,
print.anova.lme
# AR(1) errors within each Mare fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) anova(fm1) # variance changes with a power of the absolute fitted values? fm2 <- update(fm1, weights = varPower()) anova(fm1, fm2) # Pinheiro and Bates, p. 251-252 fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age)) fm2Orth.gls <- update(fm1Orth.gls, corr = corCompSymm(form = ~ 1 | Subject)) anova(fm1Orth.gls, fm2Orth.gls) # Pinheiro and Bates, pp. 215-215, 255-260 #p. 215 fm1Dial.lme <- lme(rate ~(pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer, ~ pressure + I(pressure^2)) # p. 216 fm2Dial.lme <- update(fm1Dial.lme, weights = varPower(form = ~ pressure)) # p. 255 fm1Dial.gls <- gls(rate ~ (pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) anova(fm1Dial.gls, fm2Dial.gls) fm3Dial.gls <- update(fm2Dial.gls, corr = corAR1(0.771, form = ~ 1 | Subject)) anova(fm2Dial.gls, fm3Dial.gls) # anova.gls to compare a gls and an lme fit anova(fm3Dial.gls, fm2Dial.lme, test = FALSE) # Pinheiro and Bates, pp. 261-266 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) fm3Wheat2 <- update(fm1Wheat2, corr = corRatio(c(12.5, 0.2), form = ~ latitude + longitude, nugget = TRUE)) # Test a specific contrast anova(fm3Wheat2, L = c(-1, 0, 1))
# AR(1) errors within each Mare fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) anova(fm1) # variance changes with a power of the absolute fitted values? fm2 <- update(fm1, weights = varPower()) anova(fm1, fm2) # Pinheiro and Bates, p. 251-252 fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age)) fm2Orth.gls <- update(fm1Orth.gls, corr = corCompSymm(form = ~ 1 | Subject)) anova(fm1Orth.gls, fm2Orth.gls) # Pinheiro and Bates, pp. 215-215, 255-260 #p. 215 fm1Dial.lme <- lme(rate ~(pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer, ~ pressure + I(pressure^2)) # p. 216 fm2Dial.lme <- update(fm1Dial.lme, weights = varPower(form = ~ pressure)) # p. 255 fm1Dial.gls <- gls(rate ~ (pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) anova(fm1Dial.gls, fm2Dial.gls) fm3Dial.gls <- update(fm2Dial.gls, corr = corAR1(0.771, form = ~ 1 | Subject)) anova(fm2Dial.gls, fm3Dial.gls) # anova.gls to compare a gls and an lme fit anova(fm3Dial.gls, fm2Dial.lme, test = FALSE) # Pinheiro and Bates, pp. 261-266 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) fm3Wheat2 <- update(fm1Wheat2, corr = corRatio(c(12.5, 0.2), form = ~ latitude + longitude, nugget = TRUE)) # Test a specific contrast anova(fm3Wheat2, L = c(-1, 0, 1))
When only one fitted model object is present, a data frame with the
numerator degrees of freedom, denominator degrees of
freedom, F-values, and P-values for Wald tests for the terms in the
model (when Terms
and L
are NULL
), a combination
of model terms (when Terms
in not NULL
), or linear
combinations of the model coefficients (when L
is not
NULL
). Otherwise, when multiple fitted objects are being
compared, a data frame with the degrees of freedom, the (restricted)
log-likelihood, the Akaike Information Criterion (AIC), and the
Bayesian Information Criterion (BIC) of each object is returned. If
test=TRUE
, whenever two consecutive objects have different
number of degrees of freedom, a likelihood ratio statistic with the
associated p-value is included in the returned data frame.
## S3 method for class 'lme' anova(object, ..., test, type, adjustSigma, Terms, L, verbose) ## S3 method for class 'anova.lme' print(x, verbose, ...)
## S3 method for class 'lme' anova(object, ..., test, type, adjustSigma, Terms, L, verbose) ## S3 method for class 'anova.lme' print(x, verbose, ...)
object |
an object inheriting from class |
... |
other optional fitted model objects inheriting from
classes |
test |
an optional logical value controlling whether likelihood
ratio tests should be used to compare the fitted models represented
by |
type |
an optional character string specifying the type of sum of
squares to be used in F-tests for the terms in the model. If
|
adjustSigma |
an optional logical value. If |
Terms |
an optional integer or character vector specifying which
terms in the model should be jointly tested to be zero using a Wald
F-test. If given as a character vector, its elements must correspond
to term names; else, if given as an integer vector, its elements must
correspond to the order in which terms are included in the
model. This argument is only used when a single fitted object is
passed to the function. Default is |
L |
an optional numeric vector or array specifying linear
combinations of the coefficients in the model that should be tested
to be zero. If given as an array, its rows define the linear
combinations to be tested. If names are assigned to the vector
elements (array columns), they must correspond to coefficients
names and will be used to map the linear combination(s) to the
coefficients; else, if no names are available, the vector elements
(array columns) are assumed in the same order as the coefficients
appear in the model. This argument is only used when a single fitted
object is passed to the function. Default is |
x |
an object inheriting from class |
verbose |
an optional logical value. If |
a data frame inheriting from class "anova.lme"
.
Likelihood comparisons are not meaningful for objects fit using restricted maximum likelihood and with different fixed effects.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
gls
, gnls
, nlme
,
lme
, AIC
, BIC
,
print.anova.lme
,
logLik.lme
,
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) anova(fm1) fm2 <- update(fm1, random = pdDiag(~age)) anova(fm1, fm2) ## Pinheiro and Bates, pp. 251-254 ------------------------------------------ fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age)) fm2Orth.gls <- update(fm1Orth.gls, corr = corCompSymm(form = ~ 1 | Subject)) ## anova.gls examples: anova(fm1Orth.gls, fm2Orth.gls) fm3Orth.gls <- update(fm2Orth.gls, weights = NULL) anova(fm2Orth.gls, fm3Orth.gls) fm4Orth.gls <- update(fm3Orth.gls, weights = varIdent(form = ~ 1 | Sex)) anova(fm3Orth.gls, fm4Orth.gls) # not in book but needed for the following command fm3Orth.lme <- lme(distance ~ Sex*I(age-11), data = Orthodont, random = ~ I(age-11) | Subject, weights = varIdent(form = ~ 1 | Sex)) # Compare an "lme" object with a "gls" object (test would be non-sensical!) anova(fm3Orth.lme, fm4Orth.gls, test = FALSE) ## Pinheiro and Bates, pp. 222-225 ------------------------------------------ op <- options(contrasts = c("contr.treatment", "contr.poly")) fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # Test a specific contrast anova(fm2BW.lme, L = c("Time:Diet2" = 1, "Time:Diet3" = -1)) ## Pinheiro and Bates, pp. 352-365 ------------------------------------------ fm1Theo.lis <- nlsList( conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data=Theoph) fm1Theo.lis fm1Theo.nlme <- nlme(fm1Theo.lis) fm2Theo.nlme <- update(fm1Theo.nlme, random= pdDiag(lKe+lKa+lCl~1) ) fm3Theo.nlme <- update(fm2Theo.nlme, random= pdDiag( lKa+lCl~1) ) # Comparing the 3 nlme models anova(fm1Theo.nlme, fm3Theo.nlme, fm2Theo.nlme) options(op) # (set back to previous state)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) anova(fm1) fm2 <- update(fm1, random = pdDiag(~age)) anova(fm1, fm2) ## Pinheiro and Bates, pp. 251-254 ------------------------------------------ fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age)) fm2Orth.gls <- update(fm1Orth.gls, corr = corCompSymm(form = ~ 1 | Subject)) ## anova.gls examples: anova(fm1Orth.gls, fm2Orth.gls) fm3Orth.gls <- update(fm2Orth.gls, weights = NULL) anova(fm2Orth.gls, fm3Orth.gls) fm4Orth.gls <- update(fm3Orth.gls, weights = varIdent(form = ~ 1 | Sex)) anova(fm3Orth.gls, fm4Orth.gls) # not in book but needed for the following command fm3Orth.lme <- lme(distance ~ Sex*I(age-11), data = Orthodont, random = ~ I(age-11) | Subject, weights = varIdent(form = ~ 1 | Sex)) # Compare an "lme" object with a "gls" object (test would be non-sensical!) anova(fm3Orth.lme, fm4Orth.gls, test = FALSE) ## Pinheiro and Bates, pp. 222-225 ------------------------------------------ op <- options(contrasts = c("contr.treatment", "contr.poly")) fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # Test a specific contrast anova(fm2BW.lme, L = c("Time:Diet2" = 1, "Time:Diet3" = -1)) ## Pinheiro and Bates, pp. 352-365 ------------------------------------------ fm1Theo.lis <- nlsList( conc ~ SSfol(Dose, Time, lKe, lKa, lCl), data=Theoph) fm1Theo.lis fm1Theo.nlme <- nlme(fm1Theo.lis) fm2Theo.nlme <- update(fm1Theo.nlme, random= pdDiag(lKe+lKa+lCl~1) ) fm3Theo.nlme <- update(fm2Theo.nlme, random= pdDiag( lKa+lCl~1) ) # Comparing the 3 nlme models anova(fm1Theo.nlme, fm3Theo.nlme, fm2Theo.nlme) options(op) # (set back to previous state)
This method function extracts the correlation matrix, or list of
correlation matrices, associated with object
.
## S3 method for class 'corStruct' as.matrix(x, ...)
## S3 method for class 'corStruct' as.matrix(x, ...)
x |
an object inheriting from class |
... |
further arguments passed from other methods. |
If the correlation structure includes a grouping factor, the returned
value will be a list with components given by the correlation
matrices for each group. Otherwise, the returned value will be a
matrix representing the correlation structure associated with
object
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
cst1 <- corAR1(form = ~1|Subject) cst1 <- Initialize(cst1, data = Orthodont) as.matrix(cst1)
cst1 <- corAR1(form = ~1|Subject) cst1 <- Initialize(cst1, data = Orthodont) as.matrix(cst1)
This method function extracts the positive-definite matrix represented
by x
.
## S3 method for class 'pdMat' as.matrix(x, ...)
## S3 method for class 'pdMat' as.matrix(x, ...)
x |
an object inheriting from class |
... |
further arguments passed from other methods. |
a matrix corresponding to the positive-definite matrix represented by
x
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
as.matrix(pdSymm(diag(4)))
as.matrix(pdSymm(diag(4)))
This method function extracts the positive-definite matrices
corresponding to the pdMat
elements of object
.
## S3 method for class 'reStruct' as.matrix(x, ...)
## S3 method for class 'reStruct' as.matrix(x, ...)
x |
an object inheriting from class |
... |
further arguments passed from other methods. |
a list with components given by the positive-definite matrices
corresponding to the elements of object
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
as.matrix.pdMat
, reStruct
,
pdMat
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) as.matrix(rs1)
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) as.matrix(rs1)
The names of all variables used in the formulas extracted from the
objects defined in ...
are converted into a single linear
formula, with the variables names separated by +
.
asOneFormula(..., omit)
asOneFormula(..., omit)
... |
objects, or lists of objects, from which a formula can be extracted. |
omit |
an optional character vector with the names of variables to be omitted from the returned formula. Defaults to c(".", "pi"). |
a one-sided linear formula with all variables named in the formulas
extracted from the objects in ...
, except the ones listed in
omit
.
José Pinheiro and Douglas Bates [email protected]
asOneFormula(y ~ x + z | g, list(~ w, ~ t * sin(2 * pi)))
asOneFormula(y ~ x + z | g, list(~ w, ~ t * sin(2 * pi)))
The Assay
data frame has 60 rows and 4 columns.
This data frame contains the following columns:
an ordered factor with levels
2
< 1
identifying the block where the wells
are measured.
a factor with levels a
to f
identifying the
sample corresponding to the well.
a factor with levels
1
to 5
indicating the dilution applied to the well
a numeric vector of the log-optical density
These data, courtesy of Rich Wolfe and David Lansky from Searle, Inc., come from a bioassay run on a 96-well cell culture plate. The assay is performed using a split-block design. The 8 rows on the plate are labeled A–H from top to bottom and the 12 columns on the plate are labeled 1–12 from left to right. Only the central 60 wells of the plate are used for the bioassay (the intersection of rows B–G and columns 2–11). There are two blocks in the design: Block 1 contains columns 2–6 and Block 2 contains columns 7–11. Within each block, six samples are assigned randomly to rows and five (serial) dilutions are assigned randomly to columns. The response variable is the logarithm of the optical density. The cells are treated with a compound that they metabolize to produce the stain. Only live cells can make the stain, so the optical density is a measure of the number of cells that are alive and healthy.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.2)
Create a tabular representation of the response in a balanced
groupedData
object.
asTable(object)
asTable(object)
object |
A balanced |
A balanced groupedData
object can be represented as a matrix or table
of response values corresponding to the values of a primary covariate
for each level of a grouping factor. This function creates such a
matrix representation of the data in object
.
A matrix. The data in the matrix are the values of the response. The columns correspond to the distinct values of the primary covariate and are labelled as such. The rows correspond to the distinct levels of the grouping factor and are labelled as such.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
groupedData
, isBalanced
,
balancedGrouped
asTable(Orthodont) # Pinheiro and Bates, p. 109 ergoStool.mat <- asTable(ergoStool)
asTable(Orthodont) # Pinheiro and Bates, p. 109 ergoStool.mat <- asTable(ergoStool)
Predicted values are obtained at the specified values of
primary
. If object
has a grouping structure
(i.e. getGroups(object)
is not NULL
), predicted values
are obtained for each group. If level
has more than one
element, predictions are obtained for each level of the
max(level)
grouping factor. If other covariates besides
primary
are used in the prediction model, their average
(numeric covariates) or most frequent value (categorical covariates)
are used to obtain the predicted values. The original observations
are also included in the returned object.
augPred(object, primary, minimum, maximum, length.out, ...) ## S3 method for class 'lme' augPred(object, primary = NULL, minimum = min(primary), maximum = max(primary), length.out = 51, level = Q, ...)
augPred(object, primary, minimum, maximum, length.out, ...) ## S3 method for class 'lme' augPred(object, primary = NULL, minimum = min(primary), maximum = max(primary), length.out = 51, level = Q, ...)
object |
a fitted model object from which predictions can be
extracted, using a |
primary |
an optional one-sided formula specifying the primary
covariate to be used to generate the augmented predictions. By
default, if a covariate can be extracted from the data used to generate
|
minimum |
an optional lower limit for the primary
covariate. Defaults to |
maximum |
an optional upper limit for the primary
covariate. Defaults to |
length.out |
an optional integer with the number of primary covariate values at which to evaluate the predictions. Defaults to 51. |
level |
an optional integer vector specifying the desired prediction levels. Levels increase from outermost to innermost grouping, with level 0 representing the population (fixed effects) predictions. Defaults to the innermost level. |
... |
some methods for the generic may require additional arguments. |
a data frame with four columns representing, respectively, the values
of the primary covariate, the groups (if object
does not have a
grouping structure, all elements will be 1
), the predicted or
observed values, and the type of value in the third column:
original
for the observed values and predicted
(single
or no grouping factor) or predict.groupVar
(multiple levels of
grouping), with groupVar
replaced by the actual grouping
variable name (fixed
is used for population predictions). The
returned object inherits from class "augPred"
.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: gls
, lme
, and lmList
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
plot.augPred
, getGroups
,
predict
fm1 <- lme(Orthodont, random = ~1) augPred(fm1, length.out = 2, level = c(0,1))
fm1 <- lme(Orthodont, random = ~1) augPred(fm1, length.out = 2, level = c(0,1))
Create a groupedData
object from a data matrix. This function
can be used only with balanced data. The opposite conversion, from a
groupedData
object to a matrix
, is done with asTable
.
balancedGrouped(form, data, labels=NULL, units=NULL)
balancedGrouped(form, data, labels=NULL, units=NULL)
form |
A formula of the form |
data |
A matrix or data frame containing the values of the
response grouped according to the levels of the grouping factor
(rows) and the distinct levels of the primary covariate (columns).
The |
labels |
an optional list of character strings giving labels for
the response and the primary covariate. The label for the primary
covariate is named |
units |
an optional list of character strings giving the units for
the response and the primary covariate. The units string for the
primary covariate is named |
A balanced groupedData
object.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
groupedData
, isBalanced
, asTable
OrthoMat <- asTable( Orthodont ) Orth2 <- balancedGrouped(distance ~ age | Subject, data = OrthoMat, labels = list(x = "Age", y = "Distance from pituitary to pterygomaxillary fissure"), units = list(x = "(yr)", y = "(mm)")) Orth2[ 1:10, ] ## check the first few entries # Pinheiro and Bates, p. 109 ergoStool.mat <- asTable(ergoStool) balancedGrouped(effort~Type|Subject, data=ergoStool.mat)
OrthoMat <- asTable( Orthodont ) Orth2 <- balancedGrouped(distance ~ age | Subject, data = OrthoMat, labels = list(x = "Age", y = "Distance from pituitary to pterygomaxillary fissure"), units = list(x = "(yr)", y = "(mm)")) Orth2[ 1:10, ] ## check the first few entries # Pinheiro and Bates, p. 109 ergoStool.mat <- asTable(ergoStool) balancedGrouped(effort~Type|Subject, data=ergoStool.mat)
The bdf
data frame has 2287 rows and 25 columns of language
scores from grade 8 pupils in elementary schools in The Netherlands.
data(bdf)
data(bdf)
a factor denoting the school.
a factor denoting the pupil.
a numeric vector of verbal IQ scores
a numeric vector of IQ scores.
Sex of the student.
a factor indicating if the student is a member of a minority group.
an ordered factor indicating if one or more grades have been repeated.
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector of socioeconomic status indicators.
a factor indicating of the school is a public school, a Protestant private school, a Catholic private school, or a non-denominational private school.
a numeric vector
a numeric vector
a factor with levels 0
and 1
a numeric vector
a numeric vector
a factor indicating if the class is a mixed-grade class.
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector
‘http://stat.gamma.rug.nl/snijders/multilevel.htm’, the first edition of http://www.stats.ox.ac.uk/~snijders/mlbook.htm.
Snijders, Tom and Bosker, Roel (1999), Multilevel Analysis: An Introduction to Basic and Advanced Multilevel Modeling, Sage.
summary(bdf) ## More examples, including lme() fits reproducing parts in the above ## book, are available in the R script files system.file("mlbook", "ch04.R", package ="nlme") # and system.file("mlbook", "ch05.R", package ="nlme")
summary(bdf) ## More examples, including lme() fits reproducing parts in the above ## book, are available in the R script files system.file("mlbook", "ch04.R", package ="nlme") # and system.file("mlbook", "ch05.R", package ="nlme")
The BodyWeight
data frame has 176 rows and 4 columns.
This data frame contains the following columns:
a numeric vector giving the body weight of the rat (grams).
a numeric vector giving the time at which the measurement is made (days).
an ordered factor with levels 2
< 3
< 4
< 1
< 8
< 5
< 6
< 7
<
11
< 9
< 10
< 12
< 13
<
15
< 14
< 16
identifying the rat whose
weight is measured.
a factor with levels
1
to 3
indicating the diet that the rat receives.
Hand and Crowder (1996) describe data on the body weights of rats measured over 64 days. These data also appear in Table 2.4 of Crowder and Hand (1990). The body weights of the rats (in grams) are measured on day 1 and every seven days thereafter until day 64, with an extra measurement on day 44. The experiment started several weeks before “day 1.” There are three groups of rats, each on a different diet.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.3)
Crowder, M. and Hand, D. (1990), Analysis of Repeated Measures, Chapman and Hall, London.
Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall, London.
The Cefamandole
data frame has 84 rows and 3 columns.
This data frame contains the following columns:
a factor giving the subject from which the sample was drawn.
a numeric vector giving the time at which the sample was drawn (minutes post-injection).
a numeric vector giving the observed plasma concentration of cefamandole (mcg/ml).
Davidian and Giltinan (1995, 1.1, p. 2) describe data obtained during a pilot study to investigate the pharmacokinetics of the drug cefamandole. Plasma concentrations of the drug were measured on six healthy volunteers at 14 time points following an intraveneous dose of 15 mg/kg body weight of cefamandole.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.4)
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London.
plot(Cefamandole) fm1 <- nlsList(SSbiexp, data = Cefamandole) summary(fm1)
plot(Cefamandole) fm1 <- nlsList(SSbiexp, data = Cefamandole) summary(fm1)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include all "pdMat"
,
"corStruct"
and "varFunc"
classes,
"reStruct"
, and "modelStruct"
.
coefficients<-
is an alias for coef<-
.
coef(object, ...) <- value coefficients(object, ...) <- value
coef(object, ...) <- value coefficients(object, ...) <- value
object |
any object representing a fitted model, or, by default,
any object with a |
... |
some methods for this generic function may require additional arguments. |
value |
a value to be assigned to the coefficients associated with
|
will depend on the method function; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
This method function extracts the coefficients associated with the
correlation structure represented by object
.
## S3 method for class 'corStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'corStruct' coef(object, ...) <- value
## S3 method for class 'corStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'corStruct' coef(object, ...) <- value
object |
an object inheriting from class |
unconstrained |
a logical value. If |
value |
a vector with the replacement values for the coefficients
associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the coefficients corresponding to object
.
On the left side of an assignment, sets the values of the coefficients
of object
to value
. Object
must be initialized (using
Initialize
) before new values can be assigned to its
coefficients.
José Pinheiro and Douglas Bates
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
corAR1
, corARMA
,
corCAR1
, corCompSymm
,
corExp
, corGaus
, corLin
,
corRatio
, corSpatial
, corSpher
,
corSymm
,Initialize
cst1 <- corARMA(p = 1, q = 1) coef(cst1)
cst1 <- corARMA(p = 1, q = 1) coef(cst1)
The estimated coefficients for the nonlinear model represented by
object
are extracted.
## S3 method for class 'gnls' coef(object, ...)
## S3 method for class 'gnls' coef(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the estimated coefficients for the nonlinear model
represented by object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) coef(fm1)
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) coef(fm1)
The estimated coefficients at level are obtained by adding
together the fixed effects estimates and the corresponding random
effects estimates at grouping levels less or equal to
. The
resulting estimates are returned as a data frame, with rows
corresponding to groups and columns to coefficients. Optionally, the
returned data frame may be augmented with covariates summarized over
groups.
## S3 method for class 'lme' coef(object, augFrame, level, data, which, FUN, omitGroupingFactor, subset, ...)
## S3 method for class 'lme' coef(object, augFrame, level, data, which, FUN, omitGroupingFactor, subset, ...)
object |
an object inheriting from class |
augFrame |
an optional logical value. If |
level |
an optional positive integer giving the level of grouping to be used in extracting the coefficients from an object with multiple nested grouping levels. Defaults to the highest or innermost level of grouping. |
data |
an optional data frame with the variables to be used for
augmenting the returned data frame when |
which |
an optional positive integer or character vector
specifying which columns of |
FUN |
an optional summary function or a list of summary functions
to be applied to group-varying variables, when collapsing |
omitGroupingFactor |
an optional logical value. When |
subset |
an optional expression specifying a subset |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame inheriting from class "coef.lme"
with the estimated
coefficients at level level
and, optionally, other covariates
summarized over groups. The returned object also inherits from classes
"ranef.lme"
and "data.frame"
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York, esp. pp. 455-457.
lme
,
ranef.lme
,
plot.ranef.lme
, gsummary
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) coef(fm1) coef(fm1, augFrame = TRUE)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) coef(fm1) coef(fm1, augFrame = TRUE)
The coefficients of each lm
object in the object
list are
extracted and organized into a data frame, with rows corresponding to
the lm
components and columns corresponding to the
coefficients. Optionally, the returned data frame may be augmented
with covariates summarized over the groups associated with the
lm
components.
## S3 method for class 'lmList' coef(object, augFrame, data, which, FUN, omitGroupingFactor, ...)
## S3 method for class 'lmList' coef(object, augFrame, data, which, FUN, omitGroupingFactor, ...)
object |
an object inheriting from class |
augFrame |
an optional logical value. If |
data |
an optional data frame with the variables to be used for
augmenting the returned data frame when |
which |
an optional positive integer or character vector
specifying which columns of the data frame used to produce |
FUN |
an optional summary function or a list of summary functions
to be applied to group-varying variables, when collapsing the data
by groups. Group-invariant variables are always summarized by the
unique value that they assume within that group. If |
omitGroupingFactor |
an optional logical value. When |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame inheriting from class "coef.lmList"
with the estimated
coefficients for each "lm"
component of object
and,
optionally, other covariates summarized over the groups corresponding
to the "lm"
components. The returned object also inherits from
classes "ranef.lmList"
and "data.frame"
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York, esp. pp. 457-458.
lmList
, fixed.effects.lmList
,
ranef.lmList
,
plot.ranef.lmList
, gsummary
fm1 <- lmList(distance ~ age|Subject, data = Orthodont) coef(fm1) coef(fm1, augFrame = TRUE)
fm1 <- lmList(distance ~ age|Subject, data = Orthodont) coef(fm1) coef(fm1, augFrame = TRUE)
This method function extracts the coefficients associated with each
component of the modelStruct
list.
## S3 method for class 'modelStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'modelStruct' coef(object, ...) <- value
## S3 method for class 'modelStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'modelStruct' coef(object, ...) <- value
object |
an object inheriting from class |
unconstrained |
a logical value. If |
value |
a vector with the replacement values for the coefficients
associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with all coefficients corresponding to the components of
object
.
On the left side of an assignment, sets the values of the coefficients
of object
to value
. Object
must be initialized (using
Initialize
) before new values can be assigned to its
coefficients.
José Pinheiro and Douglas Bates [email protected]
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), corStruct = corAR1(0.3)) coef(lms1)
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), corStruct = corAR1(0.3)) coef(lms1)
This method function extracts the coefficients associated with the
positive-definite matrix represented by object
.
## S3 method for class 'pdMat' coef(object, unconstrained, ...) ## S3 replacement method for class 'pdMat' coef(object, ...) <- value
## S3 method for class 'pdMat' coef(object, unconstrained, ...) ## S3 replacement method for class 'pdMat' coef(object, ...) <- value
object |
an object inheriting from class |
unconstrained |
a logical value. If |
value |
a vector with the replacement values for the coefficients
associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the coefficients corresponding to object
.
On the left side of an assignment, sets the values of the coefficients
of object
to value
.
José Pinheiro and Douglas Bates
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
coef(pdSymm(diag(3)))
coef(pdSymm(diag(3)))
This method function extracts the coefficients associated with the
positive-definite matrix represented by object
.
## S3 method for class 'reStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'reStruct' coef(object, ...) <- value
## S3 method for class 'reStruct' coef(object, unconstrained, ...) ## S3 replacement method for class 'reStruct' coef(object, ...) <- value
object |
an object inheriting from class |
unconstrained |
a logical value. If |
value |
a vector with the replacement values for the coefficients
associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the coefficients corresponding to object
.
On the left side of an assignment, sets the values of the coefficients
of object
to value
.
José Pinheiro and Douglas Bates [email protected]
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) coef(rs1)
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) coef(rs1)
This method function extracts the coefficients associated with the
variance function structure represented by object
.
## S3 method for class 'varFunc' coef(object, unconstrained, allCoef, ...) ## S3 replacement method for class 'varIdent' coef(object, ...) <- value
## S3 method for class 'varFunc' coef(object, unconstrained, allCoef, ...) ## S3 replacement method for class 'varIdent' coef(object, ...) <- value
object |
an object inheriting from class |
unconstrained |
a logical value. If |
allCoef |
a logical value. If |
value |
a vector with the replacement values for the coefficients
associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the coefficients corresponding to object
.
On the left side of an assignment, sets the values of the coefficients
of object
to value
.
José Pinheiro and Douglas Bates
vf1 <- varPower(1) coef(vf1) coef(vf1) <- 2
vf1 <- varPower(1) coef(vf1) coef(vf1) <- 2
This function is generic; method functions can be written to handle
specific classes of objects. Currently, only a groupedData
method is available.
collapse(object, ...)
collapse(object, ...)
object |
an object to be collapsed, usually a data frame. |
... |
some methods for the generic may require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
## see the method function documentation
## see the method function documentation
If object
has a single grouping factor, it is returned
unchanged. Else, it is summarized by the values of the
displayLevel
grouping factor (or the combination of its values
and the values of the covariate indicated in preserve
, if any is
present). The collapsed data is used to produce a new
groupedData
object, with grouping factor given by the
displayLevel
factor.
## S3 method for class 'groupedData' collapse(object, collapseLevel, displayLevel, outer, inner, preserve, FUN, subset, ...)
## S3 method for class 'groupedData' collapse(object, collapseLevel, displayLevel, outer, inner, preserve, FUN, subset, ...)
object |
an object inheriting from class |
collapseLevel |
an optional positive integer or character string indicating the grouping level to use when collapsing the data. Level values increase from outermost to innermost grouping. Default is the highest or innermost level of grouping. |
displayLevel |
an optional positive integer or character string
indicating the grouping level to use as the grouping factor for the
collapsed data. Default is |
outer |
an optional logical value or one-sided formula,
indicating covariates that are outer to the |
inner |
an optional logical value or one-sided formula, indicating
a covariate that is inner to the |
preserve |
an optional one-sided formula indicating a covariate
whose levels should be preserved when collapsing the data according
to the |
FUN |
an optional summary function or a list of summary functions
to be used for collapsing the data. The function or functions are
applied only to variables in |
subset |
an optional named list. Names can be either positive
integers representing grouping levels, or names of grouping
factors. Each element in the list is a vector indicating the levels
of the corresponding grouping factor to be preserved in the collapsed
data. Default is |
... |
some methods for this generic require additional arguments. None are used in this method. |
a groupedData
object with a single grouping factor given by the
displayLevel
grouping factor, resulting from collapsing
object
over the levels of the collapseLevel
grouping
factor.
José Pinheiro and Douglas Bates [email protected]
groupedData
, plot.nmGroupedData
# collapsing by Dog collapse(Pixel, collapseLevel = 1) # same as collapse(Pixel, collapseLevel = "Dog")
# collapsing by Dog collapse(Pixel, collapseLevel = 1) # same as collapse(Pixel, collapseLevel = "Dog")
The columns in object1
and object2
are put together in
matrices which allow direct comparison of the individual elements for
each object. Missing columns in either object are replaced by
NA
s.
compareFits(object1, object2, which)
compareFits(object1, object2, which)
object1 , object2
|
data frames, or matrices, with the same
row names, but possibly different column names. These will usually
correspond to coefficients from fitted objects with a grouping
structure (e.g. |
which |
an optional integer or character vector indicating which
columns in |
a three-dimensional array, with the third dimension given by the number
of unique column names in either object1
or object2
. To
each column name there corresponds a matrix with as many rows as the
rows in object1
and two columns, corresponding to object1
and object2
. The returned object inherits from class
compareFits
.
José Pinheiro and Douglas Bates [email protected]
plot.compareFits
,
pairs.compareFits
,
comparePred
,
coef
,
random.effects
fm1 <- lmList(Orthodont) fm2 <- lme(fm1) (cF12 <- compareFits(coef(fm1), coef(fm2)))
fm1 <- lmList(Orthodont) fm2 <- lme(fm1) (cF12 <- compareFits(coef(fm1), coef(fm2)))
Predicted values are obtained at the specified values of
primary
for each object. If either object1
or
object2
have a grouping structure
(i.e. getGroups(object)
is not NULL
), predicted values
are obtained for each group. When both objects determine groups, the
group levels must be the same. If other covariates besides
primary
are used in the prediction model, their group-wise averages
(numeric covariates) or most frequent values (categorical covariates)
are used to obtain the predicted values. The original observations are
also included in the returned object.
comparePred(object1, object2, primary, minimum, maximum, length.out, level, ...)
comparePred(object1, object2, primary, minimum, maximum, length.out, level, ...)
object1 , object2
|
fitted model objects, from which predictions can
be extracted using the |
primary |
an optional one-sided formula specifying the primary
covariate to be used to generate the augmented predictions. By
default, if a covariate can be extracted from the data used to generate
the objects (using |
minimum |
an optional lower limit for the primary
covariate. Defaults to |
maximum |
an optional upper limit for the primary
covariate. Defaults to |
length.out |
an optional integer with the number of primary covariate values at which to evaluate the predictions. Defaults to 51. |
level |
an optional integer specifying the desired prediction level. Levels increase from outermost to innermost grouping, with level 0 representing the population (fixed effects) predictions. Only one level can be specified. Defaults to the innermost level. |
... |
some methods for the generic may require additional arguments. |
a data frame with four columns representing, respectively, the values
of the primary covariate, the groups (if object
does not have a
grouping structure, all elements will be 1
), the predicted or
observed values, and the type of value in the third column: the
objects' names are used to classify the predicted values and
original
is used for the observed values. The returned object
inherits from classes comparePred
and augPred
.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: gls
, lme
, and lmList
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age * Sex, data = Orthodont, random = ~ age) fm2 <- update(fm1, distance ~ age) comparePred(fm1, fm2, length.out = 2)
fm1 <- lme(distance ~ age * Sex, data = Orthodont, random = ~ age) fm2 <- update(fm1, distance ~ age) comparePred(fm1, fm2, length.out = 2)
This function is a constructor for the corAR1
class,
representing an autocorrelation structure of order 1. Objects
created using this constructor must later be initialized using the
appropriate Initialize
method.
corAR1(value, form, fixed)
corAR1(value, form, fixed)
value |
the value of the lag 1 autocorrelation, which must be between -1 and 1. Defaults to 0 (no autocorrelation). |
form |
a one sided formula of the form |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corAR1
, representing an autocorrelation
structure of order 1.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 235, 397.
ACF.lme
,
corARMA
,
corClasses
,
Dim.corSpatial
,
Initialize.corStruct
,
summary.corStruct
## covariate is observation order and grouping factor is Mare cs1 <- corAR1(0.2, form = ~ 1 | Mare) # Pinheiro and Bates, p. 236 cs1AR1 <- corAR1(0.8, form = ~ 1 | Subject) cs1AR1. <- Initialize(cs1AR1, data = Orthodont) corMatrix(cs1AR1.) # Pinheiro and Bates, p. 240 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm2Ovar.lme <- update(fm1Ovar.lme, correlation = corAR1()) # Pinheiro and Bates, pp. 255-258: use in gls fm1Dial.gls <- gls(rate ~(pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) fm3Dial.gls <- update(fm2Dial.gls, corr = corAR1(0.771, form = ~ 1 | Subject)) # Pinheiro and Bates use in nlme: # from p. 240 needed on p. 396 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm5Ovar.lme <- update(fm1Ovar.lme, correlation = corARMA(p = 1, q = 1)) # p. 396 fm1Ovar.nlme <- nlme(follicles~ A+B*sin(2*pi*w*Time)+C*cos(2*pi*w*Time), data=Ovary, fixed=A+B+C+w~1, random=pdDiag(A+B+w~1), start=c(fixef(fm5Ovar.lme), 1) ) # p. 397 fm2Ovar.nlme <- update(fm1Ovar.nlme, correlation=corAR1(0.311) )
## covariate is observation order and grouping factor is Mare cs1 <- corAR1(0.2, form = ~ 1 | Mare) # Pinheiro and Bates, p. 236 cs1AR1 <- corAR1(0.8, form = ~ 1 | Subject) cs1AR1. <- Initialize(cs1AR1, data = Orthodont) corMatrix(cs1AR1.) # Pinheiro and Bates, p. 240 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm2Ovar.lme <- update(fm1Ovar.lme, correlation = corAR1()) # Pinheiro and Bates, pp. 255-258: use in gls fm1Dial.gls <- gls(rate ~(pressure + I(pressure^2) + I(pressure^3) + I(pressure^4))*QB, Dialyzer) fm2Dial.gls <- update(fm1Dial.gls, weights = varPower(form = ~ pressure)) fm3Dial.gls <- update(fm2Dial.gls, corr = corAR1(0.771, form = ~ 1 | Subject)) # Pinheiro and Bates use in nlme: # from p. 240 needed on p. 396 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm5Ovar.lme <- update(fm1Ovar.lme, correlation = corARMA(p = 1, q = 1)) # p. 396 fm1Ovar.nlme <- nlme(follicles~ A+B*sin(2*pi*w*Time)+C*cos(2*pi*w*Time), data=Ovary, fixed=A+B+C+w~1, random=pdDiag(A+B+w~1), start=c(fixef(fm5Ovar.lme), 1) ) # p. 397 fm2Ovar.nlme <- update(fm1Ovar.nlme, correlation=corAR1(0.311) )
This function is a constructor for the corARMA
class,
representing an autocorrelation-moving average correlation structure
of order (p, q). Objects created using this constructor must later
be initialized using the appropriate Initialize
method.
corARMA(value, form, p, q, fixed)
corARMA(value, form, p, q, fixed)
value |
a vector with the values of the autoregressive and moving
average parameters, which must have length |
form |
a one sided formula of the form |
p , q
|
non-negative integers specifying respectively the autoregressive order and the moving average order of the ARMA structure. Both default to 0, but at least one should be > 0. |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corARMA
, representing an
autocorrelation-moving average correlation structure.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 236, 397.
corAR1
,
corClasses
Initialize.corStruct
,
summary.corStruct
## ARMA(1,2) structure, with observation order as a covariate and ## Mare as grouping factor cs1 <- corARMA(c(0.2, 0.3, -0.1), form = ~ 1 | Mare, p = 1, q = 2) # Pinheiro and Bates, p. 237 cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) corMatrix(cs1ARMA) cs2ARMA <- corARMA(c(0.8, 0.4), form = ~ 1 | Subject, p=1, q=1) cs2ARMA <- Initialize(cs2ARMA, data = Orthodont) corMatrix(cs2ARMA) # Pinheiro and Bates use in nlme: # from p. 240 needed on p. 396 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm5Ovar.lme <- update(fm1Ovar.lme, correlation = corARMA(p = 1, q = 1)) # p. 396 fm1Ovar.nlme <- nlme(follicles~ A+B*sin(2*pi*w*Time)+C*cos(2*pi*w*Time), data=Ovary, fixed=A+B+C+w~1, random=pdDiag(A+B+w~1), start=c(fixef(fm5Ovar.lme), 1) ) # p. 397 fm3Ovar.nlme <- update(fm1Ovar.nlme, correlation=corARMA(p=0, q=2) )
## ARMA(1,2) structure, with observation order as a covariate and ## Mare as grouping factor cs1 <- corARMA(c(0.2, 0.3, -0.1), form = ~ 1 | Mare, p = 1, q = 2) # Pinheiro and Bates, p. 237 cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) corMatrix(cs1ARMA) cs2ARMA <- corARMA(c(0.8, 0.4), form = ~ 1 | Subject, p=1, q=1) cs2ARMA <- Initialize(cs2ARMA, data = Orthodont) corMatrix(cs2ARMA) # Pinheiro and Bates use in nlme: # from p. 240 needed on p. 396 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm5Ovar.lme <- update(fm1Ovar.lme, correlation = corARMA(p = 1, q = 1)) # p. 396 fm1Ovar.nlme <- nlme(follicles~ A+B*sin(2*pi*w*Time)+C*cos(2*pi*w*Time), data=Ovary, fixed=A+B+C+w~1, random=pdDiag(A+B+w~1), start=c(fixef(fm5Ovar.lme), 1) ) # p. 397 fm3Ovar.nlme <- update(fm1Ovar.nlme, correlation=corARMA(p=0, q=2) )
This function is a constructor for the corCAR1
class,
representing an autocorrelation structure of order 1, with a
continuous time covariate. Objects created using this constructor must
be later initialized using the appropriate Initialize
method.
corCAR1(value, form, fixed)
corCAR1(value, form, fixed)
value |
the correlation between two observations one unit of time apart. Must be between 0 and 1. Defaults to 0.2. |
form |
a one sided formula of the form |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corCAR1
, representing an autocorrelation
structure of order 1, with a continuous time covariate.
José Pinheiro and Douglas Bates [email protected]
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Jones, R.H. (1993) "Longitudinal Data with Serial Correlation: A State-space Approach", Chapman and Hall.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 236, 243.
corClasses
,
Initialize.corStruct
,
summary.corStruct
## covariate is Time and grouping factor is Mare cs1 <- corCAR1(0.2, form = ~ Time | Mare) # Pinheiro and Bates, pp. 240, 243 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm4Ovar.lme <- update(fm1Ovar.lme, correlation = corCAR1(form = ~Time))
## covariate is Time and grouping factor is Mare cs1 <- corCAR1(0.2, form = ~ Time | Mare) # Pinheiro and Bates, pp. 240, 243 fm1Ovar.lme <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = pdDiag(~sin(2*pi*Time))) fm4Ovar.lme <- update(fm1Ovar.lme, correlation = corCAR1(form = ~Time))
Standard classes of correlation structures (corStruct
)
available in the nlme
package.
Available standard classes:
corAR1 |
autoregressive process of order 1. |
corARMA |
autoregressive moving average process, with arbitrary orders for the autoregressive and moving average components. |
corCAR1 |
continuous autoregressive process (AR(1) process for a continuous time covariate). |
corCompSymm |
compound symmetry structure corresponding to a constant correlation. |
corExp |
exponential spatial correlation. |
corGaus |
Gaussian spatial correlation. |
corLin |
linear spatial correlation. |
corRatio |
Rational quadratics spatial correlation. |
corSpher |
spherical spatial correlation. |
corSymm |
general correlation matrix, with no additional structure. |
Users may define their own corStruct
classes by specifying a
constructor
function and, at a minimum, methods for the
functions corMatrix
and coef
. For
examples of these functions, see the methods for classes corSymm
and corAR1
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
corAR1
, corARMA
,
corCAR1
, corCompSymm
,
corExp
, corGaus
,
corLin
,
corRatio
, corSpher
,
corSymm
,
summary.corStruct
This function is a constructor for the corCompSymm
class,
representing a compound symmetry structure corresponding to uniform
correlation. Objects created using this constructor must later be
initialized using the appropriate Initialize
method.
corCompSymm(value, form, fixed)
corCompSymm(value, form, fixed)
value |
the correlation between any two correlated observations. Defaults to 0. |
form |
a one sided formula of the form |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corCompSymm
, representing a compound
symmetry correlation structure.
José Pinheiro and Douglas Bates [email protected]
Milliken, G. A. and Johnson, D. E. (1992) "Analysis of Messy Data, Volume I: Designed Experiments", Van Nostrand Reinhold.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 233-234.
corClasses
,
Initialize.corStruct
,
summary.corStruct
## covariate is observation order and grouping factor is Subject cs1 <- corCompSymm(0.5, form = ~ 1 | Subject) # Pinheiro and Bates, pp. 222-225 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs2CompSymm <- corCompSymm(value = 0.3, form = ~ age | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) ## Print/Summary methods for the empty case: (cCS <- corCompSymm()) # Uninitialized correlation struc.. summary(cCS) # (ditto)
## covariate is observation order and grouping factor is Subject cs1 <- corCompSymm(0.5, form = ~ 1 | Subject) # Pinheiro and Bates, pp. 222-225 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs2CompSymm <- corCompSymm(value = 0.3, form = ~ age | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) ## Print/Summary methods for the empty case: (cCS <- corCompSymm()) # Uninitialized correlation struc.. summary(cCS) # (ditto)
This function is a constructor for the "corExp"
class,
representing an exponential spatial correlation structure. Letting
denote the range and
denote the nugget
effect, the correlation between two observations a distance
apart is
when no nugget effect
is present and
when a nugget
effect is assumed. Objects created using this constructor must later be
initialized using the appropriate
Initialize
method.
corExp(value, form, nugget, metric, fixed)
corExp(value, form, nugget, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class "corExp"
, also inheriting from class
"corSpatial"
, representing an exponential spatial correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 238.
corClasses
,
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corExp(form = ~ x + y + z) # Pinheiro and Bates, p. 238 spatDat <- data.frame(x = (0:4)/4, y = (0:4)/4) cs1Exp <- corExp(1, form = ~ x + y) cs1Exp <- Initialize(cs1Exp, spatDat) corMatrix(cs1Exp) cs2Exp <- corExp(1, form = ~ x + y, metric = "man") cs2Exp <- Initialize(cs2Exp, spatDat) corMatrix(cs2Exp) cs3Exp <- corExp(c(1, 0.2), form = ~ x + y, nugget = TRUE) cs3Exp <- Initialize(cs3Exp, spatDat) corMatrix(cs3Exp) # example lme(..., corExp ...) # Pinheiro and Bates, pp. 222-247 # p. 222 options(contrasts = c("contr.treatment", "contr.poly")) fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p. 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 247 fm4BW.lme <- update(fm3BW.lme, correlation = corExp(form = ~ Time, nugget = TRUE)) anova(fm3BW.lme, fm4BW.lme)
sp1 <- corExp(form = ~ x + y + z) # Pinheiro and Bates, p. 238 spatDat <- data.frame(x = (0:4)/4, y = (0:4)/4) cs1Exp <- corExp(1, form = ~ x + y) cs1Exp <- Initialize(cs1Exp, spatDat) corMatrix(cs1Exp) cs2Exp <- corExp(1, form = ~ x + y, metric = "man") cs2Exp <- Initialize(cs2Exp, spatDat) corMatrix(cs2Exp) cs3Exp <- corExp(c(1, 0.2), form = ~ x + y, nugget = TRUE) cs3Exp <- Initialize(cs3Exp, spatDat) corMatrix(cs3Exp) # example lme(..., corExp ...) # Pinheiro and Bates, pp. 222-247 # p. 222 options(contrasts = c("contr.treatment", "contr.poly")) fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p. 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 247 fm4BW.lme <- update(fm3BW.lme, correlation = corExp(form = ~ Time, nugget = TRUE)) anova(fm3BW.lme, fm4BW.lme)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include all corStruct
classes.
corFactor(object, ...)
corFactor(object, ...)
object |
an object from which a correlation matrix can be extracted. |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
corFactor.corStruct
,
recalc.corStruct
## see the method function documentation
## see the method function documentation
This method function extracts a transpose inverse square-root factor,
or a series of transpose inverse square-root factors, of the
correlation matrix, or list of correlation matrices, represented by
object
. Letting denote a correlation
matrix, a square-root factor of
is any square
matrix
such that
. This method
extracts
.
## S3 method for class 'corStruct' corFactor(object, ...)
## S3 method for class 'corStruct' corFactor(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
If the correlation structure does not include a grouping factor, the
returned value will be a vector with a transpose inverse square-root
factor of the correlation matrix associated with object
stacked
column-wise. If the correlation structure includes a grouping factor,
the returned value will be a vector with transpose inverse
square-root factors of the correlation matrices for each group, stacked
by group and stacked column-wise within each group.
This method function is used intensively in optimization
algorithms and its value is returned as a vector for efficiency
reasons. The corMatrix
method function can be used to obtain
transpose inverse square-root factors in matrix form.
José Pinheiro and Douglas Bates [email protected]
corFactor
,
corMatrix.corStruct
,
recalc.corStruct
,
Initialize.corStruct
cs1 <- corAR1(form = ~1 | Subject) cs1 <- Initialize(cs1, data = Orthodont) corFactor(cs1)
cs1 <- corAR1(form = ~1 | Subject) cs1 <- Initialize(cs1, data = Orthodont) corFactor(cs1)
This function is a constructor for the corGaus
class,
representing a Gaussian spatial correlation structure. Letting
denote the range and
denote the nugget
effect, the correlation between two observations a distance
apart is
when no nugget
effect is present and
when a nugget effect is assumed. Objects created using this
constructor must later be initialized using the appropriate
'
Initialize
method.
corGaus(value, form, nugget, metric, fixed)
corGaus(value, form, nugget, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corGaus
, also inheriting from class
corSpatial
, representing a Gaussian spatial correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corGaus(form = ~ x + y + z) # example lme(..., corGaus ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm8BW.lme <- update(fm3BW.lme, correlation = corGaus(form = ~ Time))
sp1 <- corGaus(form = ~ x + y + z) # example lme(..., corGaus ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm8BW.lme <- update(fm3BW.lme, correlation = corGaus(form = ~ Time))
This function is a constructor for the corLin
class,
representing a linear spatial correlation structure. Letting
denote the range and
denote the nugget
effect, the correlation between two observations a distance
apart is
when no nugget effect
is present and
when a nugget
effect is assumed. If
the correlation is
zero. Objects created using this constructor must later be
initialized using the appropriate
Initialize
method.
corLin(value, form, nugget, metric, fixed)
corLin(value, form, nugget, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corLin
, also inheriting from class
corSpatial
, representing a linear spatial correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corLin(form = ~ x + y) # example lme(..., corLin ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm7BW.lme <- update(fm3BW.lme, correlation = corLin(form = ~ Time))
sp1 <- corLin(form = ~ x + y) # example lme(..., corLin ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm7BW.lme <- update(fm3BW.lme, correlation = corLin(form = ~ Time))
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include all corStruct
classes.
corMatrix(object, ...)
corMatrix(object, ...)
object |
an object for which a correlation matrix can be extracted. |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
corMatrix.corStruct
,
corMatrix.pdMat
## see the method function documentation
## see the method function documentation
This method function extracts the correlation matrix (or its transpose
inverse square-root factor), or list of correlation matrices (or their
transpose inverse square-root factors) corresponding to
covariate
and object
. Letting denote
a correlation matrix, a square-root factor of
is
any square matrix
such that
. When
corr = FALSE
, this method extracts .
## S3 method for class 'corStruct' corMatrix(object, covariate, corr, ...)
## S3 method for class 'corStruct' corMatrix(object, covariate, corr, ...)
object |
an object inheriting from class |
covariate |
an optional covariate vector (matrix), or list of
covariate vectors (matrices), at which values the correlation matrix,
or list of correlation matrices, are to be evaluated. Defaults to
|
corr |
a logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
If covariate
is a vector (matrix), the returned value will be
an array with the corresponding correlation matrix (or its transpose
inverse square-root factor). If the covariate
is a list of
vectors (matrices), the returned value will be a list with the
correlation matrices (or their transpose inverse square-root factors)
corresponding to each component of covariate
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
corFactor.corStruct
, Initialize.corStruct
cs1 <- corAR1(0.3) corMatrix(cs1, covariate = 1:4) corMatrix(cs1, covariate = 1:4, corr = FALSE) # Pinheiro and Bates, p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) # Pinheiro and Bates, p. 226 cs1Symm <- corSymm(value = c(0.2, 0.1, -0.1, 0, 0.2, 0), form = ~ 1 | Subject) cs1Symm <- Initialize(cs1Symm, data = Orthodont) corMatrix(cs1Symm) # Pinheiro and Bates, p. 236 cs1AR1 <- corAR1(0.8, form = ~ 1 | Subject) cs1AR1 <- Initialize(cs1AR1, data = Orthodont) corMatrix(cs1AR1) # Pinheiro and Bates, p. 237 cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) corMatrix(cs1ARMA) # Pinheiro and Bates, p. 238 spatDat <- data.frame(x = (0:4)/4, y = (0:4)/4) cs1Exp <- corExp(1, form = ~ x + y) cs1Exp <- Initialize(cs1Exp, spatDat) corMatrix(cs1Exp)
cs1 <- corAR1(0.3) corMatrix(cs1, covariate = 1:4) corMatrix(cs1, covariate = 1:4, corr = FALSE) # Pinheiro and Bates, p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) # Pinheiro and Bates, p. 226 cs1Symm <- corSymm(value = c(0.2, 0.1, -0.1, 0, 0.2, 0), form = ~ 1 | Subject) cs1Symm <- Initialize(cs1Symm, data = Orthodont) corMatrix(cs1Symm) # Pinheiro and Bates, p. 236 cs1AR1 <- corAR1(0.8, form = ~ 1 | Subject) cs1AR1 <- Initialize(cs1AR1, data = Orthodont) corMatrix(cs1AR1) # Pinheiro and Bates, p. 237 cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) corMatrix(cs1ARMA) # Pinheiro and Bates, p. 238 spatDat <- data.frame(x = (0:4)/4, y = (0:4)/4) cs1Exp <- corExp(1, form = ~ x + y) cs1Exp <- Initialize(cs1Exp, spatDat) corMatrix(cs1Exp)
The correlation matrix corresponding to the positive-definite matrix
represented by object
is obtained.
## S3 method for class 'pdMat' corMatrix(object, ...)
## S3 method for class 'pdMat' corMatrix(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
the correlation matrix corresponding to the positive-definite matrix
represented by object
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdSymm(diag(1:4)) corMatrix(pd1)
pd1 <- pdSymm(diag(1:4)) corMatrix(pd1)
This method function extracts the correlation matrices
corresponding to the pdMat
elements of object
.
## S3 method for class 'reStruct' corMatrix(object, ...)
## S3 method for class 'reStruct' corMatrix(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by the correlation matrices
corresponding to the elements of object
.
José Pinheiro and Douglas Bates [email protected]
as.matrix.reStruct
,
corMatrix
, reStruct
,
pdMat
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) corMatrix(rs1)
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) corMatrix(rs1)
This function is a constructor for the corNatural
class,
representing a general correlation structure in the “natural”
parameterization, which is described under pdNatural
.
Objects created using this constructor must later be
initialized using the appropriate Initialize
method.
corNatural(value, form, fixed)
corNatural(value, form, fixed)
value |
an optional vector with the parameter values. Default is
|
form |
a one sided formula of the form |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corNatural
representing a general correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Initialize.corNatural
,
pdNatural
,
summary.corNatural
## covariate is observation order and grouping factor is Subject cs1 <- corNatural(form = ~ 1 | Subject)
## covariate is observation order and grouping factor is Subject cs1 <- corNatural(form = ~ 1 | Subject)
This function is a constructor for the corRatio
class,
representing a rational quadratic spatial correlation structure. Letting
denote the range and
denote the nugget
effect, the correlation between two observations a distance
apart is
when no nugget effect
is present and
when a
nugget effect is assumed. Objects created using this constructor need
to be later initialized using the appropriate
Initialize
method.
corRatio(value, form, nugget, metric, fixed)
corRatio(value, form, nugget, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corRatio
, also inheriting from class
corSpatial
, representing a rational quadratic spatial correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corRatio(form = ~ x + y + z) # example lme(..., corRatio ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm5BW.lme <- update(fm3BW.lme, correlation = corRatio(form = ~ Time)) # example gls(..., corRatio ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 263 fm3Wheat2 <- update(fm1Wheat2, corr = corRatio(c(12.5, 0.2), form = ~ latitude + longitude, nugget = TRUE))
sp1 <- corRatio(form = ~ x + y + z) # example lme(..., corRatio ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm5BW.lme <- update(fm3BW.lme, correlation = corRatio(form = ~ Time)) # example gls(..., corRatio ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 263 fm3Wheat2 <- update(fm1Wheat2, corr = corRatio(c(12.5, 0.2), form = ~ latitude + longitude, nugget = TRUE))
This function is a constructor for the corSpatial
class,
representing a spatial correlation structure. This class is "virtual",
having four "real" classes, corresponding to specific spatial
correlation structures, associated with it: corExp
,
corGaus
, corLin
, corRatio
, and
corSpher
. The returned object will inherit from one of these
"real" classes, determined by the type
argument, and from the
"virtual" corSpatial
class. Objects created using this
constructor must later be initialized using the appropriate
Initialize
method.
corSpatial(value, form, nugget, type, metric, fixed)
corSpatial(value, form, nugget, type, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
type |
an optional character string specifying the desired type of
correlation structure. Available types include |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class determined by the type
argument and also
inheriting from class corSpatial
, representing a spatial
correlation structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
corExp
,
corGaus
,
corLin
,
corRatio
,
corSpher
,
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corSpatial(form = ~ x + y + z, type = "g", metric = "man")
sp1 <- corSpatial(form = ~ x + y + z, type = "g", metric = "man")
This function is a constructor for the corSpher
class,
representing a spherical spatial correlation structure. Letting
denote the range and
denote the nugget
effect, the correlation between two observations a distance
apart is
when no
nugget effect is present and
when a nugget effect is assumed. If
the
correlation is zero. Objects created using this constructor must later
be initialized using the appropriate
Initialize
method.
corSpher(value, form, nugget, metric, fixed)
corSpher(value, form, nugget, metric, fixed)
value |
an optional vector with the parameter values in
constrained form. If |
form |
a one sided formula of the form |
nugget |
an optional logical value indicating whether a nugget
effect is present. Defaults to |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corSpher
, also inheriting from class
corSpatial
, representing a spherical spatial correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Littel, Milliken, Stroup, and Wolfinger (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corStruct
,
summary.corStruct
,
dist
sp1 <- corSpher(form = ~ x + y) # example lme(..., corSpher ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm6BW.lme <- update(fm3BW.lme, correlation = corSpher(form = ~ Time)) # example gls(..., corSpher ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 262 fm2Wheat2 <- update(fm1Wheat2, corr = corSpher(c(28, 0.2), form = ~ latitude + longitude, nugget = TRUE))
sp1 <- corSpher(form = ~ x + y) # example lme(..., corSpher ...) # Pinheiro and Bates, pp. 222-249 fm1BW.lme <- lme(weight ~ Time * Diet, BodyWeight, random = ~ Time) # p. 223 fm2BW.lme <- update(fm1BW.lme, weights = varPower()) # p 246 fm3BW.lme <- update(fm2BW.lme, correlation = corExp(form = ~ Time)) # p. 249 fm6BW.lme <- update(fm3BW.lme, correlation = corSpher(form = ~ Time)) # example gls(..., corSpher ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 262 fm2Wheat2 <- update(fm1Wheat2, corr = corSpher(c(28, 0.2), form = ~ latitude + longitude, nugget = TRUE))
This function is a constructor for the corSymm
class,
representing a general correlation structure. The internal
representation of this structure, in terms of unconstrained
parameters, uses the spherical parametrization defined in Pinheiro and
Bates (1996). Objects created using this constructor must later be
initialized using the appropriate Initialize
method.
corSymm(value, form, fixed)
corSymm(value, form, fixed)
value |
an optional vector with the parameter values. Default is
|
form |
a one sided formula of the form |
fixed |
an optional logical value indicating whether the
coefficients should be allowed to vary in the optimization, or kept
fixed at their initial value. Defaults to |
an object of class corSymm
representing a general correlation
structure.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corSymm
,
summary.corSymm
## covariate is observation order and grouping factor is Subject cs1 <- corSymm(form = ~ 1 | Subject) # Pinheiro and Bates, p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) # Pinheiro and Bates, p. 226 cs1Symm <- corSymm(value = c(0.2, 0.1, -0.1, 0, 0.2, 0), form = ~ 1 | Subject) cs1Symm <- Initialize(cs1Symm, data = Orthodont) corMatrix(cs1Symm) # example gls(..., corSpher ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 262 fm2Wheat2 <- update(fm1Wheat2, corr = corSpher(c(28, 0.2), form = ~ latitude + longitude, nugget = TRUE)) # example gls(..., corSymm ... ) # Pinheiro and Bates, p. 251 fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age))
## covariate is observation order and grouping factor is Subject cs1 <- corSymm(form = ~ 1 | Subject) # Pinheiro and Bates, p. 225 cs1CompSymm <- corCompSymm(value = 0.3, form = ~ 1 | Subject) cs1CompSymm <- Initialize(cs1CompSymm, data = Orthodont) corMatrix(cs1CompSymm) # Pinheiro and Bates, p. 226 cs1Symm <- corSymm(value = c(0.2, 0.1, -0.1, 0, 0.2, 0), form = ~ 1 | Subject) cs1Symm <- Initialize(cs1Symm, data = Orthodont) corMatrix(cs1Symm) # example gls(..., corSpher ...) # Pinheiro and Bates, pp. 261, 263 fm1Wheat2 <- gls(yield ~ variety - 1, Wheat2) # p. 262 fm2Wheat2 <- update(fm1Wheat2, corr = corSpher(c(28, 0.2), form = ~ latitude + longitude, nugget = TRUE)) # example gls(..., corSymm ... ) # Pinheiro and Bates, p. 251 fm1Orth.gls <- gls(distance ~ Sex * I(age - 11), Orthodont, correlation = corSymm(form = ~ 1 | Subject), weights = varIdent(form = ~ 1 | age))
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include all "varFunc"
classes.
covariate(object) <- value
covariate(object) <- value
object |
any object with a |
value |
a value to be assigned to the covariate associated with
|
will depend on the method function; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
## see the method function documentation
## see the method function documentation
The covariate(s) used in the calculation of the weights of the
variance function represented by object
is (are) replaced by
value
. If object
has been initialized, value
must
have the same dimensions as getCovariate(object)
.
## S3 replacement method for class 'varFunc' covariate(object) <- value
## S3 replacement method for class 'varFunc' covariate(object) <- value
object |
an object inheriting from class |
value |
a value to be assigned to the covariate associated with
|
a varFunc
object similar to object
, but with its
covariate
attribute replaced by value
.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(1.1, form = ~age) covariate(vf1) <- Orthodont[["age"]]
vf1 <- varPower(1.1, form = ~age) covariate(vf1) <- Orthodont[["age"]]
The Dialyzer
data frame has 140 rows and 5 columns.
This data frame contains the following columns:
an ordered factor with levels
10
< 8
< 2
< 6
< 3
<
5
< 9
< 7
< 1
< 4
<
17
< 20
< 11
< 12
< 16
<
13
< 14
< 18
< 15
< 19
giving the unique identifier for each subject
a factor with levels
200
and
300
giving the bovine blood flow rate (dL/min).
a numeric vector giving the transmembrane pressure (dmHg).
the hemodialyzer ultrafiltration rate (mL/hr).
index of observation within subject—1 through 7.
Vonesh and Carter (1992) describe data measured on high-flux hemodialyzers to assess their in vivo ultrafiltration characteristics. The ultrafiltration rates (in mL/hr) of 20 high-flux dialyzers were measured at seven different transmembrane pressures (in dmHg). The in vitro evaluation of the dialyzers used bovine blood at flow rates of either 200~dl/min or 300~dl/min. The data, are also analyzed in Littell, Milliken, Stroup, and Wolfinger (1996).
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.6)
Vonesh, E. F. and Carter, R. L. (1992), Mixed-effects nonlinear regression for unbalanced repeated measures, Biometrics, 48, 1-18.
Littell, R. C., Milliken, G. A., Stroup, W. W. and Wolfinger, R. D. (1996), SAS System for Mixed Models, SAS Institute, Cary, NC.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: "corSpatial"
, "corStruct"
,
"pdCompSymm"
, "pdDiag"
, "pdIdent"
, "pdMat"
,
and "pdSymm"
.
Dim(object, ...)
Dim(object, ...)
object |
any object for which dimensions can be extracted. |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
If dim
allowed more than one argument, there would be no
need for this generic function.
José Pinheiro and Douglas Bates [email protected]
## see the method function documentation
## see the method function documentation
if groups
is missing, it returns the Dim
attribute of
object
; otherwise, calculates the dimensions associated with
the grouping factor.
## S3 method for class 'corSpatial' Dim(object, groups, ...)
## S3 method for class 'corSpatial' Dim(object, groups, ...)
object |
an object inheriting from class |
groups |
an optional factor defining the grouping of the observations; observations within a group are correlated and observations in different groups are uncorrelated. |
... |
further arguments to be passed to or from methods. |
a list with components:
N |
length of |
M |
number of groups |
spClass |
an integer representing the spatial correlation class;
0 = user defined class, 1 = |
sumLenSq |
sum of the squares of the number of observations per group |
len |
an integer vector with the number of observations per group |
start |
an integer vector with the starting position for the distance vectors in each group, beginning from zero |
José Pinheiro and Douglas Bates [email protected]
Dim(corGaus(), getGroups(Orthodont)) cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) Dim(cs1ARMA)
Dim(corGaus(), getGroups(Orthodont)) cs1ARMA <- corARMA(0.4, form = ~ 1 | Subject, q = 1) cs1ARMA <- Initialize(cs1ARMA, data = Orthodont) Dim(cs1ARMA)
if groups
is missing, it returns the Dim
attribute of
object
; otherwise, calculates the dimensions associated with
the grouping factor.
## S3 method for class 'corStruct' Dim(object, groups, ...)
## S3 method for class 'corStruct' Dim(object, groups, ...)
object |
an object inheriting from class |
groups |
an optional factor defining the grouping of the observations; observations within a group are correlated and observations in different groups are uncorrelated. |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components:
N |
length of |
M |
number of groups |
maxLen |
maximum number of observations in a group |
sumLenSq |
sum of the squares of the number of observations per group |
len |
an integer vector with the number of observations per group |
start |
an integer vector with the starting position for the observations in each group, beginning from zero |
José Pinheiro and Douglas Bates [email protected]
Dim(corAR1(), getGroups(Orthodont))
Dim(corAR1(), getGroups(Orthodont))
This method function returns the dimensions of the matrix represented
by object
.
## S3 method for class 'pdMat' Dim(object, ...)
## S3 method for class 'pdMat' Dim(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
an integer vector with the number of rows and columns of the
matrix represented by object
.
José Pinheiro and Douglas Bates [email protected]
Dim(pdSymm(diag(3)))
Dim(pdSymm(diag(3)))
The Earthquake
data frame has 182 rows and 5 columns.
This data frame contains the following columns:
an ordered factor with levels
20
< 16
< 14
< 10
< 3
<
8
< 23
< 22
< 6
< 13
<
7
< 21
< 18
< 15
< 4
<
12
< 19
< 5
< 9
< 1
<
2
< 17
< 11
indicating the earthquake
on which the measurements were made.
a numeric vector giving the intensity of the earthquake on the Richter scale.
the distance from the seismological measuring station to the epicenter of the earthquake (km).
a factor with levels 0
and 1
giving the soil condition at the measuring station, either
soil or rock.
maximum horizontal acceleration observed (g).
Measurements recorded at available seismometer locations for 23 large earthquakes in western North America between 1940 and 1980. They were originally given in Joyner and Boore (1981); are mentioned in Brillinger (1987); and are analyzed in Davidian and Giltinan (1995).
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.8)
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London.
Joyner and Boore (1981), Peak horizontal acceleration and velocity from strong-motion records including records from the 1979 Imperial Valley, California, earthquake, Bulletin of the Seismological Society of America, 71, 2011-2038.
Brillinger, D. (1987), Comment on a paper by C. R. Rao, Statistical Science, 2, 448-450.
The ergoStool
data frame has 36 rows and 3 columns.
This data frame contains the following columns:
a numeric vector giving the effort (Borg scale) required to arise from a stool.
a factor with levels
T1
,
T2
,
T3
, and
T4
giving the stool type.
an ordered factor giving a unique identifier for the subject in the experiment.
Devore (2000) cites data from an article in Ergometrics (1993, pp. 519-535) on “The Effects of a Pneumatic Stool and a One-Legged Stool on Lower Limb Joint Load and Muscular Activity.”
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.9)
Devore, J. L. (2000), Probability and Statistics for Engineering and the Sciences (5th ed), Duxbury, Boston, MA.
fm1 <- lme(effort ~ Type, data = ergoStool, random = ~ 1 | Subject) anova( fm1 )
fm1 <- lme(effort ~ Type, data = ergoStool, random = ~ 1 | Subject) anova( fm1 )
The Fatigue
data frame has 262 rows and 3 columns.
This data frame contains the following columns:
an ordered factor with levels
1
< 2
< 3
< 4
< 5
<
6
< 7
< 8
< 9
< 10
<
11
< 12
< 13
< 14
< 15
<
16
< 17
< 18
< 19
< 20
<
21
giving the test path (or test unit) number. The
order is in terms of increasing failure time or decreasing
terminal crack length.
number of test cycles at which the measurement is made (millions of cycles).
relative crack length (dimensionless).
These data are given in Lu and Meeker (1993) where they state “We obtained the data in Table 1 visually from figure 4.5.2 on page 242 of Bogdanoff and Kozin (1985).” The data represent the growth of cracks in metal for 21 test units. An initial notch of length 0.90 inches was made on each unit which then was subjected to several thousand test cycles. After every 10,000 test cycles the crack length was measured. Testing was stopped if the crack length exceeded 1.60 inches, defined as a failure, or at 120,000 cycles.
Lu, C. Joséph , and Meeker, William Q. (1993), Using degradation measures to estimate a time-to-failure distribution, Technometrics, 35, 161-174
Evaluate an approximate Hessian and gradient of a scalar function using finite differences.
fdHess(pars, fun, ..., .relStep = .Machine$double.eps^(1/3), minAbsPar = 0)
fdHess(pars, fun, ..., .relStep = .Machine$double.eps^(1/3), minAbsPar = 0)
pars |
the numeric values of the parameters at which to evaluate the
function |
fun |
a function depending on the parameters |
... |
Optional additional arguments to |
.relStep |
The relative step size to use in the finite
differences. It defaults to the cube root of |
minAbsPar |
The minimum magnitude of a parameter value that is considered non-zero. It defaults to zero meaning that any non-zero value will be considered different from zero. |
This function uses a second-order response surface design known as a “Koschal design” to determine the parameter values at which the function is evaluated.
A list with components
mean |
the value of function |
gradient |
an approximate gradient (of length |
Hessian |
a matrix whose upper triangle contains an approximate Hessian. |
José Pinheiro and Douglas Bates [email protected]
(fdH <- fdHess(c(12.3, 2.34), function(x) x[1]*(1-exp(-0.4*x[2])))) stopifnot(length(fdH$ mean) == 1, length(fdH$ gradient) == 2, identical(dim(fdH$ Hessian), c(2L, 2L)))
(fdH <- fdHess(c(12.3, 2.34), function(x) x[1]*(1-exp(-0.4*x[2])))) stopifnot(length(fdH$ mean) == 1, length(fdH$ gradient) == 2, identical(dim(fdH$ Hessian), c(2L, 2L)))
The fitted values for the linear model represented by object
are extracted.
## S3 method for class 'glsStruct' fitted(object, glsFit, ...)
## S3 method for class 'glsStruct' fitted(object, glsFit, ...)
object |
an object inheriting from class |
glsFit |
an optional list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the fitted values for the linear model represented by
object
.
This method function is generally only used inside gls
and
fitted.gls
.
José Pinheiro and Douglas Bates [email protected]
The fitted values for the nonlinear model represented by object
are extracted.
## S3 method for class 'gnlsStruct' fitted(object, ...)
## S3 method for class 'gnlsStruct' fitted(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the fitted values for the nonlinear model represented by
object
.
This method function is generally only used inside gnls
and
fitted.gnls
.
José Pinheiro and Douglas Bates [email protected]
The fitted values at level are obtained by adding together the
population fitted values (based only on the fixed effects estimates)
and the estimated contributions of the random effects to the fitted
values at grouping levels less or equal to
. The resulting
values estimate the best linear unbiased predictions (BLUPs) at level
.
## S3 method for class 'lme' fitted(object, level, asList, ...)
## S3 method for class 'lme' fitted(object, level, asList, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the fitted values from |
asList |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
If a single level of grouping is specified in level
, the
returned value is either a list with the fitted values split by groups
(asList = TRUE
) or a vector with the fitted values
(asList = FALSE
); else, when multiple grouping levels are
specified in level
, the returned object is a data frame with
columns given by the fitted values at different levels and the
grouping factors. For a vector or data frame result the
napredict
method is applied.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1998) "Computational methods for multilevel models" available in PostScript or PDF formats at http://nlme.stat.wisc.edu/pub/NLME/
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 235, 397.
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) fitted(fm1, level = 0:1)
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) fitted(fm1, level = 0:1)
The fitted values at level are obtained by adding together the
population fitted values (based only on the fixed effects estimates)
and the estimated contributions of the random effects to the fitted
values at grouping levels less or equal to
. The resulting
values estimate the best linear unbiased predictions (BLUPs) at level
.
## S3 method for class 'lmeStruct' fitted(object, level, conLin, lmeFit, ...)
## S3 method for class 'lmeStruct' fitted(object, level, conLin, lmeFit, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the fitted values from |
conLin |
an optional condensed linear model object, consisting of
a list with components |
lmeFit |
an optional list with components |
... |
some methods for this generic accept other optional arguments. |
if a single level of grouping is specified in level
,
the returned value is a vector with the fitted values at the desired
level; else, when multiple grouping levels are specified in
level
, the returned object is a matrix with
columns given by the fitted values at different levels.
This method function is generally only used inside lme
and
fitted.lme
.
José Pinheiro and Douglas Bates [email protected]
lme
, fitted.lme
,
residuals.lmeStruct
The fitted values are extracted from each lm
component of
object
and arranged into a list with as many components as
object
, or combined into a single vector.
## S3 method for class 'lmList' fitted(object, subset, asList, ...)
## S3 method for class 'lmList' fitted(object, subset, asList, ...)
object |
an object inheriting from class |
subset |
an optional character or integer vector naming the
|
asList |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by the fitted values of each lm
component of object
, or a vector with the fitted values for all
lm
components of object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) fitted(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) fitted(fm1)
The fitted values at level are obtained by adding together the
contributions from the estimated fixed effects and the estimated
random effects at levels less or equal to
and evaluating the
model function at the resulting estimated parameters. The resulting
values estimate the predictions at level
.
## S3 method for class 'nlmeStruct' fitted(object, level, conLin, ...)
## S3 method for class 'nlmeStruct' fitted(object, level, conLin, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the fitted values from |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
additional arguments that could be given to this method. None are used. |
if a single level of grouping is specified in level
,
the returned value is a vector with the fitted values at the desired
level; else, when multiple grouping levels are specified in
level
, the returned object is a matrix with
columns given by the fitted values at different levels.
This method function is generally only used inside nlme
and
fitted.nlme
.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1998) "Computational methods for multilevel models" available in PostScript or PDF formats at http://nlme.stat.wisc.edu/pub/NLME/
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include lmList
and lme
.
fixed.effects(object, ...) fixef(object, ...)
fixed.effects(object, ...) fixef(object, ...)
object |
any fitted model object from which fixed effects estimates can be extracted. |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
## see the method function documentation
## see the method function documentation
The average of the coefficients corresponding to the lm
components of object
is calculated.
## S3 method for class 'lmList' fixef(object, ...)
## S3 method for class 'lmList' fixef(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the average of the individual lm
coefficients in
object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) fixed.effects(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) fixed.effects(fm1)
The formula
attributes of the pdMat
elements of
x
are extracted and returned as a list, in case
asList=TRUE
, or converted to a single one-sided formula when
asList=FALSE
. If the pdMat
elements do not have a
formula
attribute, a NULL
value is returned.
## S3 method for class 'pdBlocked' formula(x, asList, ...)
## S3 method for class 'pdBlocked' formula(x, asList, ...)
x |
an object inheriting from class |
asList |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list of one-sided formulas, or a single one-sided formula, or
NULL
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdBlocked(list(~ age, ~ Sex - 1)) formula(pd1) formula(pd1, asList = TRUE)
pd1 <- pdBlocked(list(~ age, ~ Sex - 1)) formula(pd1) formula(pd1, asList = TRUE)
This method function extracts the formula associated with a
pdMat
object, in which the column and row names are specified.
## S3 method for class 'pdMat' formula(x, asList, ...)
## S3 method for class 'pdMat' formula(x, asList, ...)
x |
an object inheriting from class |
asList |
logical. Should the |
... |
some methods for this generic require additional arguments. None are used in this method. |
if x
has a formula
attribute, its value is
returned, else NULL
is returned.
Because factors may be present in formula(x)
, the
pdMat
object needs to have access to a data frame where the
variables named in the formula can be evaluated, before it can resolve
its row and column names from the formula.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdSymm(~Sex*age) formula(pd1)
pd1 <- pdSymm(~Sex*age) formula(pd1)
This method function extracts a formula from each of the
components of x
, returning a list of formulas.
## S3 method for class 'reStruct' formula(x, asList, ...)
## S3 method for class 'reStruct' formula(x, asList, ...)
x |
an object inheriting from class |
asList |
logical. Should the |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with the formulas of each component of x
.
José Pinheiro and Douglas Bates [email protected]
rs1 <- reStruct(list(A = pdDiag(diag(2), ~age), B = ~1)) formula(rs1)
rs1 <- reStruct(list(A = pdDiag(diag(2), ~age), B = ~1)) formula(rs1)
Applies the function to the distinct sets of rows of the data frame
defined by groups
.
gapply(object, which, FUN, form, level, groups, ...)
gapply(object, which, FUN, form, level, groups, ...)
object |
an object to which the function will be applied - usually
a |
which |
an optional character or positive integer vector
specifying which columns of |
FUN |
function to apply to the distinct sets of rows
of the data frame |
form |
an optional one-sided formula that defines the groups.
When this formula is given the right-hand side is evaluated in
|
level |
an optional positive integer giving the level of grouping to be used in an object with multiple nested grouping levels. Defaults to the highest or innermost level of grouping. |
groups |
an optional factor that will be used to split the
rows into groups. Defaults to |
... |
optional additional arguments to the summary function
|
Returns a data frame with as many rows as there are levels in the
groups
argument.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. sec. 3.4.
## Find number of non-missing "conc" observations for each Subject gapply( Phenobarb, FUN = function(x) sum(!is.na(x$conc)) ) # Pinheiro and Bates, p. 127 table( gapply(Quinidine, "conc", function(x) sum(!is.na(x))) ) changeRecords <- gapply( Quinidine, FUN = function(frm) any(is.na(frm[["conc"]]) & is.na(frm[["dose"]])) )
## Find number of non-missing "conc" observations for each Subject gapply( Phenobarb, FUN = function(x) sum(!is.na(x$conc)) ) # Pinheiro and Bates, p. 127 table( gapply(Quinidine, "conc", function(x) sum(!is.na(x))) ) changeRecords <- gapply( Quinidine, FUN = function(frm) any(is.na(frm[["conc"]]) & is.na(frm[["dose"]])) )
The Gasoline
data frame has 32 rows and 6 columns.
This data frame contains the following columns:
a numeric vector giving the percentage of crude oil converted to gasoline after distillation and fractionation
a numeric vector giving the temperature (degrees F) at which all the gasoline is vaporized
an ordered factor giving the inferred crude oil sample number
a numeric vector giving the crude oil gravity (degrees API)
a numeric vector giving the vapor pressure of the crude oil
a numeric vector giving the crude oil 10% point ASTM—the temperature at which 10% of the crude oil has become vapor.
Prater (1955) provides data on crude oil properties and
gasoline yields. Atkinson (1985)
uses these data to illustrate the use of diagnostics in multiple
regression analysis. Three of the covariates—API
,
vapor
, and ASTM
—measure characteristics of the
crude oil used to produce the gasoline. The other covariate —
endpoint
—is a characteristic of the refining process.
Daniel and Wood (1980) notice that the covariates characterizing
the crude oil occur in only ten distinct groups and conclude that the
data represent responses measured on ten different crude oil samples.
Prater, N. H. (1955), Estimate gasoline yields from crudes, Petroleum Refiner, 35 (5).
Atkinson, A. C. (1985), Plots, Transformations, and Regression, Oxford Press, New York.
Daniel, C. and Wood, F. S. (1980), Fitting Equations to Data, Wiley, New York
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S (4th ed), Springer, New York.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include corStruct
, corSpatial
,
data.frame
, and varFunc
.
getCovariate(object, form, data)
getCovariate(object, form, data)
object |
any object with a |
form |
an optional one-sided formula specifying the covariate(s)
to be extracted. Defaults to |
data |
a data frame in which to evaluate the variables defined in
|
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 100.
getCovariate.corStruct
,
getCovariate.data.frame
,
getCovariate.varFunc
,
getCovariateFormula
## see the method function documentation
## see the method function documentation
This method function extracts the covariate(s) associated with
object
.
## S3 method for class 'corStruct' getCovariate(object, form, data)
## S3 method for class 'corStruct' getCovariate(object, form, data)
object |
an object inheriting from class |
form |
this argument is included to make the method function
compatible with the generic. It will be assigned the value of
|
data |
an optional data frame in which to evaluate the variables
defined in |
when the correlation structure does not include a grouping factor, the
returned value will be a vector or a matrix with the covariate(s)
associated with object
. If a grouping factor is present, the
returned value will be a list of vectors or matrices with the
covariate(s) corresponding to each grouping level.
For spatial correlation structures, this extracts the distances
implied by the covariates, and excludes 1-observation groups.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
cs1 <- corAR1(form = ~ 1 | Subject) getCovariate(cs1, data = Orthodont)
cs1 <- corAR1(form = ~ 1 | Subject) getCovariate(cs1, data = Orthodont)
The right hand side of form
, stripped of any conditioning
expression (i.e. an expression following a |
operator), is
evaluated in object
.
## S3 method for class 'data.frame' getCovariate(object, form, data)
## S3 method for class 'data.frame' getCovariate(object, form, data)
object |
an object inheriting from class |
form |
an optional formula specifying the covariate to be
evaluated in |
data |
some methods for this generic require a separate data frame. Not used in this method. |
the value of the right hand side of form
, stripped of
any conditional expression, evaluated in object
.
José Pinheiro and Douglas Bates [email protected]
getCovariate(Orthodont)
getCovariate(Orthodont)
This method function extracts the covariate(s) associated with the
variance function represented by object
, if any is present.
## S3 method for class 'varFunc' getCovariate(object, form, data)
## S3 method for class 'varFunc' getCovariate(object, form, data)
object |
an object inheriting from class |
form |
an optional formula specifying the covariate to be
evaluated in |
data |
some methods for this generic require a |
if object
has a covariate
attribute, its value is
returned; else NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(1.1, form = ~age) covariate(vf1) <- Orthodont[["age"]] getCovariate(vf1)
vf1 <- varPower(1.1, form = ~age) covariate(vf1) <- Orthodont[["age"]] getCovariate(vf1)
The right hand side of formula(object)
, without any
conditioning expressions (i.e. any expressions after a |
operator) is returned as a one-sided formula.
getCovariateFormula(object)
getCovariateFormula(object)
object |
any object from which a formula can be extracted. |
a one-sided formula describing the covariates associated with
formula(object)
.
José Pinheiro and Douglas Bates [email protected]
getCovariateFormula(y ~ x | g) getCovariateFormula(y ~ x)
getCovariateFormula(y ~ x | g) getCovariateFormula(y ~ x)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include gls
, lme
,
and lmList
.
getData(object)
getData(object)
object |
an object from which a data.frame can be extracted, generally a fitted model object. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
getData.gls
,
getData.lme
,
getData.lmList
## see the method function documentation
## see the method function documentation
If present in the calling sequence used to produce object
, the
data frame used to fit the model is obtained.
## S3 method for class 'gls' getData(object)
## S3 method for class 'gls' getData(object)
object |
an object inheriting from class |
if a data
argument is present in the calling sequence that
produced object
, the corresponding data frame (with
na.action
and subset
applied to it, if also present in
the call that produced object
) is returned;
else, NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, correlation = corAR1(form = ~ 1 | Mare)) getData(fm1)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, correlation = corAR1(form = ~ 1 | Mare)) getData(fm1)
If present in the calling sequence used to produce object
, the
data frame used to fit the model is obtained.
## S3 method for class 'lme' getData(object)
## S3 method for class 'lme' getData(object)
object |
an object inheriting from class |
if a data
argument is present in the calling sequence that
produced object
, the corresponding data frame (with
na.action
and subset
applied to it, if also present in
the call that produced object
) is returned;
else, NULL
is returned.
Note that as from version 3.1-102, this only omits rows omitted in the
fit if na.action = na.omit
, and does not omit at all if
na.action = na.exclude
. That is generally what is wanted for
plotting, the main use of this function.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = ~ sin(2*pi*Time)) getData(fm1)
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), data = Ovary, random = ~ sin(2*pi*Time)) getData(fm1)
If present in the calling sequence used to produce object
, the
data frame used to fit the model is obtained.
## S3 method for class 'lmList' getData(object)
## S3 method for class 'lmList' getData(object)
object |
an object inheriting from class |
if a data
argument is present in the calling sequence that
produced object
, the corresponding data frame (with
na.action
and subset
applied to it, if also present in
the call that produced object
) is returned;
else, NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) getData(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) getData(fm1)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include corStruct
, data.frame
,
gls
, lme
, lmList
, and varFunc
.
getGroups(object, form, level, data, sep)
getGroups(object, form, level, data, sep)
object |
any object |
form |
an optional formula with a conditioning expression on its
right hand side (i.e. an expression involving the |
level |
a positive integer vector with the level(s) of grouping to be used when multiple nested levels of grouping are present. This argument is optional for most methods of this generic function and defaults to all levels of nesting. |
data |
a data frame in which to interpret the variables named in
|
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
getGroupsFormula
, getGroups.data.frame
,
getGroups.gls
, getGroups.lmList
,
getGroups.lme
## see the method function documentation
## see the method function documentation
This method function extracts the grouping factor associated with
object
, if any is present.
## S3 method for class 'corStruct' getGroups(object, form, level, data, sep)
## S3 method for class 'corStruct' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
this argument is included to make the method function
compatible with the generic. It will be assigned the value of
|
level |
this argument is included to make the method function compatible with the generic and is not used. |
data |
an optional data frame in which to evaluate the variables
defined in |
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
if a grouping factor is present in the correlation structure
represented by object
, the function returns the corresponding
factor vector; else the function returns NULL
.
José Pinheiro and Douglas Bates [email protected]
cs1 <- corAR1(form = ~ 1 | Subject) getGroups(cs1, data = Orthodont)
cs1 <- corAR1(form = ~ 1 | Subject) getGroups(cs1, data = Orthodont)
Each variable named in the expression after the |
operator on
the right hand side of form
is evaluated in object
. If
more than one variable is indicated in level
they are combined
into a data frame; else the selected variable is returned as a vector.
When multiple grouping levels are defined in form
and
level > 1
, the levels of the returned factor are obtained by
pasting together the levels of the grouping factors of level greater
or equal to level
, to ensure their uniqueness.
## S3 method for class 'data.frame' getGroups(object, form, level, data, sep)
## S3 method for class 'data.frame' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
an optional formula with a conditioning expression on its
right hand side (i.e. an expression involving the |
level |
a positive integer vector with the level(s) of grouping to be used when multiple nested levels of grouping are present. Defaults to all levels of nesting. |
data |
unused |
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
either a data frame with columns given by the grouping factors
indicated in level
, from outer to inner, or, when a single
level is requested, a factor representing the selected grouping
factor.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
getGroups(Pixel) getGroups(Pixel, level = 2)
getGroups(Pixel) getGroups(Pixel, level = 2)
If present, the grouping factor associated to the correlation
structure for the linear model represented by object
is extracted.
## S3 method for class 'gls' getGroups(object, form, level, data, sep)
## S3 method for class 'gls' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
an optional formula with a conditioning expression on its
right hand side (i.e. an expression involving the |
level |
a positive integer vector with the level(s) of grouping to be used when multiple nested levels of grouping are present. This argument is optional for most methods of this generic function and defaults to all levels of nesting. Not used. |
data |
a data frame in which to interpret the variables named in
|
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
if the linear model represented by object
incorporates a
correlation structure and the corresponding corStruct
object
has a grouping factor, a vector with the group values is returned;
else, NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) getGroups(fm1)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) getGroups(fm1)
The grouping factors corresponding to the linear mixed-effects model
represented by object
are extracted. If more than one level is
indicated in level
, the corresponding grouping factors are
combined into a data frame; else the selected grouping factor is
returned as a vector.
## S3 method for class 'lme' getGroups(object, form, level, data, sep)
## S3 method for class 'lme' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
this argument is included to make the method function compatible with the generic and is ignored in this method. |
level |
an optional integer vector giving the level(s) of grouping
to be extracted from |
data |
unused |
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
either a data frame with columns given by the grouping factors
indicated in level
, or, when a single level is requested, a
factor representing the selected grouping factor.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(pixel ~ day + day^2, Pixel, random = list(Dog = ~day, Side = ~1)) getGroups(fm1, level = 1:2)
fm1 <- lme(pixel ~ day + day^2, Pixel, random = list(Dog = ~day, Side = ~1)) getGroups(fm1, level = 1:2)
The grouping factor determining the partitioning of the observations
used to produce the lm
components of object
is
extracted.
## S3 method for class 'lmList' getGroups(object, form, level, data, sep)
## S3 method for class 'lmList' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
an optional formula with a conditioning expression on its
right hand side (i.e. an expression involving the |
level |
a positive integer vector with the level(s) of grouping to be used when multiple nested levels of grouping are present. This argument is optional for most methods of this generic function and defaults to all levels of nesting. Not used. |
data |
a data frame in which to interpret the variables named in
|
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
a vector with the grouping factor corresponding to the lm
components of object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) getGroups(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) getGroups(fm1)
This method function extracts the grouping factor associated with the
variance function represented by object
, if any is present.
## S3 method for class 'varFunc' getGroups(object, form, level, data, sep)
## S3 method for class 'varFunc' getGroups(object, form, level, data, sep)
object |
an object inheriting from class |
form |
an optional formula with a conditioning expression on its
right hand side (i.e. an expression involving the |
level |
a positive integer vector with the level(s) of grouping to be used when multiple nested levels of grouping are present. This argument is optional for most methods of this generic function and defaults to all levels of nesting. Not used. |
data |
a data frame in which to interpret the variables named in
|
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
if object
has a groups
attribute, its value is
returned; else NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(form = ~ age | Sex) vf1 <- Initialize(vf1, Orthodont) getGroups(vf1)
vf1 <- varPower(form = ~ age | Sex) vf1 <- Initialize(vf1, Orthodont) getGroups(vf1)
The conditioning expression associated with formula(object)
(i.e. the expression after the |
operator) is returned either as
a named list of one-sided formulas, or a single one-sided formula,
depending on the value of asList
. The components of the
returned list are ordered from outermost to innermost level and are
named after the grouping factor expression.
getGroupsFormula(object, asList, sep)
getGroupsFormula(object, asList, sep)
object |
any object from which a formula can be extracted. |
asList |
an optional logical value. If |
sep |
character, the separator to use between group levels when
multiple levels are collapsed. The default is |
a one-sided formula, or a list of one-sided formulas, with the
grouping structure associated with formula(object)
. If no
conditioning expression is present in formula(object)
a
NULL
value is returned.
José Pinheiro and Douglas Bates [email protected]
getGroupsFormula.gls
,
getGroupsFormula.lmList
,
getGroupsFormula.lme
,
getGroupsFormula.reStruct
,
getGroups
getGroupsFormula(y ~ x | g1/g2)
getGroupsFormula(y ~ x | g1/g2)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include data.frame
, gls
, lme
,
and lmList
.
getResponse(object, form)
getResponse(object, form)
object |
any object |
form |
an optional two-sided formula. Defaults to
|
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
getResponse(Orthodont)
getResponse(Orthodont)
The left hand side of formula{object}
is returned as a
one-sided formula.
getResponseFormula(object)
getResponseFormula(object)
object |
any object from which a formula can be extracted. |
a one-sided formula with the response variable associated with
formula{object}
.
José Pinheiro and Douglas Bates [email protected]
getResponseFormula(y ~ x | g)
getResponseFormula(y ~ x | g)
Extract the variance-covariance matrix from a fitted model, such as a mixed-effects model.
getVarCov(obj, ...) ## S3 method for class 'lme' getVarCov(obj, individuals, type = c("random.effects", "conditional", "marginal"), ...) ## S3 method for class 'gls' getVarCov(obj, individual = 1, ...)
getVarCov(obj, ...) ## S3 method for class 'lme' getVarCov(obj, individuals, type = c("random.effects", "conditional", "marginal"), ...) ## S3 method for class 'gls' getVarCov(obj, individual = 1, ...)
obj |
A fitted model. Methods are available for models fit by
|
individuals |
For models fit by |
individual |
For models fit by |
type |
For models fit by |
... |
Optional arguments for some methods, as described above |
A variance-covariance matrix or a list of variance-covariance matrices.
Mary Lindstrom [email protected]
fm1 <- lme(distance ~ age, data = Orthodont, subset = Sex == "Female") getVarCov(fm1) getVarCov(fm1, individuals = "F01", type = "marginal") getVarCov(fm1, type = "conditional") fm2 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) getVarCov(fm2)
fm1 <- lme(distance ~ age, data = Orthodont, subset = Sex == "Female") getVarCov(fm1) getVarCov(fm1, individuals = "F01", type = "marginal") getVarCov(fm1, type = "conditional") fm2 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) getVarCov(fm2)
This function fits a linear model using generalized least squares. The errors are allowed to be correlated and/or have unequal variances.
gls(model, data, correlation, weights, subset, method, na.action, control, verbose) ## S3 method for class 'gls' update(object, model., ..., evaluate = TRUE)
gls(model, data, correlation, weights, subset, method, na.action, control, verbose) ## S3 method for class 'gls' update(object, model., ..., evaluate = TRUE)
object |
an object inheriting from class |
model |
a two-sided linear formula object describing the
model, with the response on the left of a |
model. |
Changes to the model – see |
data |
an optional data frame containing the variables named in
|
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating which subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
verbose |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
evaluate |
If |
offset
terms in model
are an error since 3.1-157
(2022-03): previously they were silently ignored.
an object of class "gls"
representing the linear model
fit. Generic functions such as print
, plot
, and
summary
have methods to show the results of the fit. See
glsObject
for the components of the fit. The functions
resid
, coef
and fitted
,
can be used to extract some of its components.
José Pinheiro and Douglas Bates [email protected]
The different correlation structures available for the
correlation
argument are described in Box, G.E.P., Jenkins,
G.M., and Reinsel G.C. (1994), Littel, R.C., Milliken, G.A., Stroup,
W.W., and Wolfinger, R.D. (1996), and Venables, W.N. and Ripley,
B.D. (2002). The use of variance functions for linear
and nonlinear models is presented in detail in Carroll, R.J. and Ruppert,
D. (1988) and Davidian, M. and Giltinan, D.M. (1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Carroll, R.J. and Ruppert, D. (1988) "Transformation and Weighting in Regression", Chapman and Hall.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
corClasses
,
glsControl
,
glsObject
,
glsStruct
,
plot.gls
,
predict.gls
,
qqnorm.gls
,
residuals.gls
,
summary.gls
,
varClasses
,
varFunc
# AR(1) errors within each Mare fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) # variance increases as a power of the absolute fitted values fm2 <- update(fm1, weights = varPower())
# AR(1) errors within each Mare fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) # variance increases as a power of the absolute fitted values fm2 <- update(fm1, weights = varPower())
The values supplied in the function call replace the defaults and a
list with all possible arguments is returned. The returned list is
used as the control
argument to the gls
function.
glsControl(maxIter, msMaxIter, tolerance, msTol, msVerbose, singular.ok, returnObject = FALSE, apVar, .relStep, opt = c("nlminb", "optim"), optimMethod, minAbsParApVar, natural, sigma = NULL)
glsControl(maxIter, msMaxIter, tolerance, msTol, msVerbose, singular.ok, returnObject = FALSE, apVar, .relStep, opt = c("nlminb", "optim"), optimMethod, minAbsParApVar, natural, sigma = NULL)
maxIter |
maximum number of iterations for the |
msMaxIter |
maximum number of iterations
for the |
tolerance |
tolerance for the convergence criterion in the
|
msTol |
tolerance for the convergence criterion of the first outer
iteration when |
msVerbose |
a logical value passed as the |
singular.ok |
a logical value indicating whether non-estimable
coefficients (resulting from linear dependencies among the columns of
the regression matrix) should be allowed. Default is |
returnObject |
a logical value indicating whether the fitted
object should be returned when the maximum number of iterations is
reached without convergence of the algorithm. Default is
|
apVar |
a logical value indicating whether the approximate
covariance matrix of the variance-covariance parameters should be
calculated. Default is |
.relStep |
relative step for numerical derivatives
calculations. Default is |
opt |
the optimizer to be used, either |
optimMethod |
character - the optimization method to be used with
the |
minAbsParApVar |
numeric value - minimum absolute parameter value
in the approximate variance calculation. The default is |
natural |
logical. Should the natural parameterization be used
for the approximate variance calculations? Default is |
sigma |
optionally a positive number to fix the residual error at.
If |
a list with components for each of the possible arguments.
José Pinheiro and Douglas Bates [email protected]; the
sigma
option: Siem Heisterkamp and Bert van Willigen.
# decrease the maximum number of iterations and request tracing glsControl(msMaxIter = 20, msVerbose = TRUE)
# decrease the maximum number of iterations and request tracing glsControl(msMaxIter = 20, msVerbose = TRUE)
An object returned by the gls
function, inheriting from class
"gls"
and representing a generalized least squares fitted linear
model. Objects of this class have methods for the generic functions
anova
, coef
, fitted
, formula
,
getGroups
, getResponse
, intervals
, logLik
,
plot
, predict
, print
, residuals
,
summary
, and update
.
The following components must be included in a legitimate "gls"
object.
apVar |
an approximate covariance matrix for the
variance-covariance coefficients. If |
call |
a list containing an image of the |
coefficients |
a vector with the estimated linear model coefficients. |
contrasts |
a list of the contrast matrices used to represent factors in the model formula. This information is important for making predictions from a new data frame in which not all levels of the original factors are observed. If no factors are used in the model, this component will be an empty list. |
dims |
a list with basic dimensions used in the model fit,
including the components |
fitted |
a vector with the fitted values. |
modelStruct |
an object inheriting from class |
groups |
the correlation structure grouping factor, if any is present. |
logLik |
the log-likelihood at convergence. |
method |
the estimation method: either |
numIter |
the number of iterations used in the iterative algorithm. |
residuals |
a vector with the residuals. |
sigma |
the estimated residual standard error. |
varBeta |
an approximate covariance matrix of the coefficients estimates. |
José Pinheiro and Douglas Bates [email protected]
A generalized least squares structure is a list of model components
representing different sets of parameters in the linear
model. A glsStruct
may contain corStruct
and
varFunc
objects. NULL
arguments are not included in the
glsStruct
list.
glsStruct(corStruct, varStruct)
glsStruct(corStruct, varStruct)
corStruct |
an optional |
varStruct |
an optional |
a list of model variance-covariance components determining the parameters to be estimated for the associated linear model.
José Pinheiro and Douglas Bates [email protected]
corClasses
,
gls
,
residuals.glsStruct
,
varFunc
gls1 <- glsStruct(corAR1(), varPower())
gls1 <- glsStruct(corAR1(), varPower())
The Glucose
data frame has 378 rows and 4 columns.
This data frame contains the following columns:
an ordered factor with levels
6
< 2
< 3
< 5
< 1
< 4
a numeric vector
a numeric vector of glucose levels
an ordered factor with levels
2am
< 6am
< 10am
< 2pm
< 6pm
< 10pm
Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall, London.
The Glucose2
data frame has 196 rows and 4 columns.
This data frame contains the following columns:
a factor with levels
1
to 7
identifying the subject whose glucose
level is measured.
a factor with levels
1
2
indicating the occasion in which the experiment was conducted.
a numeric vector giving the time since alcohol ingestion (in min/10).
a numeric vector giving the blood glucose level (in mg/dl).
Hand and Crowder (Table A.14, pp. 180-181, 1996) describe data on the blood glucose levels measured at 14 time points over 5 hours for 7 volunteers who took alcohol at time 0. The same experiment was repeated on a second date with the same subjects but with a dietary additive used for all subjects.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.10)
Hand, D. and Crowder, M. (1996), Practical Longitudinal Data Analysis, Chapman and Hall, London.
This function fits a nonlinear model using generalized least squares. The errors are allowed to be correlated and/or have unequal variances.
gnls(model, data, params, start, correlation, weights, subset, na.action, naPattern, control, verbose)
gnls(model, data, params, start, correlation, weights, subset, na.action, naPattern, control, verbose)
model |
a two-sided formula object describing the
model, with the response on the left of a |
data |
an optional data frame containing the variables named in
|
params |
an optional two-sided linear formula of the form
|
start |
an optional named list, or numeric vector, with the
initial values for the parameters in |
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating which subset of the rows of
|
na.action |
a function that indicates what should happen when the
data contain |
naPattern |
an expression or formula object, specifying which returned values are to be regarded as missing. |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
verbose |
an optional logical value. If |
an object of class gnls
, also inheriting from class gls
,
representing the nonlinear model fit. Generic functions such as
print
, plot
and summary
have methods to show the
results of the fit. See gnlsObject
for the components of the
fit. The functions resid
, coef
, and fitted
can be
used to extract some of its components.
José Pinheiro and Douglas Bates [email protected]
The different correlation structures available for the
correlation
argument are described in Box, G.E.P., Jenkins,
G.M., and Reinsel G.C. (1994), Littel, R.C., Milliken, G.A., Stroup,
W.W., and Wolfinger, R.D. (1996), and Venables, W.N. and Ripley,
B.D. (2002). The use of variance functions for linear
and nonlinear models is presented in detail in Carrol, R.J. and Rupert,
D. (1988) and Davidian, M. and Giltinan, D.M. (1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Carrol, R.J. and Rupert, D. (1988) "Transformation and Weighting in Regression", Chapman and Hall.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
corClasses
,
gnlsControl
, gnlsObject
,
gnlsStruct
,
predict.gnls
,
varClasses
,
varFunc
# variance increases with a power of the absolute fitted values fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) summary(fm1)
# variance increases with a power of the absolute fitted values fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) summary(fm1)
The values supplied in the function call replace the defaults and a
list with all possible arguments is returned. The returned list is
used as the control
argument to the gnls
function.
gnlsControl(maxIter = 50, nlsMaxIter = 7, msMaxIter = 50, minScale = 0.001, tolerance = 1e-6, nlsTol = 0.001, msTol = 1e-7, returnObject = FALSE, msVerbose = FALSE, apVar = TRUE, .relStep =, opt = c("nlminb", "optim"), optimMethod = "BFGS", minAbsParApVar = 0.05, sigma = NULL)
gnlsControl(maxIter = 50, nlsMaxIter = 7, msMaxIter = 50, minScale = 0.001, tolerance = 1e-6, nlsTol = 0.001, msTol = 1e-7, returnObject = FALSE, msVerbose = FALSE, apVar = TRUE, .relStep =, opt = c("nlminb", "optim"), optimMethod = "BFGS", minAbsParApVar = 0.05, sigma = NULL)
maxIter |
maximum number of iterations for the |
nlsMaxIter |
maximum number of iterations
for the |
msMaxIter |
maximum number of iterations
for the |
minScale |
minimum factor by which to shrink the default step size
in an attempt to decrease the sum of squares in the |
tolerance |
tolerance for the convergence criterion in the
|
nlsTol |
tolerance for the convergence criterion in |
msTol |
tolerance for the convergence criterion of the first outer
iteration when |
returnObject |
a logical value indicating whether the fitted
object should be returned with a |
msVerbose |
a logical value passed as the |
apVar |
a logical value indicating whether the approximate
covariance matrix of the variance-covariance parameters should be
calculated. Default is |
.relStep |
relative step for numerical derivatives
calculations. Default is |
opt |
the optimizer to be used, either |
optimMethod |
character - the optimization method to be used with
the |
minAbsParApVar |
numeric value - minimum absolute parameter value
in the approximate variance calculation. The default is |
sigma |
optionally a positive number to fix the residual error at.
If |
a list with components for each of the possible arguments.
José Pinheiro and Douglas Bates [email protected]; the
sigma
option: Siem Heisterkamp and Bert van Willigen.
# decrease the maximum number of iterations and request tracing gnlsControl(msMaxIter = 20, msVerbose = TRUE)
# decrease the maximum number of iterations and request tracing gnlsControl(msMaxIter = 20, msVerbose = TRUE)
An object returned by the gnls
function, inheriting from class
"gnls"
and also from class "gls"
, and representing a
generalized nonlinear least squares fitted model. Objects of this
class have methods for the generic functions anova
,
coef
, fitted
, formula
, getGroups
,
getResponse
, intervals
, logLik
, plot
,
predict
, print
, residuals
, summary
, and
update
.
The following components must be included in a legitimate "gnls"
object.
apVar |
an approximate covariance matrix for the
variance-covariance coefficients. If |
call |
a list containing an image of the |
coefficients |
a vector with the estimated nonlinear model coefficients. |
contrasts |
a list of the contrast matrices used to represent factors in the model formula. This information is important for making predictions from a new data frame in which not all levels of the original factors are observed. If no factors are used in the model, this component will be an empty list. |
dims |
a list with basic dimensions used in the model fit,
including the components |
fitted |
a vector with the fitted values. |
modelStruct |
an object inheriting from class |
groups |
a vector with the correlation structure grouping factor, if any is present. |
logLik |
the log-likelihood at convergence. |
numIter |
the number of iterations used in the iterative algorithm. |
plist |
|
pmap |
|
residuals |
a vector with the residuals. |
sigma |
the estimated residual standard error. |
varBeta |
an approximate covariance matrix of the coefficients estimates. |
José Pinheiro and Douglas Bates [email protected]
gnls
, gnlsStruct
A generalized nonlinear least squares structure is a list of model
components representing different sets of parameters in the nonlinear
model. A gnlsStruct
may contain corStruct
and
varFunc
objects. NULL
arguments are not included in the
gnlsStruct
list.
gnlsStruct(corStruct, varStruct)
gnlsStruct(corStruct, varStruct)
corStruct |
an optional |
varStruct |
an optional |
a list of model variance-covariance components determining the parameters to be estimated for the associated nonlinear model.
José Pinheiro and Douglas Bates [email protected]
gnls
, corClasses
,
residuals.gnlsStruct
varFunc
gnls1 <- gnlsStruct(corAR1(), varPower())
gnls1 <- gnlsStruct(corAR1(), varPower())
An object of the groupedData
class is constructed from the
formula
and data
by attaching the formula
as an
attribute of the data, along with any of outer
, inner
,
labels
, and units
that are given. If
order.groups
is TRUE
the grouping factor is converted to
an ordered factor with the ordering determined by
FUN
. Depending on the number of grouping levels and the type of
primary covariate, the returned object will be of one of three
classes: nfnGroupedData
- numeric covariate, single level of
nesting; nffGroupedData
- factor covariate, single level of
nesting; and nmGroupedData
- multiple levels of
nesting. Several modeling and plotting functions can use the formula
stored with a groupedData
object to construct default plots and
models.
groupedData(formula, data, order.groups, FUN, outer, inner, labels, units) ## S3 method for class 'groupedData' update(object, formula, data, order.groups, FUN, outer, inner, labels, units, ...)
groupedData(formula, data, order.groups, FUN, outer, inner, labels, units) ## S3 method for class 'groupedData' update(object, formula, data, order.groups, FUN, outer, inner, labels, units, ...)
object |
an object inheriting from class |
formula |
a formula of the form |
data |
a data frame in which the expressions in |
order.groups |
an optional logical value, or list of logical
values, indicating if the grouping factors should be converted to
ordered factors according to the function |
FUN |
an optional summary function that will be applied to the
values of the response for each level of the grouping factor, when
|
outer |
an optional one-sided formula, or list of one-sided
formulas, indicating covariates that are outer to the grouping
factor(s). If multiple levels of grouping are present,
this argument can be either a single one-sided formula, or a list of
one-sided formulas. If no names are assigned to the list elements,
they are assumed in the same order as the group levels (outermost to
innermost grouping). An outer covariate is invariant within the sets
of rows defined by the grouping factor. Ordering of the groups is
done in such a way as to preserve adjacency of groups with the same
value of the outer variables. When plotting a |
inner |
an optional one-sided formula, or list of one-sided
formulas, indicating covariates that are inner to the grouping
factor(s). If multiple levels of grouping are present,
this argument can be either a single one-sided formula, or a list of
one-sided formulas. If no names are assigned to the list elements,
they are assumed in the same order as the group levels (outermost to
innermost grouping). An inner covariate can change
within the sets of rows defined by the grouping factor. An inner
formula can be used to associate points in a plot of a |
labels |
an optional list of character strings giving labels for
the response and the primary covariate. The label for the primary
covariate is named |
units |
an optional list of character strings giving the units for
the response and the primary covariate. The units string for the
primary covariate is named |
... |
some methods for this generic require additional arguments. None are used in this method. |
an object of one of the classes nfnGroupedData
,
nffGroupedData
, or nmGroupedData
, and also inheriting
from classes groupedData
and data.frame
.
Douglas Bates and José Pinheiro
Bates, D.M. and Pinheiro, J.C. (1997), "Software Design for Longitudinal Data Analysis", in "Modelling Longitudinal and Spatially Correlated Data: Methods, Applications and Future Directions", T.G. Gregoire (ed.), Springer-Verlag, New York. doi:10.1007/978-1-4612-0699-6_4
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
formula
, gapply
,
gsummary
,
lme
,
plot.nffGroupedData
,
plot.nfnGroupedData
,
plot.nmGroupedData
,
reStruct
Orth.new <- # create a new copy of the groupedData object groupedData( distance ~ age | Subject, data = as.data.frame( Orthodont ), FUN = mean, outer = ~ Sex, labels = list( x = "Age", y = "Distance from pituitary to pterygomaxillary fissure" ), units = list( x = "(yr)", y = "(mm)") ) plot( Orth.new ) # trellis plot by Subject formula( Orth.new ) # extractor for the formula gsummary( Orth.new ) # apply summary by Subject fm1 <- lme( Orth.new ) # fixed and groups formulae extracted from object Orthodont2 <- update(Orthodont, FUN = mean)
Orth.new <- # create a new copy of the groupedData object groupedData( distance ~ age | Subject, data = as.data.frame( Orthodont ), FUN = mean, outer = ~ Sex, labels = list( x = "Age", y = "Distance from pituitary to pterygomaxillary fissure" ), units = list( x = "(yr)", y = "(mm)") ) plot( Orth.new ) # trellis plot by Subject formula( Orth.new ) # extractor for the formula gsummary( Orth.new ) # apply summary by Subject fm1 <- lme( Orth.new ) # fixed and groups formulae extracted from object Orthodont2 <- update(Orthodont, FUN = mean)
Provide a summary of the variables in a data frame by groups of rows.
This is most useful with a groupedData
object to examine the
variables by group.
gsummary(object, FUN, omitGroupingFactor, form, level, groups, invariantsOnly, ...)
gsummary(object, FUN, omitGroupingFactor, form, level, groups, invariantsOnly, ...)
object |
an object to be summarized - usually a |
FUN |
an optional summary function or a list of summary functions
to be applied to each variable in the frame. The function or
functions are applied only to variables in |
omitGroupingFactor |
an optional logical value. When |
form |
an optional one-sided formula that defines the groups.
When this formula is given, the right-hand side is evaluated in
|
level |
an optional positive integer giving the level of grouping to be used in an object with multiple nested grouping levels. Defaults to the highest or innermost level of grouping. |
groups |
an optional factor that will be used to split the
rows into groups. Defaults to |
invariantsOnly |
an optional logical value. When |
... |
optional additional arguments to the summary functions
that are invoked on the variables by group. Often it is helpful to
specify |
A data.frame
with one row for each level of the grouping
factor. The number of columns is at most the number of columns in
object
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
summary
, groupedData
,
getGroups
gsummary(Orthodont) # default summary by Subject ## gsummary with invariantsOnly = TRUE and omitGroupingFactor = TRUE ## determines whether there are covariates like Sex that are invariant ## within the repeated observations on the same Subject. gsummary(Orthodont, invariantsOnly = TRUE, omitGroupingFactor = TRUE)
gsummary(Orthodont) # default summary by Subject ## gsummary with invariantsOnly = TRUE and omitGroupingFactor = TRUE ## determines whether there are covariates like Sex that are invariant ## within the repeated observations on the same Subject. gsummary(Orthodont, invariantsOnly = TRUE, omitGroupingFactor = TRUE)
The Gun
data frame has 36 rows and 4 columns.
This data frame contains the following columns:
a numeric vector
a factor with levels
M1
M2
an ordered factor with levels
T1S
< T3S
< T2S
< T1A
<
T2A
< T3A
< T1H
< T3H
<
T2H
an ordered factor with levels
Slight
< Average
< Heavy
Hicks (p.180, 1993) reports data from an experiment on methods for firing naval guns. Gunners of three different physiques (slight, average, and heavy) tested two firing methods. Both methods were tested twice by each of nine teams of three gunners with identical physique. The response was the number of rounds fired per minute.
Hicks, C. R. (1993), Fundamental Concepts in the Design of Experiments (4th ed), Harcourt Brace, New York.
The IGF
data frame has 237 rows and 3 columns.
This data frame contains the following columns:
an ordered factor giving the radioactive tracer lot.
a numeric vector giving the age (in days) of the radioactive tracer.
a numeric vector giving the estimated concentration of IGF-I protein (ng/ml)
Davidian and Giltinan (1995) describe data obtained during quality control radioimmunoassays for ten different lots of radioactive tracer used to calibrate the Insulin-like Growth Factor (IGF-I) protein concentration measurements.
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.11)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: corStruct
, lmeStruct
,
reStruct
, and varFunc
.
Initialize(object, data, ...)
Initialize(object, data, ...)
object |
any object requiring initialization, e.g. "plug-in"
structures such as |
data |
a data frame to be used in the initialization procedure. |
... |
some methods for this generic function require additional arguments. |
an initialized object with the same class as object
. Changes
introduced by the initialization procedure will depend on the method
function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Initialize.corStruct
,
Initialize.lmeStruct
,
Initialize.glsStruct
,
Initialize.varFunc
,
isInitialized
## see the method function documentation
## see the method function documentation
This method initializes object
by evaluating its associated
covariate(s) and grouping factor, if any is present, in data
,
calculating various dimensions and constants used by optimization
algorithms involving corStruct
objects (see the appropriate
Dim
method documentation), and assigning initial values for
the coefficients in object
, if none were present.
## S3 method for class 'corStruct' Initialize(object, data, ...)
## S3 method for class 'corStruct' Initialize(object, data, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables defined in
|
... |
this argument is included to make this method compatible with the generic. |
an initialized object with the same class as object
representing a correlation structure.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
cs1 <- corAR1(form = ~ 1 | Subject) cs1 <- Initialize(cs1, data = Orthodont)
cs1 <- corAR1(form = ~ 1 | Subject) cs1 <- Initialize(cs1, data = Orthodont)
The individual linear model components of the glsStruct
list
are initialized.
## S3 method for class 'glsStruct' Initialize(object, data, control, ...)
## S3 method for class 'glsStruct' Initialize(object, data, control, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables defined in
|
control |
an optional list with control parameters for the
initialization and optimization algorithms used in
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a glsStruct
object similar to object
, but with
initialized model components.
José Pinheiro and Douglas Bates [email protected]
gls
,
Initialize.corStruct
,
Initialize.varFunc
,
Initialize
The individual linear mixed-effects model components of the
lmeStruct
list are initialized.
## S3 method for class 'lmeStruct' Initialize(object, data, groups, conLin, control, ...)
## S3 method for class 'lmeStruct' Initialize(object, data, groups, conLin, control, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables defined in
|
groups |
a data frame with the grouping factors corresponding to
the lme model associated with |
conLin |
an optional condensed linear model object, consisting of
a list with components |
control |
an optional list with control parameters for the
initialization and optimization algorithms used in
|
... |
some methods for this generic require additional arguments. None are used in this method. |
an lmeStruct
object similar to object
, but with
initialized model components.
José Pinheiro and Douglas Bates [email protected]
lme
, Initialize.reStruct
,
Initialize.corStruct
,
Initialize.varFunc
, Initialize
Initial estimates for the parameters in the pdMat
objects
forming object
, which have not yet been initialized, are
obtained using the methodology described in Bates and Pinheiro
(1998). These estimates may be refined using a series of EM
iterations, as described in Bates and Pinheiro (1998). The number of
EM iterations to be used is defined in control
.
## S3 method for class 'reStruct' Initialize(object, data, conLin, control, ...)
## S3 method for class 'reStruct' Initialize(object, data, conLin, control, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables defined in
|
conLin |
a condensed linear model object, consisting of a list
with components |
control |
an optional list with a single component |
... |
some methods for this generic require additional arguments. None are used in this method. |
an reStruct
object similar to object
, but with all
pdMat
components initialized.
José Pinheiro and Douglas Bates [email protected]
This method initializes object
by evaluating its associated
covariate(s) and grouping factor, if any is present, in data
;
determining if the covariate(s) need to be updated when the
values of the coefficients associated with object
change;
initializing the log-likelihood and the weights associated with
object
; and assigning initial values for the coefficients in
object
, if none were present. The covariate(s) will only be
initialized if no update is needed when coef(object)
changes.
## S3 method for class 'varFunc' Initialize(object, data, ...)
## S3 method for class 'varFunc' Initialize(object, data, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables named in
|
... |
this argument is included to make this method compatible with the generic. |
an initialized object with the same class as object
representing a variance function structure.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower( form = ~ age | Sex ) vf1 <- Initialize( vf1, Orthodont )
vf1 <- varPower( form = ~ age | Sex ) vf1 <- Initialize( vf1, Orthodont )
Confidence intervals on the parameters associated with the model
represented by object
are obtained. This function is generic;
method functions can be written to handle specific classes of
objects. Classes which already have methods for this function include:
gls
, lme
, and lmList
.
intervals(object, level, ...)
intervals(object, level, ...)
object |
a fitted model object from which parameter estimates can be extracted. |
level |
an optional numeric value for the interval confidence level. Defaults to 0.95. |
... |
some methods for the generic may require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
intervals.lme
,
intervals.lmList
,
intervals.gls
## see the method documentation
## see the method documentation
Approximate confidence intervals for the parameters in the linear
model represented by object
are obtained, using
a normal approximation to the distribution of the (restricted)
maximum likelihood estimators (the estimators are assumed to have a
normal distribution centered at the true parameter values and with
covariance matrix equal to the negative inverse Hessian matrix of the
(restricted) log-likelihood evaluated at the estimated parameters).
Confidence intervals are obtained in an unconstrained scale first,
using the normal approximation, and, if necessary, transformed to the
constrained scale.
## S3 method for class 'gls' intervals(object, level, which, ...)
## S3 method for class 'gls' intervals(object, level, which, ...)
object |
an object inheriting from class |
level |
an optional numeric value for the interval confidence level. Defaults to 0.95. |
which |
an optional character string specifying the subset
of parameters for which to construct the confidence
intervals. Possible values are |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by data frames with rows corresponding to
parameters and columns lower
, est.
, and upper
representing respectively lower confidence limits, the estimated
values, and upper confidence limits for the parameters. Possible
components are:
coef |
linear model coefficients, only present when |
corStruct |
correlation parameters, only present when
|
varFunc |
variance function parameters, only present when
|
sigma |
residual standard error. |
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
gls
, intervals
,
print.intervals.gls
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) intervals(fm1)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) intervals(fm1)
Approximate confidence intervals for the parameters in the linear
mixed-effects model represented by object
are obtained, using
a normal approximation to the distribution of the (restricted)
maximum likelihood estimators (the estimators are assumed to have a
normal distribution centered at the true parameter values and with
covariance matrix equal to the negative inverse Hessian matrix of the
(restricted) log-likelihood evaluated at the estimated parameters).
Confidence intervals are obtained in an unconstrained scale first,
using the normal approximation, and, if necessary, transformed to the
constrained scale. The pdNatural
parametrization is used for
general positive-definite matrices.
## S3 method for class 'lme' intervals(object, level = 0.95, which = c("all", "var-cov", "fixed"), ...)
## S3 method for class 'lme' intervals(object, level = 0.95, which = c("all", "var-cov", "fixed"), ...)
object |
an object inheriting from class |
level |
an optional numeric value with the confidence level for the intervals. Defaults to 0.95. |
which |
an optional character string specifying the subset
of parameters for which to construct the confidence
intervals. Possible values are |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by data frames with rows corresponding to
parameters and columns lower
, est.
, and upper
representing respectively lower confidence limits, the estimated
values, and upper confidence limits for the parameters. Possible
components are:
fixed |
fixed effects, only present when |
reStruct |
random effects variance-covariance parameters, only
present when |
corStruct |
within-group correlation parameters, only
present when |
varFunc |
within-group variance function parameters, only
present when |
sigma |
within-group standard deviation. |
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
lme
, intervals
,
print.intervals.lme
,
pdNatural
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) intervals(fm1)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) intervals(fm1)
Confidence intervals on the linear model coefficients are obtained for
each lm
component of object
and organized into a three
dimensional array. The first dimension corresponding to the names
of the object
components. The second dimension is given by
lower
, est.
, and upper
corresponding,
respectively, to the lower confidence limit, estimated coefficient,
and upper confidence limit. The third dimension is given by the
coefficients names.
## S3 method for class 'lmList' intervals(object, level = 0.95, pool = attr(object, "pool"), ...)
## S3 method for class 'lmList' intervals(object, level = 0.95, pool = attr(object, "pool"), ...)
object |
an object inheriting from class |
level |
an optional numeric value with the confidence level for the intervals. Defaults to 0.95. |
pool |
an optional logical value indicating whether a pooled
estimate of the residual standard error should be used. Default is
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a three dimensional array with the confidence intervals and estimates
for the coefficients of each lm
component of object
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
lmList
, intervals
,
plot.intervals.lmList
fm1 <- lmList(distance ~ age | Subject, Orthodont) intervals(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) intervals(fm1)
Check the design of the experiment or study for balance.
isBalanced(object, countOnly, level)
isBalanced(object, countOnly, level)
object |
A |
countOnly |
A logical value indicating if the check for balance
should only consider the number of observations at each level of the
grouping factor(s). Defaults to |
level |
an optional integer vector specifying the desired prediction levels. Levels increase from outermost to innermost grouping, with level 0 representing the population (fixed effects) predictions. Defaults to the innermost level. |
A design is
balanced with respect to the grouping factor(s) if there are the same
number of observations at each distinct value of the grouping factor or
each combination of distinct levels of the nested grouping factors. If
countOnly
is FALSE
the design is also checked for balance
with respect to the primary covariate, which is often the time of the
observation. A design is balanced with respect to the grouping factor
and the covariate if the number of observations at each distinct level
(or combination of levels for nested factors) is constant and the times
at which the observations are taken (in general, the values of the
primary covariates) also are constant.
TRUE
or FALSE
according to whether the data are balanced
or not
José Pinheiro and Douglas Bates [email protected]
isBalanced(Orthodont) # should return TRUE isBalanced(Orthodont, countOnly = TRUE) # should return TRUE isBalanced(Pixel) # should return FALSE isBalanced(Pixel, level = 1) # should return FALSE
isBalanced(Orthodont) # should return TRUE isBalanced(Orthodont, countOnly = TRUE) # should return TRUE isBalanced(Pixel) # should return FALSE isBalanced(Pixel, level = 1) # should return FALSE
Checks if object
has been initialized (generally through a call
to Initialize
), by searching for components and attributes
which are modified during initialization.
isInitialized(object)
isInitialized(object)
object |
any object requiring initialization. |
a logical value indicating whether object
has been
initialized.
José Pinheiro and Douglas Bates
pd1 <- pdDiag(~age) isInitialized(pd1)
pd1 <- pdDiag(~age) isInitialized(pd1)
Generate the system matrix for the linear differential equations determined by a compartment model.
LDEsysMat(pars, incidence)
LDEsysMat(pars, incidence)
pars |
a numeric vector of parameter values. |
incidence |
an integer matrix with columns named |
A compartment model describes material transfer between k
in a system of k
compartments to a linear system of differential
equations. Given a description of the system and a vector of parameter
values this function returns the system matrix.
This function is intended for use in a general system for solving compartment models, as described in Bates and Watts (1988).
A k
by k
numeric matrix.
Douglas Bates [email protected]
Bates, D. M. and Watts, D. G. (1988), Nonlinear Regression Analysis and Its Applications, Wiley, New York.
# incidence matrix for a two compartment open system incidence <- matrix(c(1,1,2,2,2,1,3,2,0), ncol = 3, byrow = TRUE, dimnames = list(NULL, c("Par", "From", "To"))) incidence LDEsysMat(c(1.2, 0.3, 0.4), incidence)
# incidence matrix for a two compartment open system incidence <- matrix(c(1,1,2,2,2,1,3,2,0), ncol = 3, byrow = TRUE, dimnames = list(NULL, c("Par", "From", "To"))) incidence LDEsysMat(c(1.2, 0.3, 0.4), incidence)
This generic function fits a linear mixed-effects model in the formulation described in Laird and Ware (1982) but allowing for nested random effects. The within-group errors are allowed to be correlated and/or have unequal variances.
This page describes the formula method;
the methods lme.lmList
and lme.groupedData
are documented separately.
lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts = NULL, keep.data = TRUE) ## S3 method for class 'formula' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts = NULL, keep.data = TRUE) ## S3 method for class 'lme' update(object, fixed., ..., evaluate = TRUE)
lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts = NULL, keep.data = TRUE) ## S3 method for class 'formula' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts = NULL, keep.data = TRUE) ## S3 method for class 'lme' update(object, fixed., ..., evaluate = TRUE)
object |
an object inheriting from class |
fixed |
a two-sided linear formula object describing the
fixed-effects part of the model, with the response on the left of a
There is limited support for formulae such as |
fixed. |
Changes to the fixed-effects formula – see
|
data |
an optional data frame containing the variables named in
|
random |
optionally, any of the following: (i) a one-sided formula
of the form |
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating the subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
contrasts |
an optional list. See the |
keep.data |
logical: should the |
... |
some methods for this generic require additional arguments. None are used in this method. |
evaluate |
If |
offset
terms in fixed
are an error since 3.1-157
(2022-03): previously they were silently ignored.
An object of class "lme"
representing the linear mixed-effects
model fit. Generic functions such as print
, plot
and
summary
have methods to show the results of the fit. See
lmeObject
for the components of the fit. The functions
resid
, coef
, fitted
,
fixed.effects
, and
random.effects
can be used to extract some of its components.
The function does not do any scaling internally: the optimization will work best when the response is scaled so its variance is of the order of one.
José Pinheiro and Douglas Bates [email protected]
The computational methods follow the general framework of Lindstrom
and Bates (1988). The model formulation is described in Laird and Ware
(1982). The variance-covariance parametrizations are described in
Pinheiro and Bates (1996). The different correlation structures
available for the correlation
argument are described in Box,
Jenkins and Reinsel (1994), Littell et al (1996), and Venables and
Ripley (2002). The use of variance functions for linear and nonlinear
mixed effects models is presented in detail in Davidian and Giltinan
(1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994). Time Series Analysis: Forecasting and Control, 3rd Edition, Holden–Day.
Davidian, M. and Giltinan, D.M. (1995). Nonlinear Mixed Effects Models for Repeated Measurement Data, Chapman and Hall. doi:10.1201/9780203745502.
Laird, N.M. and Ware, J.H. (1982). Random-Effects Models for Longitudinal Data. Biometrics 38, 963–974. doi:10.2307/2529876.
Lindstrom, M.J. and Bates, D.M. (1988). Newton-Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data. Journal of the American Statistical Association 83, 1014–1022. doi:10.2307/2290128.
Littell, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996). SAS Systems for Mixed Models, SAS Institute.
Pinheiro, J.C. and Bates., D.M. (1996). Unconstrained Parametrizations for Variance-Covariance Matrices. Statistics and Computing 6, 289–296. doi:10.1007/BF00140873.
Pinheiro, J.C., and Bates, D.M. (2000). Mixed-Effects Models in S and S-PLUS, Springer. doi:10.1007/b98882.
Venables, W.N. and Ripley, B.D. (2002). Modern Applied Statistics with S, 4th Edition, Springer-Verlag. doi:10.1007/978-0-387-21706-2.
corClasses
,
lme.lmList
,
lme.groupedData
,
lmeControl
,
lmeObject
,
lmeStruct
,
lmList
,
pdClasses
,
plot.lme
,
predict.lme
,
qqnorm.lme
,
residuals.lme
,
reStruct
,
simulate.lme
,
summary.lme
,
varClasses
,
varFunc
fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) summary(fm1) summary(fm2)
fm1 <- lme(distance ~ age, data = Orthodont) # random is ~ age fm2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) summary(fm1) summary(fm2)
The response variable and primary covariate in formula(fixed)
are used to construct the fixed effects model formula. This formula
and the groupedData
object are passed as the fixed
and
data
arguments to lme.formula
, together with any other
additional arguments in the function call. See the documentation on
lme.formula
for a description of that function.
## S3 method for class 'groupedData' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts, keep.data = TRUE)
## S3 method for class 'groupedData' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts, keep.data = TRUE)
fixed |
a data frame inheriting from class |
data |
this argument is included for consistency with the generic function. It is ignored in this method function. |
random |
optionally, any of the following: (i) a one-sided formula
of the form |
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating the subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
contrasts |
an optional list. See the |
keep.data |
logical: should the |
an object of class lme
representing the linear mixed-effects
model fit. Generic functions such as print
, plot
and
summary
have methods to show the results of the fit. See
lmeObject
for the components of the fit. The functions
resid
, coef
, fitted
, fixed.effects
, and
random.effects
can be used to extract some of its components.
José Pinheiro and Douglas Bates [email protected]
The computational methods follow on the general framework of Lindstrom,
M.J. and Bates, D.M. (1988). The model formulation is described in
Laird, N.M. and Ware, J.H. (1982). The variance-covariance
parametrizations are described in Pinheiro, J.C. and Bates., D.M.
(1996). The different correlation structures available for the
correlation
argument are described in Box, G.E.P., Jenkins,
G.M., and Reinsel G.C. (1994), Littel, R.C., Milliken, G.A., Stroup,
W.W., and Wolfinger, R.D. (1996), and Venables, W.N. and Ripley,
B.D. (2002). The use of variance functions for linear and nonlinear
mixed effects models is presented in detail in Davidian, M. and
Giltinan, D.M. (1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Laird, N.M. and Ware, J.H. (1982) "Random-Effects Models for Longitudinal Data", Biometrics, 38, 963-974.
Lindstrom, M.J. and Bates, D.M. (1988) "Newton-Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data", Journal of the American Statistical Association, 83, 1014-1022.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
fm1 <- lme(Orthodont) summary(fm1)
fm1 <- lme(Orthodont) summary(fm1)
If the random effects names defined in random
are a subset of
the lmList
object coefficient names, initial estimates for the
covariance matrix of the random effects are obtained (overwriting any
values given in random
). formula(fixed)
and the
data
argument in the calling sequence used to obtain
fixed
are passed as the fixed
and data
arguments
to lme.formula
, together with any other additional arguments in
the function call. See the documentation on lme.formula
for a
description of that function.
## S3 method for class 'lmList' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts, keep.data)
## S3 method for class 'lmList' lme(fixed, data, random, correlation, weights, subset, method, na.action, control, contrasts, keep.data)
fixed |
an object inheriting from class |
data |
this argument is included for consistency with the generic function. It is ignored in this method function. |
random |
an optional one-sided linear formula with no conditioning
expression, or a |
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating the subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
contrasts |
an optional list. See the |
keep.data |
logical: should the |
an object of class lme
representing the linear mixed-effects
model fit. Generic functions such as print
, plot
and
summary
have methods to show the results of the fit. See
lmeObject
for the components of the fit. The functions
resid
, coef
, fitted
, fixed.effects
, and
random.effects
can be used to extract some of its components.
José Pinheiro and Douglas Bates [email protected]
The computational methods follow the general framework of Lindstrom
and Bates (1988). The model formulation is described in Laird and Ware
(1982). The variance-covariance parametrizations are described in
Pinheiro and Bates (1996). The different correlation structures
available for the correlation
argument are described in Box,
Jenkins and Reinse (1994), Littel et al (1996), and Venables and
Ripley, (2002). The use of variance functions for linear and nonlinear
mixed effects models is presented in detail in Davidian and Giltinan
(1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden–Day.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Laird, N.M. and Ware, J.H. (1982) "Random-Effects Models for Longitudinal Data", Biometrics, 38, 963–974.
Lindstrom, M.J. and Bates, D.M. (1988) "Newton-Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data", Journal of the American Statistical Association, 83, 1014–1022.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289–296.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
fm1 <- lmList(Orthodont) fm2 <- lme(fm1) summary(fm1) summary(fm2)
fm1 <- lmList(Orthodont) fm2 <- lme(fm1) summary(fm1) summary(fm2)
The values supplied in the lmeControl()
call replace the
defaults, and a list
with all settings (i.e., values for
all possible arguments) is returned. The returned list is
used as the control
argument to the lme
function.
lmeControl(maxIter = 50, msMaxIter = 50, tolerance = 1e-6, niterEM = 25, msMaxEval = 200, msTol = 1e-7, msVerbose = FALSE, returnObject = FALSE, gradHess = TRUE, apVar = TRUE, .relStep = .Machine$double.eps^(1/3), minAbsParApVar = 0.05, opt = c("nlminb", "optim"), optimMethod = "BFGS", natural = TRUE, sigma = NULL, allow.n.lt.q = FALSE, ...)
lmeControl(maxIter = 50, msMaxIter = 50, tolerance = 1e-6, niterEM = 25, msMaxEval = 200, msTol = 1e-7, msVerbose = FALSE, returnObject = FALSE, gradHess = TRUE, apVar = TRUE, .relStep = .Machine$double.eps^(1/3), minAbsParApVar = 0.05, opt = c("nlminb", "optim"), optimMethod = "BFGS", natural = TRUE, sigma = NULL, allow.n.lt.q = FALSE, ...)
maxIter |
maximum number of iterations for the |
msMaxIter |
maximum number of iterations
for the optimization step inside the |
tolerance |
tolerance for the convergence criterion in the
|
niterEM |
number of iterations for the EM algorithm used to refine
the initial estimates of the random effects variance-covariance
coefficients. Default is |
msMaxEval |
maximum number of evaluations of the objective
function permitted for |
msTol |
tolerance for the convergence criterion on the first
iteration when |
msVerbose |
a logical value passed as the |
returnObject |
a logical value indicating whether the fitted
object should be returned with a |
gradHess |
a logical value indicating whether numerical gradient
vectors and Hessian matrices of the log-likelihood function should
be used in the internal optimization. This option is only available
when the correlation structure ( |
apVar |
a logical value indicating whether the approximate
covariance matrix of the variance-covariance parameters should be
calculated. Default is |
.relStep |
relative step for numerical derivatives
calculations. Default is |
opt |
the optimizer to be used, either |
optimMethod |
character - the optimization method to be used with
the |
minAbsParApVar |
numeric value - minimum absolute parameter value
in the approximate variance calculation. The default is |
natural |
a logical value indicating whether the |
sigma |
optionally a positive number to fix the residual error at.
If |
allow.n.lt.q |
|
... |
further named control arguments to be passed, depending on
|
a list with components for each of the possible arguments.
José Pinheiro and Douglas Bates [email protected]; the
sigma
option: Siem Heisterkamp and Bert van Willigen.
# decrease the maximum number iterations in the ms call and # request that information on the evolution of the ms iterations be printed str(lCtr <- lmeControl(msMaxIter = 20, msVerbose = TRUE)) ## This should always work: do.call(lmeControl, lCtr)
# decrease the maximum number iterations in the ms call and # request that information on the evolution of the ms iterations be printed str(lCtr <- lmeControl(msMaxIter = 20, msVerbose = TRUE)) ## This should always work: do.call(lmeControl, lCtr)
An object returned by the lme
function, inheriting from class
"lme"
and representing a fitted linear mixed-effects
model. Objects of this class have methods for the generic functions
anova
, coef
, fitted
, fixed.effects
,
formula
, getGroups
, getResponse
,
intervals
, logLik
, pairs
, plot
,
predict
, print
, random.effects
, residuals
,
sigma
, summary
, update
, and vcov
.
The following components must be included in a legitimate "lme"
object.
apVar |
an approximate covariance matrix for the
variance-covariance coefficients. If |
call |
a list containing an image of the |
coefficients |
a list with two components, |
contrasts |
a list of the contrast matrices used to represent factors in the fixed effects formula and/or random effects formula. This information is important for making predictions from a new data frame in which not all levels of the original factors are observed. If no factors are used in the lme model, this component will be an empty list. |
dims |
a list with basic dimensions used in the lme fit,
including the components |
fitted |
a data frame with the fitted values as columns. The leftmost column corresponds to the population fixed effects (corresponding to the fixed effects only) and successive columns from left to right correspond to increasing levels of grouping. |
fixDF |
a list with components |
groups |
a data frame with the grouping factors as columns. The grouping level increases from left to right. |
logLik |
the (restricted) log-likelihood at convergence. |
method |
the estimation method: either |
modelStruct |
an object inheriting from class |
numIter |
the number of iterations used in the iterative algorithm. |
residuals |
a data frame with the residuals as columns. The leftmost column corresponds to the population residuals and successive columns from left to right correspond to increasing levels of grouping. |
terms |
the |
sigma |
the estimated within-group error standard deviation. |
varFix |
an approximate covariance matrix of the fixed effects estimates. |
José Pinheiro and Douglas Bates [email protected]
lme
, lmeStruct
A linear mixed-effects structure is a list of model components
representing different sets of parameters in the linear mixed-effects
model. An lmeStruct
list must contain at least a
reStruct
object, but may also contain corStruct
and
varFunc
objects. NULL
arguments are not included in the
lmeStruct
list.
lmeStruct(reStruct, corStruct, varStruct)
lmeStruct(reStruct, corStruct, varStruct)
reStruct |
a |
corStruct |
an optional |
varStruct |
an optional |
a list of model components determining the parameters to be estimated for the associated linear mixed-effects model.
José Pinheiro and Douglas Bates [email protected]
corClasses
,
lme
,
residuals.lmeStruct
,
reStruct
,
varFunc
lms1 <- lmeStruct(reStruct(~age), corAR1(), varPower())
lms1 <- lmeStruct(reStruct(~age), corAR1(), varPower())
Data
is partitioned according to the levels of the grouping
factor g
and individual lm
fits are obtained for each
data
partition, using the model defined in object
.
lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE) ## S3 method for class 'formula' lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE) ## S3 method for class 'lmList' update(object, formula., ..., evaluate = TRUE) ## S3 method for class 'lmList' print(x, pool, ...)
lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE) ## S3 method for class 'formula' lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE) ## S3 method for class 'lmList' update(object, formula., ..., evaluate = TRUE) ## S3 method for class 'lmList' print(x, pool, ...)
object |
For |
formula |
(used in |
formula. |
Changes to the formula – see |
data |
a data frame in which to interpret the variables named in
|
level |
an optional integer specifying the level of grouping to be used when multiple nested levels of grouping are present. |
subset |
an optional expression indicating which subset of the rows of
|
na.action |
a function that indicates what should happen when the
data contain |
pool |
an optional logical value indicating whether a pooled estimate of the residual standard error should be used in calculations of standard deviations or standard errors for summaries. |
warn.lm |
|
x |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
evaluate |
If |
a list of lm
objects with as many components as the number of
groups defined by the grouping factor. Generic functions such as
coef
, fixed.effects
, lme
, pairs
,
plot
, predict
, random.effects
, summary
,
and update
have methods that can be applied to an lmList
object.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
lm
,
lme.lmList
,
plot.lmList
,
pooledSD
,
predict.lmList
,
residuals.lmList
,
summary.lmList
fm1 <- lmList(distance ~ age | Subject, Orthodont) summary(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) summary(fm1)
The response variable and primary covariate in formula(object)
are used to construct the linear model formula. This formula
and the groupedData
object are passed as the object
and
data
arguments to lmList.formula
, together with any other
additional arguments in the function call. See the documentation on
lmList.formula
for a description of that function.
## S3 method for class 'groupedData' lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE)
## S3 method for class 'groupedData' lmList(object, data, level, subset, na.action = na.fail, pool = TRUE, warn.lm = TRUE)
object |
a data frame inheriting from class |
data |
this argument is included for consistency with the generic function. It is ignored in this method function. |
level |
an optional integer specifying the level of grouping to be used when multiple nested levels of grouping are present. |
subset |
an optional expression indicating which subset of the rows of
|
na.action |
a function that indicates what should happen when the
data contain |
pool , warn.lm
|
a list of lm
objects with as many components as the number of
groups defined by the grouping factor. Generic functions such as
coef
, fixed.effects
, lme
, pairs
,
plot
, predict
, random.effects
, summary
,
and update
have methods that can be applied to an lmList
object.
groupedData
, lm
,
lme.lmList
, lmList
,
lmList.formula
fm1 <- lmList(Orthodont) summary(fm1)
fm1 <- lmList(Orthodont) summary(fm1)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: corStruct
, several pdMat
classes,
and reStruct
.
logDet(object, ...)
logDet(object, ...)
object |
any object from which a matrix, or list of matrices, can be extracted |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
logLik
,
logDet.corStruct
,
logDet.pdMat
,
logDet.reStruct
## see the method function documentation
## see the method function documentation
This method function extracts the logarithm of the determinant of a
square-root factor of the correlation matrix associated with
object
, or the sum of the log-determinants of square-root
factors of the list of correlation matrices associated with
object
.
## S3 method for class 'corStruct' logDet(object, covariate, ...)
## S3 method for class 'corStruct' logDet(object, covariate, ...)
object |
an object inheriting from class |
covariate |
an optional covariate vector (matrix), or list of
covariate vectors (matrices), at which values the correlation matrix,
or list of correlation matrices, are to be evaluated. Defaults to
|
... |
some methods for this generic require additional arguments. None are used in this method. |
the log-determinant of a square-root factor of the correlation matrix
associated with object
, or the sum of the log-determinants of
square-root factors of the list of correlation matrices associated
with object
.
José Pinheiro and Douglas Bates [email protected]
logLik.corStruct
,
corMatrix.corStruct
,
logDet
cs1 <- corAR1(0.3) logDet(cs1, covariate = 1:4)
cs1 <- corAR1(0.3) logDet(cs1, covariate = 1:4)
This method function extracts the logarithm of the determinant of a
square-root factor of the positive-definite matrix represented by
object
.
## S3 method for class 'pdMat' logDet(object, ...)
## S3 method for class 'pdMat' logDet(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
the log-determinant of a square-root factor of the positive-definite
matrix represented by object
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdSymm(diag(1:3)) logDet(pd1)
pd1 <- pdSymm(diag(1:3)) logDet(pd1)
Calculates, for each of the pdMat
components of object
,
the logarithm of the determinant of a square-root factor.
## S3 method for class 'reStruct' logDet(object, ...)
## S3 method for class 'reStruct' logDet(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the log-determinants of square-root factors of the
pdMat
components of object
.
José Pinheiro
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) logDet(rs1)
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) logDet(rs1)
This method function extracts the component of a Gaussian
log-likelihood associated with the correlation structure, which is
equal to the negative of the logarithm of the determinant (or sum of
the logarithms of the determinants) of the matrix (or matrices)
represented by object
.
## S3 method for class 'corStruct' logLik(object, data, ...)
## S3 method for class 'corStruct' logLik(object, data, ...)
object |
an object inheriting from class |
data |
this argument is included to make this method function
compatible with other |
... |
some methods for this generic require additional arguments. None are used in this method. |
the negative of the logarithm of the determinant (or sum of
the logarithms of the determinants) of the correlation matrix (or
matrices) represented by object
.
José Pinheiro and Douglas Bates [email protected]
cs1 <- corAR1(0.2) cs1 <- Initialize(cs1, data = Orthodont) logLik(cs1)
cs1 <- corAR1(0.2) cs1 <- Initialize(cs1, data = Orthodont) logLik(cs1)
Pars
is used to update the coefficients of the model components
of object
and the individual (restricted) log-likelihood
contributions of each component are added together. The type of
log-likelihood (restricted or not) is determined by the
settings
attribute of object
.
## S3 method for class 'glsStruct' logLik(object, Pars, conLin, ...)
## S3 method for class 'glsStruct' logLik(object, Pars, conLin, ...)
object |
an object inheriting from class |
Pars |
the parameter values at which the (restricted) log-likelihood is to be evaluated. |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the (restricted) log-likelihood for the linear model described by
object
, evaluated at Pars
.
José Pinheiro and Douglas Bates [email protected]
Returns the log-likelihood value of the nonlinear model represented by
object
evaluated at the estimated coefficients.
## S3 method for class 'gnls' logLik(object, REML, ...)
## S3 method for class 'gnls' logLik(object, REML, ...)
object |
an object inheriting from class |
REML |
an logical value for consistency with |
... |
some methods for this generic require additional arguments. None are used in this method. |
the log-likelihood of the linear model represented by
object
evaluated at the estimated coefficients.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) logLik(fm1)
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) logLik(fm1)
Pars
is used to update the coefficients of the model components
of object
and the individual log-likelihood
contributions of each component are added together.
## S3 method for class 'gnlsStruct' logLik(object, Pars, conLin, ...)
## S3 method for class 'gnlsStruct' logLik(object, Pars, conLin, ...)
object |
an object inheriting from class |
Pars |
the parameter values at which the log-likelihood is to be evaluated. |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the log-likelihood for the linear model described by object
,
evaluated at Pars
.
José Pinheiro and Douglas Bates [email protected]
If REML=FALSE
, returns the log-likelihood value of the linear
mixed-effects model represented by object
evaluated at the
estimated coefficients; else, the restricted log-likelihood evaluated
at the estimated coefficients is returned.
## S3 method for class 'lme' logLik(object, REML, ...)
## S3 method for class 'lme' logLik(object, REML, ...)
object |
an object inheriting from class |
REML |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
the (restricted) log-likelihood of the model represented by
object
evaluated at the estimated coefficients.
José Pinheiro and Douglas Bates
Harville, D.A. (1974) “Bayesian Inference for Variance Components Using Only Error Contrasts”, Biometrika, 61, 383–385.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
lme
,gls
,
logLik.corStruct
,
logLik.glsStruct
,
logLik.lmeStruct
,
logLik.lmList
,
logLik.reStruct
,
logLik.varFunc
,
fm1 <- lme(distance ~ Sex * age, Orthodont, random = ~ age, method = "ML") logLik(fm1) logLik(fm1, REML = TRUE)
fm1 <- lme(distance ~ Sex * age, Orthodont, random = ~ age, method = "ML") logLik(fm1) logLik(fm1, REML = TRUE)
Pars
is used to update the coefficients of the model components
of object
and the individual (restricted) log-likelihood
contributions of each component are added together. The type of
log-likelihood (restricted or not) is determined by the
settings
attribute of object
.
## S3 method for class 'lmeStruct' logLik(object, Pars, conLin, ...)
## S3 method for class 'lmeStruct' logLik(object, Pars, conLin, ...)
object |
an object inheriting from class |
Pars |
the parameter values at which the (restricted) log-likelihood is to be evaluated. |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the (restricted) log-likelihood for the linear mixed-effects model
described by object
, evaluated at Pars
.
José Pinheiro and Douglas Bates [email protected]
If pool=FALSE
, the (restricted) log-likelihoods of the lm
components of object
are summed together. Else, the (restricted)
log-likelihood of the lm
fit with different coefficients for
each level of the grouping factor associated with the partitioning of
the object
components is obtained.
## S3 method for class 'lmList' logLik(object, REML, pool, ...)
## S3 method for class 'lmList' logLik(object, REML, pool, ...)
object |
an object inheriting from class |
REML |
an optional logical value. If |
pool |
an optional logical value indicating whether all |
... |
some methods for this generic require additional arguments. None are used in this method. |
either the sum of the (restricted) log-likelihoods of each lm
component in object
, or the (restricted) log-likelihood for the
lm
fit with separate coefficients for each component of
object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) logLik(fm1) # returns NA when it should not
fm1 <- lmList(distance ~ age | Subject, Orthodont) logLik(fm1) # returns NA when it should not
Calculates the log-likelihood, or restricted log-likelihood, of the
Gaussian linear mixed-effects model represented by object
and
conLin
(assuming spherical within-group covariance structure),
evaluated at coef(object)
. The settings
attribute of
object
determines whether the log-likelihood, or the restricted
log-likelihood, is to be calculated. The computational methods are
described in Bates and Pinheiro (1998).
## S3 method for class 'reStruct' logLik(object, conLin, ...)
## S3 method for class 'reStruct' logLik(object, conLin, ...)
object |
an object inheriting from class |
conLin |
a condensed linear model object, consisting of a list
with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the log-likelihood, or restricted log-likelihood, of linear
mixed-effects model represented by object
and conLin
,
evaluated at coef{object}
.
José Pinheiro and Douglas Bates [email protected]
This method function extracts the component of a Gaussian
log-likelihood associated with the variance function structure
represented by object
, which is equal to the sum of the
logarithms of the corresponding weights.
## S3 method for class 'varFunc' logLik(object, data, ...)
## S3 method for class 'varFunc' logLik(object, data, ...)
object |
an object inheriting from class |
data |
this argument is included to make this method function
compatible with other |
... |
some methods for this generic require additional arguments. None are used in this method. |
the sum of the logarithms of the weights corresponding to the variance
function structure represented by object
.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(form = ~age) vf1 <- Initialize(vf1, Orthodont) coef(vf1) <- 0.1 logLik(vf1)
vf1 <- varPower(form = ~age) vf1 <- Initialize(vf1, Orthodont) coef(vf1) <- 0.1 logLik(vf1)
The Machines
data frame has 54 rows and 3 columns.
This data frame contains the following columns:
an ordered factor giving the unique identifier for the worker.
a factor with levels
A
,
B
, and
C
identifying the machine brand.
a productivity score.
Data on an experiment to compare three brands of machines used in an industrial process are presented in Milliken and Johnson (p. 285, 1992). Six workers were chosen randomly among the employees of a factory to operate each machine three times. The response is an overall productivity score taking into account the number and quality of components produced.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.14)
Milliken, G. A. and Johnson, D. E. (1992), Analysis of Messy Data, Volume I: Designed Experiments, Chapman and Hall, London.
The MathAchieve
data frame has 7185 rows and 6 columns.
This data frame contains the following columns:
an ordered factor identifying the school that the student attends
a factor with levels
No
Yes
indicating if the student is a member of a minority racial group.
a factor with levels
Male
Female
a numeric vector of socio-economic status.
a numeric vector of mathematics achievement scores.
a numeric vector of the mean SES for the school.
Each row in this data frame contains the data for one student.
summary(MathAchieve)
summary(MathAchieve)
The MathAchSchool
data frame has 160 rows and 7 columns.
This data frame contains the following columns:
a factor giving the school on which the measurement is made.
a numeric vector giving the number of students in the school
a factor with levels
Public
Catholic
a numeric vector giving the percentage of students on the academic track
a numeric vector measuring the discrimination climate
a factor with levels
0
1
a numeric vector giving the mean SES score.
These variables give the school-level demographic data to accompany
the MathAchieve
data.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include pdMat
, pdBlocked
, and
reStruct
.
matrix(object) <- value
matrix(object) <- value
object |
any object to which |
value |
a matrix, or list of matrices, with the same dimensions as
|
will depend on the method function; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
as.matrix
, also for examples,
matrix<-.pdMat
,
matrix<-.reStruct
.
The positive-definite matrix represented by object
is replaced
by value
. If the original matrix had row and/or column names,
the corresponding names for value
can either be NULL
, or
a permutation of the original names.
## S3 replacement method for class 'pdMat' matrix(object) <- value ## S3 replacement method for class 'pdBlocked' matrix(object) <- value
## S3 replacement method for class 'pdMat' matrix(object) <- value ## S3 replacement method for class 'pdBlocked' matrix(object) <- value
object |
an object inheriting from class |
value |
a matrix with the new values to be assigned to the
positive-definite matrix represented by |
a pdMat
or pdBlocked
object similar to object
,
but with its coefficients modified to produce the matrix in
value
.
José Pinheiro and Douglas Bates [email protected]
class(pd1 <- pdSymm(diag(3))) # "pdSymm" "pdMat" matrix(pd1) <- diag(1:3) pd1
class(pd1 <- pdSymm(diag(3))) # "pdSymm" "pdMat" matrix(pd1) <- diag(1:3) pd1
The individual matrices in value
are assigned to each
pdMat
component of object
, in the order they are listed. The
new matrices must have the same dimensions as the matrices they are
meant to replace.
## S3 replacement method for class 'reStruct' matrix(object) <- value
## S3 replacement method for class 'reStruct' matrix(object) <- value
object |
an object inheriting from class |
value |
a matrix, or list of matrices, with the new values to be
assigned to the matrices associated with the |
an reStruct
object similar to object
, but with the
coefficients of the individual pdMat
components modified to
produce the matrices listed in value
.
José Pinheiro and Douglas Bates [email protected]
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) matrix(rs1) <- list(diag(2), 3)
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) matrix(rs1) <- list(diag(2), 3)
The Meat
data frame has 30 rows and 4 columns.
This data frame contains the following columns:
an ordered factor specifying the storage treatment - 1 (0 days), 2 (1 day), 3 (2 days), 4 (4 days), 5 (9 days), and 6 (18 days)
a numeric vector giving the tenderness score of beef roast.
an ordered factor identifying the muscle from which the
roast was extracted with levels
II
< V
< I
< III
< IV
an ordered factor giving the unique identifier for each pair
of beef roasts with levels II-1
< ... < IV-1
Cochran and Cox (section 11.51, 1957) describe data from an experiment conducted at Iowa State College (Paul, 1943) to compare the effects of length of cold storage on the tenderness of beef roasts. Six storage periods ranging from 0 to 18 days were used. Thirty roasts were scored by four judges on a scale from 0 to 10, with the score increasing with tenderness. The response was the sum of all four scores. Left and right roasts from the same animal were grouped into pairs, which were further grouped into five blocks, according to the muscle from which they were extracted. Different storage periods were applied to each roast within a pair according to a balanced incomplete block design.
Cochran, W. G. and Cox, G. M. (1957), Experimental Designs, Wiley, New York.
The Milk
data frame has 1337 rows and 4 columns.
This data frame contains the following columns:
a numeric vector giving the protein content of the milk.
a numeric vector giving the time since calving (weeks).
an ordered factor giving a unique identifier for each cow.
a factor with levels
barley
,
barley+lupins
, and
lupins
identifying the diet for each cow.
Diggle, Liang, and Zeger (1994) describe data on the protein content of cows' milk in the weeks following calving. The cattle are grouped according to whether they are fed a diet with barley alone, with barley and lupins, or with lupins alone.
Diggle, Peter J., Liang, Kung-Yee and Zeger, Scott L. (1994), Analysis of longitudinal data, Oxford University Press, Oxford.
The model matrices for each element of formula(object)
,
calculated using data
, are bound together column-wise. When
multiple grouping levels are present (i.e. when length(object) >
1
), the individual model matrices are combined from innermost (at
the leftmost position) to outermost (at the rightmost position).
## S3 method for class 'reStruct' model.matrix(object, data, contrast, ...)
## S3 method for class 'reStruct' model.matrix(object, data, contrast, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables defined in
|
contrast |
an optional named list specifying the contrasts to be used
for representing the |
... |
some methods for this generic require additional arguments. None are used in this method. |
a matrix obtained by binding together, column-wise, the model matrices
for each element of formula(object)
.
José Pinheiro and Douglas Bates [email protected]
model.matrix
, contrasts
,
reStruct
, formula.reStruct
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) model.matrix(rs1, Pixel)
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) model.matrix(rs1, Pixel)
The Muscle
data frame has 60 rows and 3 columns.
This data frame contains the following columns:
an ordered factor indicating the strip of muscle being measured.
a numeric vector giving the concentration of CaCl2
a numeric vector giving the shortening of the heart muscle strip.
Baumann and Waldvogel (1963) describe data on the shortening of heart
muscle strips dipped in a solution.
The muscle strips are taken from the left auricle of a rat's heart.
Baumann, F. and Waldvogel, F. (1963), La restitution pastsystolique de la contraction de l'oreillette gauche du rat. Effets de divers ions et de l'acetylcholine, Helvetica Physiologica Acta, 21.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: formula
, modelStruct
,
pdBlocked
, pdMat
, and reStruct
.
Names(object, ...) Names(object, ...) <- value
Names(object, ...) Names(object, ...) <- value
object |
any object for which names can be extracted and/or assigned. |
... |
some methods for this generic function require additional arguments. |
value |
names to be assigned to |
will depend on the method function used; see the appropriate documentation.
On the left side of an assignment, sets the names associated with
object
to value
, which must have an appropriate length.
If names
were generic, there would be no need for this generic
function.
José Pinheiro and Douglas Bates [email protected]
## see the method function documentation
## see the method function documentation
This method function returns the names of the terms corresponding to
the right hand side of object
(treated as a linear formula),
obtained as the column names of the corresponding
model.matrix
.
## S3 method for class 'formula' Names(object, data, exclude, ...)
## S3 method for class 'formula' Names(object, data, exclude, ...)
object |
an object inheriting from class |
data |
an optional data frame containing the variables specified
in |
exclude |
an optional character vector with names to be excluded
from the returned value. Default is |
... |
some methods for this generic require additional arguments. None are used in this method. |
a character vector with the column names of the model.matrix
corresponding to the right hand side of object
which are not
listed in excluded
.
José Pinheiro and Douglas Bates [email protected]
Names(distance ~ Sex * age, data = Orthodont)
Names(distance ~ Sex * age, data = Orthodont)
This method function extracts the first element of the Dimnames
attribute, which contains the column names, for each block diagonal
element in the matrix represented by object
.
## S3 method for class 'pdBlocked' Names(object, asList, ...)
## S3 method for class 'pdBlocked' Names(object, asList, ...)
object |
an object inheriting from class |
asList |
a logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
if asList
is FALSE
, a character vector with column names
of the matrix represented by object
; otherwise, if
asList
is TRUE
, a list with components given by the
column names of the individual block diagonal elements in the matrix
represented by object
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdBlocked(list(~Sex - 1, ~age - 1), data = Orthodont) Names(pd1)
pd1 <- pdBlocked(list(~Sex - 1, ~age - 1), data = Orthodont) Names(pd1)
This method function returns the fist element of the Dimnames
attribute of object
, which contains the column names of the
matrix represented by object
.
## S3 method for class 'pdMat' Names(object, ...) ## S3 replacement method for class 'pdMat' Names(object, ...) <- value
## S3 method for class 'pdMat' Names(object, ...) ## S3 replacement method for class 'pdMat' Names(object, ...) <- value
object |
an object inheriting from class |
value |
a character vector with the replacement values for the
column and row names of the matrix represented by |
... |
some methods for this generic require additional arguments. None are used in this method. |
if object
has a Dimnames
attribute then the first
element of this attribute is returned; otherwise NULL
.
On the left side of an assignment, sets the Dimnames
attribute
of object
to list(value, value)
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdSymm(~age, data = Orthodont) Names(pd1)
pd1 <- pdSymm(~age, data = Orthodont) Names(pd1)
This method function extracts the column names of each of the
positive-definite matrices represented the pdMat
elements of object
.
## S3 method for class 'reStruct' Names(object, ...) ## S3 replacement method for class 'reStruct' Names(object, ...) <- value
## S3 method for class 'reStruct' Names(object, ...) ## S3 replacement method for class 'reStruct' Names(object, ...) <- value
object |
an object inheriting from class |
value |
a list of character vectors with the replacement values
for the names of the individual |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list containing the column names of each of the positive-definite
matrices represented by the pdMat
elements of object
.
On the left side of an assignment, sets the Names
of the
pdMat
elements of object
to the corresponding element of
value
.
José Pinheiro and Douglas Bates [email protected]
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) Names(rs1)
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) Names(rs1)
This function is generic; method functions can be written to handle
specific classes of objects. By default, it tries to extract a
needUpdate
attribute of object
. If this is NULL
or FALSE
it returns FALSE
; else it returns TRUE
.
Updating of objects usually takes place in iterative algorithms in
which auxiliary quantities associated with the object, and not being
optimized over, may change.
needUpdate(object)
needUpdate(object)
object |
any object |
a logical value indicating whether object
needs to be updated.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varExp() vf1 <- Initialize(vf1, data = Orthodont) needUpdate(vf1)
vf1 <- varExp() vf1 <- Initialize(vf1, data = Orthodont) needUpdate(vf1)
This method function checks if any of the elements of object
needs to be updated. Updating of objects usually takes place in
iterative algorithms in which auxiliary quantities associated with the
object, and not being optimized over, may change.
## S3 method for class 'modelStruct' needUpdate(object)
## S3 method for class 'modelStruct' needUpdate(object)
object |
an object inheriting from class |
a logical value indicating whether any element of object
needs
to be updated.
José Pinheiro and Douglas Bates [email protected]
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), varStruct = varPower(form = ~age)) needUpdate(lms1)
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), varStruct = varPower(form = ~age)) needUpdate(lms1)
The Nitrendipene
data frame has 89 rows and 4 columns.
This data frame contains the following columns:
a numeric vector
a numeric vector
an ordered factor with levels
2
< 1
< 3
< 4
a numeric vector
Bates, D. M. and Watts, D. G. (1988), Nonlinear Regression Analysis and Its Applications, Wiley, New York.
This generic function fits a nonlinear mixed-effects model in the formulation described in Lindstrom and Bates (1990) but allowing for nested random effects. The within-group errors are allowed to be correlated and/or have unequal variances.
nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose) ## S3 method for class 'formula' nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose)
nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose) ## S3 method for class 'formula' nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose)
model |
a nonlinear model formula, with the response on the left
of a |
data |
an optional data frame containing the variables named in
|
fixed |
a two-sided linear formula of the form
|
random |
optionally, any of the following: (i) a two-sided formula
of the form |
groups |
an optional one-sided formula of the form |
start |
an optional numeric vector, or list of initial estimates
for the fixed effects and random effects. If declared as a numeric
vector, it is converted internally to a list with a single component
|
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating the subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
naPattern |
an expression or formula object, specifying which returned values are to be regarded as missing. |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
verbose |
an optional logical value. If |
an object of class nlme
representing the nonlinear
mixed-effects model fit. Generic functions such as print
,
plot
and summary
have methods to show the results of the
fit. See nlmeObject
for the components of the fit. The functions
resid
, coef
, fitted
, fixed.effects
, and
random.effects
can be used to extract some of its components.
The function does not do any scaling internally: the optimization will work best when the response is scaled so its variance is of the order of one.
José Pinheiro and Douglas Bates [email protected]
The model formulation and computational methods are described in Lindstrom, M.J. and Bates, D.M. (1990). The variance-covariance parametrizations are described in Pinheiro and Bates (1996).
Lindstrom, M.J. and Bates, D.M. (1990) "Nonlinear Mixed Effects Models for Repeated Measures Data", Biometrics, 46, 673-687.
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
For the different correlation structures, variance functions and links,
see ‘References’ in lme
.
nlmeControl
, nlme.nlsList
,
nlmeObject
, nlsList
,
nlmeStruct
,
pdClasses
,
reStruct
, varFunc
,
corClasses
, varClasses
fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly, fixed = Asym + R0 + lrc ~ 1, random = Asym ~ 1, start = c(Asym = 103, R0 = -8.5, lrc = -3.3)) summary(fm1) fm2 <- update(fm1, random = pdDiag(Asym + lrc ~ 1)) summary(fm2)
fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly, fixed = Asym + R0 + lrc ~ 1, random = Asym ~ 1, start = c(Asym = 103, R0 = -8.5, lrc = -3.3)) summary(fm1) fm2 <- update(fm1, random = pdDiag(Asym + lrc ~ 1)) summary(fm2)
If the random effects names defined in random
are a subset of
the lmList
object coefficient names, initial estimates for the
covariance matrix of the random effects are obtained (overwriting any
values given in random
). formula(fixed)
and the
data
argument in the calling sequence used to obtain
fixed
are passed as the fixed
and data
arguments
to nlme.formula
, together with any other additional arguments in
the function call. See the documentation on nlme.formula
for a
description of that function.
## S3 method for class 'nlsList' nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose)
## S3 method for class 'nlsList' nlme(model, data, fixed, random, groups, start, correlation, weights, subset, method, na.action, naPattern, control, verbose)
model |
an object inheriting from class |
data |
this argument is included for consistency with the generic function. It is ignored in this method function. |
fixed |
this argument is included for consistency with the generic function. It is ignored in this method function. |
random |
an optional one-sided linear formula with no conditioning
expression, or a |
groups |
an optional one-sided formula of the form |
start |
an optional numeric vector, or list of initial estimates
for the fixed effects and random effects. If declared as a numeric
vector, it is converted internally to a list with a single component
|
correlation |
an optional |
weights |
an optional |
subset |
an optional expression indicating the subset of the rows of
|
method |
a character string. If |
na.action |
a function that indicates what should happen when the
data contain |
naPattern |
an expression or formula object, specifying which returned values are to be regarded as missing. |
control |
a list of control values for the estimation algorithm to
replace the default values returned by the function |
verbose |
an optional logical value. If |
an object of class nlme
representing the linear mixed-effects
model fit. Generic functions such as print
, plot
and
summary
have methods to show the results of the fit. See
nlmeObject
for the components of the fit. The functions
resid
, coef
, fitted
, fixed.effects
, and
random.effects
can be used to extract some of its components.
José Pinheiro and Douglas Bates [email protected]
The computational methods follow on the general framework of Lindstrom,
M.J. and Bates, D.M. (1988). The model formulation is described in
Laird, N.M. and Ware, J.H. (1982). The variance-covariance
parametrizations are described in <Pinheiro, J.C. and Bates., D.M.
(1996). The different correlation structures available for the
correlation
argument are described in Box, G.E.P., Jenkins,
G.M., and Reinsel G.C. (1994), Littel, R.C., Milliken, G.A., Stroup,
W.W., and Wolfinger, R.D. (1996), and Venables, W.N. and Ripley,
B.D. (2002). The use of variance functions for linear and nonlinear
mixed effects models is presented in detail in Davidian, M. and
Giltinan, D.M. (1995).
Box, G.E.P., Jenkins, G.M., and Reinsel G.C. (1994) "Time Series Analysis: Forecasting and Control", 3rd Edition, Holden-Day.
Davidian, M. and Giltinan, D.M. (1995) "Nonlinear Mixed Effects Models for Repeated Measurement Data", Chapman and Hall.
Laird, N.M. and Ware, J.H. (1982) "Random-Effects Models for Longitudinal Data", Biometrics, 38, 963-974.
Lindstrom, M.J. and Bates, D.M. (1988) "Newton-Raphson and EM Algorithms for Linear Mixed-Effects Models for Repeated-Measures Data", Journal of the American Statistical Association, 83, 1014-1022.
Littel, R.C., Milliken, G.A., Stroup, W.W., and Wolfinger, R.D. (1996) "SAS Systems for Mixed Models", SAS Institute.
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
Venables, W.N. and Ripley, B.D. (2002) "Modern Applied Statistics with S", 4th Edition, Springer-Verlag.
fm1 <- nlsList(SSasymp, data = Loblolly) fm2 <- nlme(fm1, random = Asym ~ 1) summary(fm1) summary(fm2)
fm1 <- nlsList(SSasymp, data = Loblolly) fm2 <- nlme(fm1, random = Asym ~ 1) summary(fm1) summary(fm2)
The values supplied in the function call replace the defaults and a
list with all possible arguments is returned. The returned list is
used as the control
argument to the nlme
function.
nlmeControl(maxIter, pnlsMaxIter, msMaxIter, minScale, tolerance, niterEM, pnlsTol, msTol, returnObject, msVerbose, msWarnNoConv, gradHess, apVar, .relStep, minAbsParApVar = 0.05, opt = c("nlminb", "nlm"), natural = TRUE, sigma = NULL, ...)
nlmeControl(maxIter, pnlsMaxIter, msMaxIter, minScale, tolerance, niterEM, pnlsTol, msTol, returnObject, msVerbose, msWarnNoConv, gradHess, apVar, .relStep, minAbsParApVar = 0.05, opt = c("nlminb", "nlm"), natural = TRUE, sigma = NULL, ...)
maxIter |
maximum number of iterations for the |
pnlsMaxIter |
maximum number of iterations
for the |
msMaxIter |
maximum number of iterations for |
minScale |
minimum factor by which to shrink the default step size
in an attempt to decrease the sum of squares in the |
tolerance |
tolerance for the convergence criterion in the
|
niterEM |
number of iterations for the EM algorithm used to refine the initial estimates of the random effects variance-covariance coefficients. Default is 25. |
pnlsTol |
tolerance for the convergence criterion in |
msTol |
tolerance for the convergence criterion in |
returnObject |
a logical value indicating whether the fitted
object should be returned when the maximum number of iterations is
reached without convergence of the algorithm. Default is
|
msVerbose |
a logical value passed as the |
msWarnNoConv |
logical indicating if a |
gradHess |
a logical value indicating whether numerical gradient
vectors and Hessian matrices of the log-likelihood function should
be used in the |
apVar |
a logical value indicating whether the approximate
covariance matrix of the variance-covariance parameters should be
calculated. Default is |
.relStep |
relative step for numerical derivatives
calculations. Default is |
minAbsParApVar |
numeric value - minimum absolute parameter value
in the approximate variance calculation. The default is |
opt |
the optimizer to be used, either |
natural |
a logical value indicating whether the |
sigma |
optionally a positive number to fix the residual error at.
If |
... |
Further, named control arguments to be passed to
|
a list with components for each of the possible arguments.
José Pinheiro and Douglas Bates [email protected]; the
sigma
option: Siem Heisterkamp and Bert van Willigen.
nlme
, nlm
, optim
,
nlmeStruct
# decrease the maximum number of iterations and request tracing nlmeControl(msMaxIter = 20, msVerbose = TRUE)
# decrease the maximum number of iterations and request tracing nlmeControl(msMaxIter = 20, msVerbose = TRUE)
An object returned by the nlme
function, inheriting from class
"nlme"
, also inheriting from class "lme"
, and representing a
fitted nonlinear mixed-effects model. Objects of this class have
methods for the generic functions anova
, coef
,
fitted
, fixed.effects
, formula
, getGroups
,
getResponse
, intervals
, logLik
, pairs
,
plot
, predict
, print
, random.effects
,
residuals
, summary
, and update
.
The following components must be included in a legitimate "nlme"
object.
apVar |
an approximate covariance matrix for the
variance-covariance coefficients. If |
call |
a list containing an image of the |
coefficients |
a list with two components, |
contrasts |
a list of the contrast matrices used to represent factors in the fixed effects formula and/or random effects formula. This information is important for making predictions from a new data frame in which not all levels of the original factors are observed. If no factors are used in the nlme model, this component will be an empty list. |
dims |
a list with basic dimensions used in the nlme fit,
including the components |
fitted |
a data frame with the fitted values as columns. The leftmost column corresponds to the population fixed effects (corresponding to the fixed effects only) and successive columns from left to right correspond to increasing levels of grouping. |
fixDF |
a list with components |
groups |
a data frame with the grouping factors as columns. The grouping level increases from left to right. |
logLik |
the (restricted) log-likelihood at convergence. |
map |
a list with components |
method |
the estimation method: either |
modelStruct |
an object inheriting from class |
numIter |
the number of iterations used in the iterative algorithm. |
residuals |
a data frame with the residuals as columns. The leftmost column corresponds to the population residuals and successive columns from left to right correspond to increasing levels of grouping. |
sigma |
the estimated within-group error standard deviation. |
varFix |
an approximate covariance matrix of the fixed effects estimates. |
José Pinheiro and Douglas Bates [email protected]
nlme
, nlmeStruct
A nonlinear mixed-effects structure is a list of model components
representing different sets of parameters in the nonlinear mixed-effects
model. An nlmeStruct
list must contain at least a
reStruct
object, but may also contain corStruct
and
varFunc
objects. NULL
arguments are not included in the
nlmeStruct
list.
nlmeStruct(reStruct, corStruct, varStruct)
nlmeStruct(reStruct, corStruct, varStruct)
reStruct |
a |
corStruct |
an optional |
varStruct |
an optional |
a list of model components determining the parameters to be estimated for the associated nonlinear mixed-effects model.
José Pinheiro and Douglas Bates [email protected]
corClasses
,
nlme
,
residuals.nlmeStruct
,
reStruct
,
varFunc
nlms1 <- nlmeStruct(reStruct(~age), corAR1(), varPower())
nlms1 <- nlmeStruct(reStruct(~age), corAR1(), varPower())
Data
is partitioned according to the levels of the grouping
factor defined in model
and individual nls
fits are
obtained for each data
partition, using the model defined in
model
.
nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA) ## S3 method for class 'formula' nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA) ## S3 method for class 'nlsList' update(object, model., ..., evaluate = TRUE)
nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA) ## S3 method for class 'formula' nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA) ## S3 method for class 'nlsList' update(object, model., ..., evaluate = TRUE)
object |
an object inheriting from class |
model |
either a nonlinear model formula, with the response on
the left of a |
model. |
changes to the model – see |
data |
a data frame in which to interpret the variables named in
|
start |
an optional named list with initial values for the
parameters to be estimated in |
control |
a list of control values passed as the |
level |
an optional integer specifying the level of grouping to be used when multiple nested levels of grouping are present. |
subset |
an optional expression indicating the subset of the rows of
|
na.action |
a function that indicates what should happen when the
data contain |
pool |
an optional logical value that is preserved as an attribute of the
returned value. This will be used as the default for |
warn.nls |
|
... |
some methods for this generic require additional arguments. None are used in this method. |
evaluate |
If |
As nls(.)
is called on each sub group, and convergence
of these may be problematic, these calls happen with error catching.
Since nlme version 3.1-127
(2016-04), all the errors are
caught (via tryCatch
) and if present, a “summarizing”
warning
is stored as attribute of the resulting
"nlsList"
object and signalled unless suppressed by
warn.nls = FALSE
or currently also when warn.nls = NA
(default) and getOption("show.error.messages")
is
false.
nlsList()
originally had used try(*)
(with its default
silent=FALSE)
and hence all errors were printed to the console
unless the global option show.error.messages
was set to true.
This still works, but has been deprecated.
a list of nls
objects with as many components as the number of
groups defined by the grouping factor. Generic functions such as
coef
, fixed.effects
, lme
, pairs
,
plot
, predict
, random.effects
, summary
,
and update
have methods that can be applied to an nlsList
object.
Pinheiro, J.C., and Bates, D.M. (2000), Mixed-Effects Models in S and S-PLUS, Springer.
nls
, nlme.nlsList
,
nlsList.selfStart
,
summary.nlsList
fm1 <- nlsList(uptake ~ SSasympOff(conc, Asym, lrc, c0), data = CO2, start = c(Asym = 30, lrc = -4.5, c0 = 52)) summary(fm1) cfm1 <- confint(fm1) # via profiling each % FIXME: only *one* message instead of one *each* mat.class <- class(matrix(1)) # ("matrix", "array") for R >= 4.0.0; ("matrix" in older R) i.ok <- which(vapply(cfm1, function(r) identical(class(r), mat.class), NA)) stopifnot(length(i.ok) > 0, !anyNA(match(c(2:4, 6:9, 12), i.ok))) ## where as (some of) the others gave errors during profile re-fitting : str(cfm1[- i.ok])
fm1 <- nlsList(uptake ~ SSasympOff(conc, Asym, lrc, c0), data = CO2, start = c(Asym = 30, lrc = -4.5, c0 = 52)) summary(fm1) cfm1 <- confint(fm1) # via profiling each % FIXME: only *one* message instead of one *each* mat.class <- class(matrix(1)) # ("matrix", "array") for R >= 4.0.0; ("matrix" in older R) i.ok <- which(vapply(cfm1, function(r) identical(class(r), mat.class), NA)) stopifnot(length(i.ok) > 0, !anyNA(match(c(2:4, 6:9, 12), i.ok))) ## where as (some of) the others gave errors during profile re-fitting : str(cfm1[- i.ok])
The response variable and primary covariate in formula(data)
are used together with model
to construct the nonlinear model
formula. This is used in the nls
calls and, because a
self-starting model function can calculate initial estimates for its
parameters from the data, no starting estimates need to be provided.
## S3 method for class 'selfStart' nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA)
## S3 method for class 'selfStart' nlsList(model, data, start, control, level, subset, na.action = na.fail, pool = TRUE, warn.nls = NA)
model |
a |
data |
a data frame in which to interpret the variables in
|
start |
an optional named list with initial values for the
parameters to be estimated in |
control |
a list of control values passed as the |
level |
an optional integer specifying the level of grouping to be used when multiple nested levels of grouping are present. |
subset |
an optional expression indicating the subset of the rows of
|
na.action |
a function that indicates what should happen when the
data contain |
pool , warn.nls
|
a list of nls
objects with as many components as the number of
groups defined by the grouping factor. A NULL
value is assigned
to the components corresponding to clusters for which the nls
algorithm failed to converge. Generic functions such as coef
,
fixed.effects
, lme
, pairs
, plot
,
predict
, random.effects
, summary
, and
update
have methods that can be applied to an nlsList
object.
selfStart
, groupedData
,
nls
, nlsList
,
nlme.nlsList
, nlsList.formula
fm1 <- nlsList(SSasympOff, CO2) summary(fm1)
fm1 <- nlsList(SSasympOff, CO2) summary(fm1)
The Oats
data frame has 72 rows and 4 columns.
This data frame contains the following columns:
an ordered factor with levels
VI
< V
< III
< IV
< II
< I
a factor with levels
Golden Rain
Marvellous
Victory
a numeric vector
a numeric vector
These data have been introduced by Yates (1935) as an example of a
split-plot design. The treatment structure used in the experiment was
a full factorial, with three varieties of oats
and four concentrations of nitrogen. The experimental units were
arranged into six blocks, each with three whole-plots subdivided into
four subplots. The varieties of oats were assigned randomly to the
whole-plots and the concentrations of nitrogen to the subplots. All
four concentrations of nitrogen were used on each whole-plot.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.15)
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. (4th ed), Springer, New York.
The Orthodont
data frame has 108 rows and 4 columns of the
change in an orthdontic measurement over time for several young subjects.
This data frame contains the following columns:
a numeric vector of distances from the pituitary to the pterygomaxillary fissure (mm). These distances are measured on x-ray images of the skull.
a numeric vector of ages of the subject (yr).
an ordered factor indicating the subject on which the
measurement was made. The levels are labelled M01
to M16
for the males and F01
to F13
for
the females. The ordering is by increasing average distance
within sex.
a factor with levels
Male
and
Female
Investigators at the University of North Carolina Dental School followed the growth of 27 children (16 males, 11 females) from age 8 until age 14. Every two years they measured the distance between the pituitary and the pterygomaxillary fissure, two points that are easily identified on x-ray exposures of the side of the head.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.17)
Potthoff, R. F. and Roy, S. N. (1964), “A generalized multivariate analysis of variance model useful especially for growth curve problems”, Biometrika, 51, 313–326.
formula(Orthodont) plot(Orthodont)
formula(Orthodont) plot(Orthodont)
The Ovary
data frame has 308 rows and 3 columns.
This data frame contains the following columns:
an ordered factor indicating the mare on which the measurement is made.
time in the estrus cycle. The data were recorded daily from 3 days before ovulation until 3 days after the next ovulation. The measurement times for each mare are scaled so that the ovulations for each mare occur at times 0 and 1.
the number of ovarian follicles greater than 10 mm in diameter.
Pierson and Ginther (1987) report on a study of the number of large ovarian follicles detected in different mares at several times in their estrus cycles.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.18)
Pierson, R. A. and Ginther, O. J. (1987), Follicular population dynamics during the estrus cycle of the mare, Animal Reproduction Science, 14, 219-231.
The Oxboys
data frame has 234 rows and 4 columns.
This data frame contains the following columns:
an ordered factor giving a unique identifier for each boy in the experiment
a numeric vector giving the standardized age (dimensionless)
a numeric vector giving the height of the boy (cm)
an ordered factor - the result of converting age
from a
continuous variable to a count so these slightly unbalanced
data can be analyzed as balanced.
These data are described in Goldstein (1987) as data on the height of a selection of boys from Oxford, England versus a standardized age.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.19)
The Oxide
data frame has 72 rows and 5 columns.
This data frame contains the following columns:
a factor with levels
1
and
2
a factor giving a unique identifier for each lot.
a factor giving a unique identifier for each wafer within a lot.
a factor with levels
1
,
2
, and
3
a numeric vector giving the thickness of the oxide layer.
These data are described in Littell et al. (1996, p. 155) as coming “from a passive data collection study in the semiconductor industry where the objective is to estimate the variance components to determine the assignable causes of the observed variability.” The observed response is the thickness of the oxide layer on silicon wafers, measured at three different sites of each of three wafers selected from each of eight lots sampled from the population of lots.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.20)
Littell, R. C., Milliken, G. A., Stroup, W. W. and Wolfinger, R. D. (1996), SAS System for Mixed Models, SAS Institute, Cary, NC.
Scatter plots of the values being compared are generated for each pair
of coefficients in x
. Different symbols (colors) are used
for each object being compared and values corresponding to the same
group are joined by a line, to facilitate comparison of fits. If only
two coefficients are present, the trellis
function
xyplot
is used; otherwise the trellis
function splom
is used.
## S3 method for class 'compareFits' pairs(x, subset, key, ...)
## S3 method for class 'compareFits' pairs(x, subset, key, ...)
x |
an object of class |
subset |
an optional logical or integer vector specifying which
rows of |
key |
an optional logical value, or list. If |
... |
optional arguments passed down to the |
Pairwise scatter plots of the values being compared, with different symbols (colors) used for each object under comparison.
José Pinheiro and Douglas Bates
compareFits
,
plot.compareFits
,
pairs.lme
,
pairs.lmList
,
xyplot
,
splom
example(compareFits) # cF12 <- compareFits(coef(lmList(Orthodont)), .. lme(*)) pairs(cF12)
example(compareFits) # cF12 <- compareFits(coef(lmList(Orthodont)), .. lme(*)) pairs(cF12)
Diagnostic plots for the linear mixed-effects fit are obtained. The
form
argument gives considerable flexibility in the type of
plot specification. A conditioning expression (on the right side of a
|
operator) always implies that different panels are used for
each level of the conditioning factor, according to a Trellis
display. The expression on the right hand side of the formula, before
a |
operator, must evaluate to a data frame with at least two
columns. If the data frame has two columns, a scatter plot of the two
variables is displayed (the Trellis function xyplot
is
used). Otherwise, if more than two columns are present, a scatter plot
matrix with pairwise scatter plots of the columns in the data frame is
displayed (the Trellis function splom
is used).
## S3 method for class 'lme' pairs(x, form, label, id, idLabels, grid, ...)
## S3 method for class 'lme' pairs(x, form, label, id, idLabels, grid, ...)
x |
an object inheriting from class |
form |
an optional one-sided formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
label |
an optional character vector of labels for the variables in the pairs plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for an outlier
test based on the Mahalanobis distances of the estimated random
effects. Groups with random effects distances greater than the
|
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
points identified according to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot.
José Pinheiro and Douglas Bates [email protected]
lme
,
pairs.compareFits
,
pairs.lmList
,
xyplot
,
splom
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) # scatter plot of coefficients by gender, identifying unusual subjects pairs(fm1, ~coef(., augFrame = TRUE) | Sex, id = 0.1, adj = -0.5) # scatter plot of estimated random effects : pairs(fm1, ~ranef(.))
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) # scatter plot of coefficients by gender, identifying unusual subjects pairs(fm1, ~coef(., augFrame = TRUE) | Sex, id = 0.1, adj = -0.5) # scatter plot of estimated random effects : pairs(fm1, ~ranef(.))
Diagnostic plots for the linear model fits corresponding to the
x
components are obtained. The form
argument
gives considerable flexibility in the type of plot specification. A
conditioning expression (on the right side of a |
operator)
always implies that different panels are used for each level of the
conditioning factor, according to a Trellis display. The expression
on the right hand side of the formula, before a |
operator,
must evaluate to a data frame with at least two columns. If the data
frame has two columns, a scatter plot of the two variables is
displayed (the Trellis function xyplot
is used). Otherwise, if
more than two columns are present, a scatter plot matrix with
pairwise scatter plots of the columns in the data frame is displayed
(the Trellis function splom
is used).
## S3 method for class 'lmList' pairs(x, form, label, id, idLabels, grid, ...)
## S3 method for class 'lmList' pairs(x, form, label, id, idLabels, grid, ...)
x |
an object inheriting from class |
form |
an optional one-sided formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
label |
an optional character vector of labels for the variables in the pairs plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for an outlier
test based on the Mahalanobis distances of the estimated random
effects. Groups with random effects distances greater than the
|
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
points identified according to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot.
José Pinheiro and Douglas Bates [email protected]
lmList
,
pairs.lme
,
pairs.compareFits
,
xyplot
,
splom
fm1 <- lmList(distance ~ age | Subject, Orthodont) # scatter plot of coefficients by gender, identifying unusual subjects pairs(fm1, ~coef(.) | Sex, id = 0.1, adj = -0.5) # scatter plot of estimated random effects -- "bivariate Gaussian (?)" pairs(fm1, ~ranef(.))
fm1 <- lmList(distance ~ age | Subject, Orthodont) # scatter plot of coefficients by gender, identifying unusual subjects pairs(fm1, ~coef(.) | Sex, id = 0.1, adj = -0.5) # scatter plot of estimated random effects -- "bivariate Gaussian (?)" pairs(fm1, ~ranef(.))
The PBG
data frame has 60 rows and 5 columns.
This data frame contains the following columns:
a numeric vector
a numeric vector
an ordered factor with levels
T5
< T4
< T3
< T2
< T1
< P5
< P3
< P2
< P4
< P1
a factor with levels
MDL 72222
Placebo
an ordered factor with levels
5
< 3
< 2
< 4
< 1
Data on an experiment to examine the effect of a antagonist MDL 72222 on the change in blood pressure experienced with increasing dosage of phenylbiguanide are described in Ludbrook (1994) and analyzed in Venables and Ripley (2002, section 10.3). Each of five rabbits was exposed to increasing doses of phenylbiguanide after having either a placebo or the HD5-antagonist MDL 72222 administered.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.21)
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S (4th ed), Springer, New York.
Ludbrook, J. (1994), Repeated measurements and multiple comparisons in cardiovascular research, Cardiovascular Research, 28, 303-311.
This function is a constructor for the pdBlocked
class,
representing a positive-definite block-diagonal matrix. Each
block-diagonal element of the underlying matrix is itself a
positive-definite matrix and is represented internally as an
individual pdMat
object. When value
is
numeric(0)
, a list of uninitialized pdMat
objects, a
list of one-sided formulas, or a list of vectors
of character strings, object
is returned
as an uninitialized pdBlocked
object (with just some of its
attributes and its class defined) and needs to have its coefficients
assigned later, generally using the coef
or matrix
replacement
functions. If value
is a list of initialized pdMat
objects, object
will be constructed from the list obtained by
applying as.matrix
to each of the pdMat
elements of
value
. Finally, if value
is a list of numeric vectors,
they are assumed to represent the unrestricted coefficients
of the block-diagonal elements of the underlying positive-definite
matrix.
pdBlocked(value, form, nam, data, pdClass)
pdBlocked(value, form, nam, data, pdClass)
value |
an optional list with elements to be used as the
|
form |
an optional list of one-sided linear formulas specifying the
row/column names for the block-diagonal elements of the matrix
represented by |
nam |
an optional list of vector of character strings specifying the
row/column names for the block-diagonal elements of the matrix
represented by object. Each of its components must have
length equal to the dimension of the corresponding block-diagonal
element and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
pdClass |
an optional vector of character strings naming the
|
a pdBlocked
object representing a positive-definite
block-diagonal matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 162.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
pd1 <- pdBlocked(list(diag(1:2), diag(c(0.1, 0.2, 0.3))), nam = list(c("A","B"), c("a1", "a2", "a3"))) pd1
pd1 <- pdBlocked(list(diag(1:2), diag(c(0.1, 0.2, 0.3))), nam = list(c("A","B"), c("a1", "a2", "a3"))) pd1
Standard classes of positive-definite matrices (pdMat
)
structures available in the nlme
package.
Available standard classes:
pdSymm |
general positive-definite matrix, with no additional structure |
pdLogChol |
general positive-definite matrix, with no additional structure, using a log-Cholesky parameterization |
pdDiag |
diagonal |
pdIdent |
multiple of an identity |
pdCompSymm |
compound symmetry structure (constant diagonal and constant off-diagonal elements) |
pdBlocked |
block-diagonal matrix, with diagonal blocks of any
"atomic" |
pdNatural |
general positive-definite matrix in natural parametrization (i.e. parametrized in terms of standard deviations and correlations). The underlying coefficients are not unrestricted, so this class should NOT be used for optimization. |
Users may define their own pdMat
classes by specifying a
constructor
function and, at a minimum, methods for the
functions pdConstruct
, pdMatrix
and coef
. For
examples of these functions, see the methods for classes pdSymm
and pdDiag
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
pdBlocked
,
pdCompSymm
,
pdDiag
,
pdFactor
,
pdIdent
,
pdMat
,
pdMatrix
,
pdNatural
,
pdSymm
,
pdLogChol
This function is a constructor for the pdCompSymm
class,
representing a positive-definite matrix with compound symmetry
structure (constant diagonal and constant off-diagonal elements). The
underlying matrix is represented by 2 unrestricted parameters.
When value
is numeric(0)
, an uninitialized pdMat
object, a one-sided formula, or a vector of character strings,
object
is returned as an uninitialized pdCompSymm
object (with just some of its attributes and its class defined) and
needs to have its coefficients assigned later, generally using the
coef
or matrix
replacement functions. If value
is
an initialized
pdMat
object, object
will be constructed from
as.matrix(value)
. Finally, if value
is a numeric vector
of length 2, it is assumed to represent the unrestricted coefficients
of the underlying positive-definite matrix.
pdCompSymm(value, form, nam, data)
pdCompSymm(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
a pdCompSymm
object representing a positive-definite
matrix with compound symmetry structure, also inheriting from class
pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 161.
as.matrix.pdMat
,
coef.pdMat
,
matrix<-.pdMat
,
pdClasses
pd1 <- pdCompSymm(diag(3) + 1, nam = c("A","B","C")) pd1
pd1 <- pdCompSymm(diag(3) + 1, nam = c("A","B","C")) pd1
This function is an alternative constructor for the pdMat
class associated with object
and is mostly used internally in other
functions. See the documentation on the principal constructor
function, generally with the same name as the pdMat
class of
object.
pdConstruct(object, value, form, nam, data, ...)
pdConstruct(object, value, form, nam, data, ...)
object |
an object inheriting from class |
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
... |
optional arguments for some methods. |
a pdMat
object representing a positive-definite matrix,
inheriting from the same classes as object
.
José Pinheiro and Douglas Bates [email protected]
pdCompSymm
, pdDiag
,
pdIdent
, pdNatural
, pdSymm
pd1 <- pdSymm() pdConstruct(pd1, diag(1:4))
pd1 <- pdSymm() pdConstruct(pd1, diag(1:4))
This function give an alternative constructor for the pdBlocked
class, representing a positive-definite block-diagonal matrix. Each
block-diagonal element of the underlying matrix is itself a
positive-definite matrix and is represented internally as an
individual pdMat
object. When value
is
numeric(0)
, a list of uninitialized pdMat
objects, a
list of one-sided formulas, or a list of vectors of character strings,
object
is returned as an uninitialized pdBlocked
object
(with just some of its attributes and its class defined) and needs to
have its coefficients assigned later, generally using the coef
or matrix
replacement functions. If value
is a list of initialized
pdMat
objects, object
will be constructed from the list
obtained by applying as.matrix
to each of the pdMat
elements of value
. Finally, if value
is a list of
numeric vectors, they are assumed to represent the unrestricted
coefficients of the block-diagonal elements of the underlying
positive-definite matrix.
## S3 method for class 'pdBlocked' pdConstruct(object, value, form, nam, data, pdClass, ...)
## S3 method for class 'pdBlocked' pdConstruct(object, value, form, nam, data, pdClass, ...)
object |
an object inheriting from class |
value |
an optional list with elements to be used as the
|
form |
an optional list of one-sided linear formula specifying the
row/column names for the block-diagonal elements of the matrix
represented by |
nam |
an optional list of vector of character strings specifying the
row/column names for the block-diagonal elements of the matrix
represented by object. Each of its components must have
length equal to the dimension of the corresponding block-diagonal
element and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
pdClass |
an optional vector of character strings naming the
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a pdBlocked
object representing a positive-definite
block-diagonal matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
as.matrix.pdMat
,
coef.pdMat
,
pdBlocked
,
pdClasses
,
pdConstruct
,
matrix<-.pdMat
pd1 <- pdBlocked(list(c("A","B"), c("a1", "a2", "a3"))) pdConstruct(pd1, list(diag(1:2), diag(c(0.1, 0.2, 0.3))))
pd1 <- pdBlocked(list(c("A","B"), c("a1", "a2", "a3"))) pdConstruct(pd1, list(diag(1:2), diag(c(0.1, 0.2, 0.3))))
This function is a constructor for the pdDiag
class,
representing a diagonal positive-definite matrix. If the matrix
associated with object
is of dimension , it is
represented by
unrestricted parameters, given by the logarithm
of the square-root of the diagonal values. When
value
is
numeric(0)
, an uninitialized pdMat
object, a one-sided
formula, or a vector of character strings, object
is returned
as an uninitialized pdDiag
object (with just some of its
attributes and its class defined) and needs to have its coefficients
assigned later, generally using the coef
or matrix
replacement
functions. If value
is an initialized pdMat
object,
object
will be constructed from
as.matrix(value)
. Finally, if value
is a numeric vector,
it is assumed to represent the unrestricted coefficients of the
underlying positive-definite
matrix.
pdDiag(value, form, nam, data)
pdDiag(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
a pdDiag
object representing a diagonal positive-definite
matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
pd1 <- pdDiag(diag(1:3), nam = c("A","B","C")) pd1
pd1 <- pdDiag(diag(1:3), nam = c("A","B","C")) pd1
A square-root factor of the positive-definite matrix represented by
object
is obtained. Letting denote a
positive-definite matrix, a square-root factor of
is
any square matrix
such that
. This function extracts
.
pdFactor(object)
pdFactor(object)
object |
an object inheriting from class |
a vector with a square-root factor of the positive-definite matrix
associated with object
stacked column-wise.
This function is used intensively in optimization
algorithms and its value is returned as a vector for efficiency
reasons. The pdMatrix
function can be used to obtain
square-root factors in matrix form.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
pd1 <- pdCompSymm(4 * diag(3) + 1) pdFactor(pd1)
pd1 <- pdCompSymm(4 * diag(3) + 1) pdFactor(pd1)
This method function extracts square-root factors of the
positive-definite matrices corresponding to the pdMat
elements
of object
.
## S3 method for class 'reStruct' pdFactor(object)
## S3 method for class 'reStruct' pdFactor(object)
object |
an object inheriting from class |
a vector with square-root factors of the positive-definite matrices
corresponding to the elements of object
stacked column-wise.
This function is used intensively in optimization
algorithms and its value is returned as a vector for efficiency
reasons. The pdMatrix
function can be used to obtain
square-root factors in matrix form.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
pdFactor
,
pdMatrix.reStruct
,
pdFactor.pdMat
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) pdFactor(rs1)
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) pdFactor(rs1)
This function is a constructor for the pdIdent
class,
representing a multiple of the identity positive-definite matrix.
The matrix associated with object
is represented by 1
unrestricted parameter, given by the logarithm of the square-root of
the diagonal value. When value
is
numeric(0)
, an uninitialized pdMat
object, a one-sided
formula, or a vector of character strings, object
is returned
as an uninitialized pdIdent
object (with just some of its
attributes and its class defined) and needs to have its coefficients
assigned later, generally using the coef
or matrix
replacement
functions. If value
is an initialized pdMat
object,
object
will be constructed from
as.matrix(value)
. Finally, if value
is a numeric value,
it is assumed to represent the unrestricted coefficient of the
underlying positive-definite matrix.
pdIdent(value, form, nam, data)
pdIdent(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
a pdIdent
object representing a multiple of the identity
positive-definite matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
pd1 <- pdIdent(4 * diag(3), nam = c("A","B","C")) pd1
pd1 <- pdIdent(4 * diag(3), nam = c("A","B","C")) pd1
This function is a constructor for the pdLogChol
class,
representing a general positive-definite matrix. If the matrix
associated with object
is of dimension , it is
represented by
unrestricted parameters,
using the log-Cholesky parametrization described in Pinheiro and
Bates (1996).
When value
is numeric(0)
, an uninitialized pdMat
object, a one-sided formula, or a character vector, object
is
returned as an uninitialized pdLogChol
object (with just
some of its attributes and its class defined) and needs to have its
coefficients assigned later, generally using the coef
or
matrix
replacement functions.
If value
is an initialized pdMat
object,
object
will be constructed from as.matrix(value)
.
Finally, if value
is a numeric vector, it is assumed to
represent the unrestricted coefficients of the matrix-logarithm
parametrization of the underlying positive-definite matrix.
pdLogChol(value, form, nam, data)
pdLogChol(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional character vector specifying the row/column names
for the matrix represented by object. It must have length equal to
the dimension of the underlying positive-definite matrix and
unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
Internally, the pdLogChol
representation of a symmetric
positive definite matrix is a vector starting with the logarithms of
the diagonal of the Choleski factorization of that matrix followed by
its upper triangular portion.
a pdLogChol
object representing a general positive-definite
matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C. and Bates., D.M. (1996) Unconstrained Parametrizations for Variance-Covariance Matrices, Statistics and Computing 6, 289–296.
Pinheiro, J.C., and Bates, D.M. (2000) Mixed-Effects Models in S and S-PLUS, Springer.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
(pd1 <- pdLogChol(diag(1:3), nam = c("A","B","C"))) (pd4 <- pdLogChol(1:6)) (pd4c <- chol(pd4)) # -> upper-tri matrix with off-diagonals 4 5 6 pd4c[upper.tri(pd4c)] log(diag(pd4c)) # 1 2 3
(pd1 <- pdLogChol(diag(1:3), nam = c("A","B","C"))) (pd4 <- pdLogChol(1:6)) (pd4c <- chol(pd4)) # -> upper-tri matrix with off-diagonals 4 5 6 pd4c[upper.tri(pd4c)] log(diag(pd4c)) # 1 2 3
This function gives an alternative way of constructing an object
inheriting from the pdMat
class named in pdClass
, or
from data.class(object)
if object
inherits from
pdMat
, and is mostly used internally in other functions. See
the documentation on the principal constructor function, generally
with the same name as the pdMat
class of object.
pdMat(value, form, nam, data, pdClass)
pdMat(value, form, nam, data, pdClass)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
pdClass |
an optional character string naming the
|
a pdMat
object representing a positive-definite matrix,
inheriting from the class named in pdClass
, or from
class(object)
, if object
inherits from pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
pdClasses
,
pdCompSymm
, pdDiag
,
pdIdent
, pdNatural
,
pdSymm
,
reStruct
,
solve.pdMat
,
summary.pdMat
pd1 <- pdMat(diag(1:4), pdClass = "pdDiag") pd1 str(pd1)
pd1 <- pdMat(diag(1:4), pdClass = "pdDiag") pd1 str(pd1)
The positive-definite matrix represented by object
, or a
square-root factor of it is obtained. Letting denote a
positive-definite matrix, a square-root factor of
is
any square matrix
such that
. This function extracts
or
.
pdMatrix(object, factor)
pdMatrix(object, factor)
object |
an object inheriting from class |
factor |
an optional logical value. If |
if factor
is FALSE
the positive-definite matrix
represented by object
is returned; else a square-root of the
positive-definite matrix is returned.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 162.
as.matrix.pdMat
,
pdClasses
,
pdFactor
,
pdMat
,
pdMatrix.reStruct
,
corMatrix
pd1 <- pdSymm(diag(1:4)) pdMatrix(pd1)
pd1 <- pdSymm(diag(1:4)) pdMatrix(pd1)
This method function extracts the positive-definite matrices
corresponding to the pdMat
elements of object
, or
square-root factors of the positive-definite matrices.
## S3 method for class 'reStruct' pdMatrix(object, factor)
## S3 method for class 'reStruct' pdMatrix(object, factor)
object |
an object inheriting from class |
factor |
an optional logical value. If |
a list with components given by the positive-definite matrices
corresponding to the elements of object
, or square-root factors
of the positive-definite matrices.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 162.
as.matrix.reStruct
,
reStruct
,
pdMat
,
pdMatrix
,
pdMatrix.pdMat
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) pdMatrix(rs1)
rs1 <- reStruct(pdSymm(diag(3), ~age+Sex, data = Orthodont)) pdMatrix(rs1)
This function is a constructor for the pdNatural
class,
representing a general positive-definite matrix, using a natural
parametrization . If the matrix associated with object
is of
dimension , it is represented by
parameters. Letting
denote the
-th
element of the underlying positive definite matrix and
denote the associated
"correlations", the "natural" parameters are given by
and
. Note that all
natural parameters are individually unrestricted, but not jointly
unrestricted (meaning that not all unrestricted vectors would give
positive-definite matrices). Therefore, this parametrization should
NOT be used for optimization. It is mostly used for deriving
approximate confidence intervals on parameters following the
optimization of an objective function. When
value
is
numeric(0)
, an uninitialized pdMat
object, a one-sided
formula, or a vector of character strings, object
is returned
as an uninitialized pdSymm
object (with just some of its
attributes and its class defined) and needs to have its coefficients
assigned later, generally using the coef
or matrix
replacement
functions. If value
is an initialized pdMat
object,
object
will be constructed from
as.matrix(value)
. Finally, if value
is a numeric
vector, it is assumed to represent the natural parameters of the
underlying positive-definite matrix.
pdNatural(value, form, nam, data)
pdNatural(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
a pdNatural
object representing a general positive-definite
matrix in natural parametrization, also inheriting from class
pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. p. 162.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
pdNatural(diag(1:3))
pdNatural(diag(1:3))
This function is a constructor for the pdSymm
class,
representing a general positive-definite matrix. If the matrix
associated with object
is of dimension , it is
represented by
unrestricted parameters,
using the matrix-logarithm parametrization described in Pinheiro and
Bates (1996). When
value
is numeric(0)
, an uninitialized
pdMat
object, a one-sided
formula, or a vector of character strings, object
is returned
as an uninitialized pdSymm
object (with just some of its
attributes and its class defined) and needs to have its coefficients
assigned later, generally using the coef
or matrix
replacement
functions. If value
is an initialized pdMat
object,
object
will be constructed from
as.matrix(value)
. Finally, if value
is a numeric vector,
it is assumed to represent the unrestricted coefficients of the
matrix-logarithm parametrization of the underlying positive-definite
matrix.
pdSymm(value, form, nam, data)
pdSymm(value, form, nam, data)
value |
an optional initialization value, which can be any of the
following: a |
form |
an optional one-sided linear formula specifying the
row/column names for the matrix represented by |
nam |
an optional vector of character strings specifying the
row/column names for the matrix represented by object. It must have
length equal to the dimension of the underlying positive-definite
matrix and unreplicated elements. This argument is ignored when
|
data |
an optional data frame in which to evaluate the variables
named in |
a pdSymm
object representing a general positive-definite
matrix, also inheriting from class pdMat
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C. and Bates., D.M. (1996) "Unconstrained Parametrizations for Variance-Covariance Matrices", Statistics and Computing, 6, 289-296.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
as.matrix.pdMat
,
coef.pdMat
,
pdClasses
,
matrix<-.pdMat
pd1 <- pdSymm(diag(1:3), nam = c("A","B","C")) pd1
pd1 <- pdSymm(diag(1:3), nam = c("A","B","C")) pd1
The Phenobarb
data frame has 744 rows and 7 columns.
This data frame contains the following columns:
an ordered factor identifying the infant.
a numeric vector giving the birth weight of the infant (kg).
an ordered factor giving the 5-minute Apgar score for the infant. This is an indication of health of the newborn infant.
a factor indicating whether the 5-minute Apgar score is < 5
or >= 5
.
a numeric vector giving the time when the sample is drawn or drug administered (hr).
a numeric vector giving the dose of drug administered
(g/kg).
a numeric vector giving the phenobarbital concentration in
the serum (g/L).
Data from a pharmacokinetics study of phenobarbital in neonatal infants. During the first few days of life the infants receive multiple doses of phenobarbital for prevention of seizures. At irregular intervals blood samples are drawn and serum phenobarbital concentrations are determined. The data were originally given in Grasela and Donn(1985) and are analyzed in Boeckmann, Sheiner and Beal (1994), in Davidian and Giltinan (1995), and in Littell et al. (1996).
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.23)
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London. (section 6.6)
Grasela and Donn (1985), Neonatal population pharmacokinetics of phenobarbital derived from routine clinical data, Developmental Pharmacology and Therapeutics, 8, 374-383.
Boeckmann, A. J., Sheiner, L. B., and Beal, S. L. (1994), NONMEM Users Guide: Part V, University of California, San Francisco.
Littell, R. C., Milliken, G. A., Stroup, W. W. and Wolfinger, R. D. (1996), SAS System for Mixed Models, SAS Institute, Cary, NC.
A model function for a model used with the Phenobarb
data.
This function uses compiled C code to improve execution speed.
phenoModel(Subject, time, dose, lCl, lV)
phenoModel(Subject, time, dose, lCl, lV)
Subject |
an integer vector of subject identifiers. These should be sorted in increasing order. |
time |
numeric. A vector of the times at which the sample was drawn or the drug administered (hr). |
dose |
numeric. A vector of doses of drug administered
( |
lCl |
numeric. A vector of values of the natural log of the
clearance parameter according to |
lV |
numeric. A vector of values of the natural log of the
effective volume of distribution according to |
See the details section of Phenobarb
for a description
of the model function that phenoModel
evaluates.
a numeric vector of predicted phenobarbital concentrations.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer. (section 6.4)
The Pixel
data frame has 102 rows and 4 columns of data on the
pixel intensities of CT scans of dogs over time
This data frame contains the following columns:
a factor with levels 1
to 10
designating the dog
on which the scan was made
a factor with levels L
and R
designating the side
of the dog being scanned
a numeric vector giving the day post injection of the contrast on which the scan was made
a numeric vector of pixel intensities
Pinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer.
fm1 <- lme(pixel ~ day + I(day^2), data = Pixel, random = list(Dog = ~ day, Side = ~ 1)) summary(fm1) VarCorr(fm1)
fm1 <- lme(pixel ~ day + I(day^2), data = Pixel, random = list(Dog = ~ day, Side = ~ 1)) summary(fm1) VarCorr(fm1)
an xyplot
of the autocorrelations versus the lags, with
type = "h"
, is produced. If alpha > 0
, curves
representing the critical limits for a two-sided test of level
alpha
for the autocorrelations are added to the plot.
## S3 method for class 'ACF' plot(x, alpha, xlab, ylab, grid, ...)
## S3 method for class 'ACF' plot(x, alpha, xlab, ylab, grid, ...)
x |
an object inheriting from class |
alpha |
an optional numeric value with the significance level for
testing if the autocorrelations are zero. Lines corresponding to the
lower and upper critical values for a test of level |
xlab , ylab
|
optional character strings with the x- and y-axis
labels. Default respectively to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the |
an xyplot
Trellis plot.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) plot(ACF(fm1, maxLag = 10), alpha = 0.01)
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) plot(ACF(fm1, maxLag = 10), alpha = 0.01)
A Trellis xyplot
of predictions versus the primary covariate is
generated, with a different panel for each value of the grouping
factor. Predicted values are joined by lines, with
different line types (colors) being used for each level of
grouping. Original observations are represented by circles.
## S3 method for class 'augPred' plot(x, key, grid, ...)
## S3 method for class 'augPred' plot(x, key, grid, ...)
x |
an object of class |
key |
an optional logical value, or list. If |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed down to the |
A Trellis plot of predictions versus the primary covariate, with panels determined by the grouping factor.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(Orthodont) plot(augPred(fm1, level = 0:1, length.out = 2))
fm1 <- lme(Orthodont) plot(augPred(fm1, level = 0:1, length.out = 2))
A Trellis dotplot
of the values being compared, with different
rows per group, is generated, with a different panel for each
coefficient. Different symbols (colors) are used for each object being
compared.
## S3 method for class 'compareFits' plot(x, subset, key, mark, ...)
## S3 method for class 'compareFits' plot(x, subset, key, mark, ...)
x |
an object of class |
subset |
an optional logical or integer vector specifying which
rows of |
key |
an optional logical value, or list. If |
mark |
an optional numeric vector, of length equal to the number of coefficients being compared, indicating where vertical lines should be drawn in the plots. If missing, no lines are drawn. |
... |
optional arguments passed down to the |
A Trellis dotplot
of the values being compared, with rows
determined by the groups and panels by the coefficients.
José Pinheiro and Douglas Bates [email protected]
compareFits
, pairs.compareFits
,
dotplot
example(compareFits) # cF12 <- compareFits(coef(lmList(Orthodont)), .. lme(*)) plot(cF12)
example(compareFits) # cF12 <- compareFits(coef(lmList(Orthodont)), .. lme(*)) plot(cF12)
Diagnostic plots for the linear model fit are obtained. The
form
argument gives considerable flexibility in the type of
plot specification. A conditioning expression (on the right side of a
|
operator) always implies that different panels are used for
each level of the conditioning factor, according to a Trellis
display. If form
is a one-sided formula, histograms of the
variable on the right hand side of the formula, before a |
operator, are displayed (the Trellis function histogram
is
used). If form
is two-sided and both its left and
right hand side variables are numeric, scatter plots are displayed
(the Trellis function xyplot
is used). Finally, if form
is two-sided and its left had side variable is a factor, box-plots of
the right hand side variable by the levels of the left hand side
variable are displayed (the Trellis function bwplot
is used).
## S3 method for class 'gls' plot(x, form, abline, id, idLabels, idResType, grid, ...)
## S3 method for class 'gls' plot(x, form, abline, id, idLabels, idResType, grid, ...)
x |
an object inheriting from class |
form |
an optional formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
abline |
an optional numeric value, or numeric vector of length two. If given as a single value, a horizontal line will be added to the plot at that coordinate; else, if given as a vector, its values are used as the intercept and slope for a line added to the plot. If missing, no lines are added to the plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for a two-sided outlier
test for the standardized residuals. Observations with
absolute standardized residuals greater than the |
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character mode and used to label the
observations identified according to |
idResType |
an optional character string specifying the type of
residuals to be used in identifying outliers, when |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default depends on the type of Trellis plot used:
if |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot.
José Pinheiro and Douglas Bates [email protected]
gls
, xyplot
,
bwplot
, histogram
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) # standardized residuals versus fitted values by Mare plot(fm1, resid(., type = "p") ~ fitted(.) | Mare, abline = 0) # box-plots of residuals by Mare plot(fm1, Mare ~ resid(.)) # observed versus fitted values by Mare plot(fm1, follicles ~ fitted(.) | Mare, abline = c(0,1))
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) # standardized residuals versus fitted values by Mare plot(fm1, resid(., type = "p") ~ fitted(.) | Mare, abline = 0) # box-plots of residuals by Mare plot(fm1, Mare ~ resid(.)) # observed versus fitted values by Mare plot(fm1, follicles ~ fitted(.) | Mare, abline = c(0,1))
A Trellis dot-plot of the confidence intervals on the linear model
coefficients is generated, with a different panel for each
coefficient. Rows in the dot-plot correspond to the names of the
lm
components of the lmList
object used to produce
x
. The lower and upper confidence limits are connected by
a line segment and the estimated coefficients are marked with a
"+"
.
This is based on function dotplot()
from
package lattice.
## S3 method for class 'intervals.lmList' plot(x, xlab = "", ylab = attr(x, "groupsName"), strip = function(...) strip.default(..., style = 1), ...)
## S3 method for class 'intervals.lmList' plot(x, xlab = "", ylab = attr(x, "groupsName"), strip = function(...) strip.default(..., style = 1), ...)
x |
an object inheriting from class |
xlab , ylab
|
axis labels, each with a sensible default. |
strip |
|
... |
optional arguments passed to the |
a Trellis plot with the confidence intervals on the coefficients of
the individual lm
components of the lmList
that
generated x
.
José Pinheiro and Douglas Bates [email protected]
intervals.lmList
,
lmList
,
dotplot
fm1 <- lmList(distance ~ age | Subject, Orthodont) plot(intervals(fm1))
fm1 <- lmList(distance ~ age | Subject, Orthodont) plot(intervals(fm1))
Diagnostic plots for the linear mixed-effects fit are obtained. The
form
argument gives considerable flexibility in the type of
plot specification. A conditioning expression (on the right side of a
|
operator) always implies that different panels are used for
each level of the conditioning factor, according to a Trellis
display. If form
is a one-sided formula, histograms of the
variable on the right hand side of the formula, before a |
operator, are displayed (the Trellis function histogram
is
used). If form
is two-sided and both its left and
right hand side variables are numeric, scatter plots are displayed
(the Trellis function xyplot
is used). Finally, if form
is two-sided and its left had side variable is a factor, box-plots of
the right hand side variable by the levels of the left hand side
variable are displayed (the Trellis function bwplot
is used).
## S3 method for class 'lme' plot(x, form, abline, id, idLabels, idResType, grid, ...) ## S3 method for class 'nls' plot(x, form, abline, id, idLabels, idResType, grid, ...)
## S3 method for class 'lme' plot(x, form, abline, id, idLabels, idResType, grid, ...) ## S3 method for class 'nls' plot(x, form, abline, id, idLabels, idResType, grid, ...)
x |
an object inheriting from class |
form |
an optional formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
abline |
an optional numeric value, or numeric vector of length two. If given as a single value, a horizontal line will be added to the plot at that coordinate; else, if given as a vector, its values are used as the intercept and slope for a line added to the plot. If missing, no lines are added to the plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for a two-sided outlier
test for the standardized, or normalized residuals. Observations with
absolute standardized (normalized) residuals greater than the |
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
observations identified according to |
idResType |
an optional character string specifying the type of
residuals to be used in identifying outliers, when |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default depends on the type of Trellis plot used:
if |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot.
José Pinheiro and Douglas Bates [email protected]
lme
, xyplot
,
bwplot
, histogram
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) # standardized residuals versus fitted values by gender plot(fm1, resid(., type = "p") ~ fitted(.) | Sex, abline = 0) # box-plots of residuals by Subject plot(fm1, Subject ~ resid(.)) # observed versus fitted values by Subject plot(fm1, distance ~ fitted(.) | Subject, abline = c(0,1))
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) # standardized residuals versus fitted values by gender plot(fm1, resid(., type = "p") ~ fitted(.) | Sex, abline = 0) # box-plots of residuals by Subject plot(fm1, Subject ~ resid(.)) # observed versus fitted values by Subject plot(fm1, distance ~ fitted(.) | Subject, abline = c(0,1))
Diagnostic plots for the linear model fits corresponding to the
x
components are obtained. The form
argument gives
considerable flexibility in the type of plot specification. A
conditioning expression (on the right side of a |
operator)
always implies that different panels are used for each level of the
conditioning factor, according to a Trellis display. If form
is a one-sided formula, histograms of the variable on the right hand
side of the formula, before a |
operator, are displayed (the
Trellis function histogram
is used). If form
is
two-sided and both its left and right hand side variables are
numeric, scatter plots are displayed (the Trellis function
xyplot
is used). Finally, if form
is two-sided and its
left had side variable is a factor, box-plots of the right hand side
variable by the levels of the left hand side variable are displayed
(the Trellis function bwplot
is used).
## S3 method for class 'lmList' plot(x, form, abline, id, idLabels, grid, ...)
## S3 method for class 'lmList' plot(x, form, abline, id, idLabels, grid, ...)
x |
an object inheriting from class |
form |
an optional formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
abline |
an optional numeric value, or numeric vector of length two. If given as a single value, a horizontal line will be added to the plot at that coordinate; else, if given as a vector, its values are used as the intercept and slope for a line added to the plot. If missing, no lines are added to the plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for a two-sided outlier
test for the standardized residuals. Observations with
absolute standardized residuals greater than the |
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
observations identified according to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default depends on the type of Trellis plot used:
if |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot.
José Pinheiro and Douglas Bates [email protected]
lmList
,predict.lm
,
xyplot
, bwplot
, histogram
fm1 <- lmList(distance ~ age | Subject, Orthodont) # standardized residuals versus fitted values by gender plot(fm1, resid(., type = "pool") ~ fitted(.) | Sex, abline = 0, id = 0.05) # box-plots of residuals by Subject plot(fm1, Subject ~ resid(.)) # observed versus fitted values by Subject plot(fm1, distance ~ fitted(.) | Subject, abline = c(0,1))
fm1 <- lmList(distance ~ age | Subject, Orthodont) # standardized residuals versus fitted values by gender plot(fm1, resid(., type = "pool") ~ fitted(.) | Sex, abline = 0, id = 0.05) # box-plots of residuals by Subject plot(fm1, Subject ~ resid(.)) # observed versus fitted values by Subject plot(fm1, distance ~ fitted(.) | Subject, abline = c(0,1))
A Trellis dot-plot of the response by group is generated. If outer
variables are specified, the combination of their levels are used to
determine the panels of the Trellis display. The Trellis function
dotplot
is used.
## S3 method for class 'nffGroupedData' plot(x, outer, inner, innerGroups, xlab, ylab, strip, panel, key, grid, ...)
## S3 method for class 'nffGroupedData' plot(x, outer, inner, innerGroups, xlab, ylab, strip, panel, key, grid, ...)
x |
an object inheriting from class |
outer |
an optional logical value or one-sided formula,
indicating covariates that are outer to the grouping factor, which
are used to determine the panels of the Trellis plot. If
equal to |
inner |
an optional logical value or one-sided formula, indicating
a covariate that is inner to the grouping factor, which is used to
associate points within each panel of the Trellis plot. If
equal to |
innerGroups |
an optional one-sided formula specifying a factor
to be used for grouping the levels of the |
xlab |
an optional character string with the label for the
horizontal axis. Default is the |
ylab |
an optional character string with the label for the vertical axis. Default is the grouping factor name. |
strip |
an optional function passed as the |
panel |
an optional function used to generate the individual
panels in the Trellis display, passed as the |
key |
an optional logical function or function. If |
grid |
this argument is included for consistency with the
|
... |
optional arguments passed to the |
a Trellis dot-plot of the response by group.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1997), "Software Design for Longitudinal Data", in "Modelling Longitudinal and Spatially Correlated Data: Methods, Applications and Future Directions", T.G. Gregoire (ed.), Springer-Verlag, New York.
plot(Machines) plot(Machines, inner = TRUE)
plot(Machines) plot(Machines, inner = TRUE)
A Trellis plot of the response versus the primary covariate is
generated. If outer variables are specified, the combination of their
levels are used to determine the panels of the Trellis
display. Otherwise, the levels of the grouping variable determine the
panels. A scatter plot of the response versus the primary covariate is
displayed in each panel, with observations corresponding to same
inner group joined by line segments. The Trellis function
xyplot
is used.
## S3 method for class 'nfnGroupedData' plot(x, outer, inner, innerGroups, xlab, ylab, strip, aspect, panel, key, grid, ...)
## S3 method for class 'nfnGroupedData' plot(x, outer, inner, innerGroups, xlab, ylab, strip, aspect, panel, key, grid, ...)
x |
an object inheriting from class |
outer |
an optional logical value or one-sided formula,
indicating covariates that are outer to the grouping factor, which
are used to determine the panels of the Trellis plot. If
equal to |
inner |
an optional logical value or one-sided formula, indicating
a covariate that is inner to the grouping factor, which is used to
associate points within each panel of the Trellis plot. If
equal to |
innerGroups |
an optional one-sided formula specifying a factor
to be used for grouping the levels of the |
xlab , ylab
|
optional character strings with the labels for the
plot. Default is the corresponding elements of |
strip |
an optional function passed as the |
aspect |
an optional character string indicating the aspect ratio
for the plot passed as the |
panel |
an optional function used to generate the individual
panels in the Trellis display, passed as the |
key |
an optional logical function or function. If |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the |
a Trellis plot of the response versus the primary covariate.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1997), "Software Design for Longitudinal Data", in "Modelling Longitudinal and Spatially Correlated Data: Methods, Applications and Future Directions", T.G. Gregoire (ed.), Springer-Verlag, New York.
# different panels per Subject plot(Orthodont) # different panels per gender plot(Orthodont, outer = TRUE)
# different panels per Subject plot(Orthodont) # different panels per gender plot(Orthodont, outer = TRUE)
The groupedData
object is summarized by the values of the
displayLevel
grouping factor (or the combination of its values
and the values of the covariate indicated in preserve
, if any is
present). The collapsed data is used to produce a new
groupedData
object, with grouping factor given by the
displayLevel
factor, which is plotted using the
appropriate plot
method for groupedData
objects with
single level of grouping.
## S3 method for class 'nmGroupedData' plot(x, collapseLevel, displayLevel, outer, inner, preserve, FUN, subset, key, grid, ...)
## S3 method for class 'nmGroupedData' plot(x, collapseLevel, displayLevel, outer, inner, preserve, FUN, subset, key, grid, ...)
x |
an object inheriting from class |
collapseLevel |
an optional positive integer or character string indicating the grouping level to use when collapsing the data. Level values increase from outermost to innermost grouping. Default is the highest or innermost level of grouping. |
displayLevel |
an optional positive integer or character string
indicating the grouping level to use for determining the panels in
the Trellis display, when |
outer |
an optional logical value or one-sided formula,
indicating covariates that are outer to the |
inner |
an optional logical value or one-sided formula, indicating
a covariate that is inner to the |
preserve |
an optional one-sided formula indicating a covariate
whose levels should be preserved when collapsing the data according
to the |
FUN |
an optional summary function or a list of summary functions
to be used for collapsing the data. The function or functions are
applied only to variables in |
subset |
an optional named list. Names can be either positive
integers representing grouping levels, or names of grouping
factors. Each element in the list is a vector indicating the levels
of the corresponding grouping factor to be used for plotting the
data. Default is |
key |
an optional logical value, or list. If |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the Trellis plot function. |
a Trellis display of the data collapsed over the values of the
collapseLevel
grouping factor and grouped according to the
displayLevel
grouping factor.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1997), "Software Design for Longitudinal Data", in "Modelling Longitudinal and Spatially Correlated Data: Methods, Applications and Future Directions", T.G. Gregoire (ed.), Springer-Verlag, New York.
groupedData
, collapse.groupedData
,
plot.nfnGroupedData
, plot.nffGroupedData
# no collapsing, panels by Dog plot(Pixel, displayLevel = "Dog", inner = ~Side) # collapsing by Dog, preserving day plot(Pixel, collapseLevel = "Dog", preserve = ~day)
# no collapsing, panels by Dog plot(Pixel, displayLevel = "Dog", inner = ~Side) # collapsing by Dog, preserving day plot(Pixel, collapseLevel = "Dog", preserve = ~day)
Plots (class "Trellis"
from package lattice) of the
random effects from linear mixed effects model, i.e., the result of
ranef(lme(*))
(of class "ranef.lme"
).
## S3 method for class 'ranef.lme' plot(x, form = NULL, omitFixed = TRUE, level = Q, grid = TRUE, control, xlab, ylab, strip, ...)
## S3 method for class 'ranef.lme' plot(x, form = NULL, omitFixed = TRUE, level = Q, grid = TRUE, control, xlab, ylab, strip, ...)
x |
an object inheriting from class
|
form |
an optional formula specifying the desired type of plot.
See also ‘Details:’. |
omitFixed |
an optional logical value indicating whether
columns with values that are constant across groups should be
omitted. Default is |
level |
an optional integer value giving the level of grouping
to be used for |
grid |
an optional logical value indicating whether a grid should
be added to plot. Only applies to plots associated with two-sided
formulas in |
control |
an optional list with control values for the
plot, when |
xlab , ylab
|
axis labels, each with a sensible default. |
strip |
|
... |
optional arguments passed to the Trellis |
If form
is missing, or is given as a one-sided formula, a
Trellis dot-plot (via dotplot()
from pkg
lattice) of the random effects is generated, with a different
panel for each random effect (coefficient). Rows in the dot-plot are
determined by the form
argument (if not missing) or by the row
names of the random effects (coefficients). Single factors (~g
)
or crossed factors (~g1*g2
) are allowed. For a single factor,
its levels determine the dot-plot rows (with possibly multiple dots
per row); otherwise, if form
specifies a crossing of factors, the dot-plot rows are determined by
all combinations of the levels of the individual factors in the
formula.
If form
is a two-sided formula, the left hand side must
be a single random effect (coefficient) and the right hand side is
formed by covariates in x
separated by +
.
An xyplot()
Trellis display is generated,
with a different panel for each variable listed in the right hand side
of form
. Scatter plots are generated for numeric variables and
boxplots are generated for categorical (factor
or
ordered
) variables.
a Trellis plot of the estimated random-effects (coefficients) versus covariates, or groups.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) plot(ranef(fm1)) fm1RE <- ranef(fm1, augFrame = TRUE) plot(fm1RE, form = ~ Sex) plot(fm1RE, form = age ~ Sex) # "connected" boxplots
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) plot(ranef(fm1)) fm1RE <- ranef(fm1, augFrame = TRUE) plot(fm1RE, form = ~ Sex) plot(fm1RE, form = age ~ Sex) # "connected" boxplots
If form
is missing, or is given as a one-sided formula, a
Trellis dot-plot of the random effects is generated, with a different
panel for each random effect (coefficient). Rows in the dot-plot are
determined by the form
argument (if not missing) or by the row
names of the random effects (coefficients). If a single factor is
specified in form
, its levels determine the dot-plot rows
(with possibly multiple dots per row); otherwise, if form
specifies a crossing of factors, the dot-plot rows are determined by
all combinations of the levels of the individual factors in the
formula. The Trellis function dotplot
is used in this method
function.
If form
is a two-sided formula, a Trellis display is generated,
with a different panel for each variable listed in the right hand side
of form
. Scatter plots are generated for numeric variables and
boxplots are generated for categorical (factor
or
ordered
) variables.
## S3 method for class 'ranef.lmList' plot(x, form, grid, control, ...)
## S3 method for class 'ranef.lmList' plot(x, form, grid, control, ...)
x |
an object inheriting from class
|
form |
an optional formula specifying the desired type of plot. If
given as a one-sided formula, a |
grid |
an optional logical value indicating whether a grid should
be added to plot. Only applies to plots associated with two-sided
formulas in |
control |
an optional list with control values for the
plot, when |
... |
optional arguments passed to the Trellis |
a Trellis plot of the estimated random-effects (coefficients) versus covariates, or groups.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) plot(ranef(fm1)) fm1RE <- ranef(fm1, augFrame = TRUE) plot(fm1RE, form = ~ Sex) plot(fm1RE, form = age ~ Sex)
fm1 <- lmList(distance ~ age | Subject, Orthodont) plot(ranef(fm1)) fm1RE <- ranef(fm1, augFrame = TRUE) plot(fm1RE, form = ~ Sex) plot(fm1RE, form = age ~ Sex)
an xyplot
of the semi-variogram versus the distances is
produced. If smooth = TRUE
, a loess
smoother is added to
the plot. If showModel = TRUE
and x
includes an
"modelVariog"
attribute, the corresponding semi-variogram
is added to the plot.
## S3 method for class 'Variogram' plot(x, smooth, showModel, sigma, span, xlab, ylab, type, ylim, grid, ...)
## S3 method for class 'Variogram' plot(x, smooth, showModel, sigma, span, xlab, ylab, type, ylim, grid, ...)
x |
an object inheriting from class |
smooth |
an optional logical value controlling whether a
|
showModel |
an optional logical value controlling whether the
semi-variogram corresponding to an |
sigma |
an optional numeric value used as the height of a
horizontal line displayed in the plot. Can be used to represent the
process standard deviation. Default is |
span |
an optional numeric value with the smoothing parameter for
the |
xlab , ylab
|
optional character strings with the x- and y-axis
labels. Default respectively to |
type |
an optional character indicating the type of plot. Defaults
to |
ylim |
an optional numeric vector with the limits for the
y-axis. Defaults to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the Trellis |
an xyplot
Trellis plot.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) plot(Variogram(fm1, form = ~ Time | Mare, maxDist = 0.7))
fm1 <- lme(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary) plot(Variogram(fm1, form = ~ Time | Mare, maxDist = 0.7))
The pooled estimated standard deviation is obtained by adding together
the residual sum of squares for each non-null element of
object
, dividing by the sum of the corresponding residual
degrees-of-freedom, and taking the square-root.
pooledSD(object)
pooledSD(object)
object |
an object inheriting from class |
the pooled standard deviation for the non-null elements of
object
, with an attribute df
with the number of
degrees-of-freedom used in the estimation.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(Orthodont) pooledSD(fm1)
fm1 <- lmList(Orthodont) pooledSD(fm1)
The predictions for the linear model represented by object
are
obtained at the covariate values defined in newdata
.
## S3 method for class 'gls' predict(object, newdata, na.action, ...)
## S3 method for class 'gls' predict(object, newdata, na.action, ...)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the predictions. All variables used in the linear model must be present in the data frame. If missing, the fitted values are returned. |
na.action |
a function that indicates what should happen when
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the predicted values.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) newOvary <- data.frame(Time = c(-0.75, -0.5, 0, 0.5, 0.75)) predict(fm1, newOvary)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) newOvary <- data.frame(Time = c(-0.75, -0.5, 0, 0.5, 0.75)) predict(fm1, newOvary)
The predictions for the nonlinear model represented by object
are
obtained at the covariate values defined in newdata
.
## S3 method for class 'gnls' predict(object, newdata, na.action, naPattern, ...)
## S3 method for class 'gnls' predict(object, newdata, na.action, naPattern, ...)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the predictions. All variables used in the nonlinear model must be present in the data frame. If missing, the fitted values are returned. |
na.action |
a function that indicates what should happen when
|
naPattern |
an expression or formula object, specifying which returned values are to be regarded as missing. |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the predicted values.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) newSoybean <- data.frame(Time = c(10,30,50,80,100)) predict(fm1, newSoybean)
fm1 <- gnls(weight ~ SSlogis(Time, Asym, xmid, scal), Soybean, weights = varPower()) newSoybean <- data.frame(Time = c(10,30,50,80,100)) predict(fm1, newSoybean)
The predictions at level are obtained by adding together the
population predictions (based only on the fixed effects estimates)
and the estimated contributions of the random effects to the
predictions at grouping levels less or equal to
. The resulting
values estimate the best linear unbiased predictions (BLUPs) at level
. If group values not included in the original grouping factors
are present in
newdata
, the corresponding predictions will be
set to NA
for levels greater or equal to the level at which the
unknown groups occur.
## S3 method for class 'lme' predict(object, newdata, level = Q, asList = FALSE, na.action = na.fail, ...)
## S3 method for class 'lme' predict(object, newdata, level = Q, asList = FALSE, na.action = na.fail, ...)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the predictions. All variables used in the fixed and random effects models, as well as the grouping factors, must be present in the data frame. If missing, the fitted values are returned. |
level |
an optional integer vector giving the level(s) of grouping to be used in obtaining the predictions. Level values increase from outermost to innermost grouping, with level zero corresponding to the population predictions. Defaults to the highest or innermost level of grouping. |
asList |
an optional logical value. If |
na.action |
a function that indicates what should happen when
|
... |
some methods for this generic require additional arguments. None are used in this method. |
if a single level of grouping is specified in level
, the
returned value is either a list with the predictions split by groups
(asList = TRUE
) or a vector with the predictions
(asList = FALSE
); else, when multiple grouping levels are
specified in level
, the returned object is a data frame with
columns given by the predictions at different levels and the grouping
factors.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) newOrth <- data.frame(Sex = c("Male","Male","Female","Female","Male","Male"), age = c(15, 20, 10, 12, 2, 4), Subject = c("M01","M01","F30","F30","M04","M04")) ## The 'Orthodont' data has *no* 'F30', so predict NA at level 1 : predict(fm1, newOrth, level = 0:1)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) newOrth <- data.frame(Sex = c("Male","Male","Female","Female","Male","Male"), age = c(15, 20, 10, 12, 2, 4), Subject = c("M01","M01","F30","F30","M04","M04")) ## The 'Orthodont' data has *no* 'F30', so predict NA at level 1 : predict(fm1, newOrth, level = 0:1)
If the grouping factor corresponding to object
is included
in newdata
, the data frame is partitioned according to the
grouping factor levels; else, newdata
is repeated for all
lm
components. The predictions and, optionally, the standard
errors for the predictions, are obtained for each lm
component of object
, using the corresponding element of the
partitioned newdata
, and arranged into a list with as many
components as object
, or combined into a single vector or data
frame (if se.fit=TRUE
).
## S3 method for class 'lmList' predict(object, newdata, subset, pool, asList, se.fit, ...)
## S3 method for class 'lmList' predict(object, newdata, subset, pool, asList, se.fit, ...)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the
predictions. All variables used in the |
subset |
an optional character or integer vector naming the
|
asList |
an optional logical value. If |
pool |
an optional logical value indicating whether a pooled
estimate of the residual standard error should be used. Default is
|
se.fit |
an optional logical value indicating whether pointwise
standard errors should be computed along with the
predictions. Default is |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by the predictions (and, optionally, the
standard errors for the predictions) from each lm
component of object
, a vector with the predictions from all
lm
components of object
, or a data frame with columns
given by the predictions and their corresponding standard errors.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) predict(fm1, se.fit = TRUE)
fm1 <- lmList(distance ~ age | Subject, Orthodont) predict(fm1, se.fit = TRUE)
The predictions at level are obtained by adding together the
contributions from the estimated fixed effects and the estimated
random effects at levels less or equal to
and evaluating the
model function at the resulting estimated parameters. If group values
not included in the original grouping factors are present in
newdata
, the corresponding predictions will be set to
NA
for levels greater or equal to the level at which the
unknown groups occur.
## S3 method for class 'nlme' predict(object, newdata, level = Q, asList = FALSE, na.action = na.fail, naPattern = NULL, ...)
## S3 method for class 'nlme' predict(object, newdata, level = Q, asList = FALSE, na.action = na.fail, naPattern = NULL, ...)
object |
an object inheriting from class |
newdata |
an optional data frame to be used for obtaining the predictions. All variables used in the nonlinear model, the fixed and the random effects models, as well as the grouping factors, must be present in the data frame. If missing, the fitted values are returned. |
level |
an optional integer vector giving the level(s) of grouping
to be used in obtaining the predictions. Level values increase from
outermost to innermost grouping, with level zero corresponding to the
population predictions. Defaults to the highest or innermost level of
grouping (and is |
asList |
an optional logical value. If |
na.action |
a function that indicates what should happen when
|
naPattern |
an expression or formula object, specifying which returned values are to be regarded as missing. |
... |
some methods for this generic require additional arguments. None are used in this method. |
if a single level of grouping is specified in level
, the
returned value is either a list with the predictions split by groups
(asList = TRUE
) or a vector with the predictions
(asList = FALSE
); else, when multiple grouping levels are
specified in level
, the returned object is a data frame with
columns given by the predictions at different levels and the grouping
factors.
José Pinheiro and Douglas Bates [email protected]
head(Loblolly) # groupedData w/ 'Seed' is grouping variable : ## Grouped Data: height ~ age | Seed ## height age Seed ## 1 4.51 3 301 ## 15 10.89 5 301 ## .. ..... . ... fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly, fixed = Asym + R0 + lrc ~ 1, random = Asym ~ 1, ## <---grouping---> Asym ~ 1 | Seed start = c(Asym = 103, R0 = -8.5, lrc = -3.3)) fm1 age. <- seq(from = 2, to = 30, by = 2) newLL.301 <- data.frame(age = age., Seed = 301) newLL.329 <- data.frame(age = age., Seed = 329) (p301 <- predict(fm1, newLL.301, level = 0:1)) (p329 <- predict(fm1, newLL.329, level = 0:1)) ## Prediction are the same at level 0 : all.equal(p301[,"predict.fixed"], p329[,"predict.fixed"]) ## and differ by the 'Seed' effect at level 1 : p301[,"predict.Seed"] - p329[,"predict.Seed"]
head(Loblolly) # groupedData w/ 'Seed' is grouping variable : ## Grouped Data: height ~ age | Seed ## height age Seed ## 1 4.51 3 301 ## 15 10.89 5 301 ## .. ..... . ... fm1 <- nlme(height ~ SSasymp(age, Asym, R0, lrc), data = Loblolly, fixed = Asym + R0 + lrc ~ 1, random = Asym ~ 1, ## <---grouping---> Asym ~ 1 | Seed start = c(Asym = 103, R0 = -8.5, lrc = -3.3)) fm1 age. <- seq(from = 2, to = 30, by = 2) newLL.301 <- data.frame(age = age., Seed = 301) newLL.329 <- data.frame(age = age., Seed = 329) (p301 <- predict(fm1, newLL.301, level = 0:1)) (p329 <- predict(fm1, newLL.329, level = 0:1)) ## Prediction are the same at level 0 : all.equal(p301[,"predict.fixed"], p329[,"predict.fixed"]) ## and differ by the 'Seed' effect at level 1 : p301[,"predict.Seed"] - p329[,"predict.Seed"]
The standard deviations and correlations associated with the
positive-definite matrix represented by object
(considered as a
variance-covariance matrix) are printed, together with the formula and
the grouping level associated object
, if any are present.
## S3 method for class 'summary.pdMat' print(x, sigma, rdig, Level, resid, ...)
## S3 method for class 'summary.pdMat' print(x, sigma, rdig, Level, resid, ...)
x |
an object inheriting from class |
sigma |
an optional numeric value used as a multiplier for
the square-root factor of the positive-definite matrix represented by
|
rdig |
an optional integer value with the number of significant digits to be used in printing correlations. Defaults to 3. |
Level |
an optional character string with a description of the
grouping level associated with |
resid |
an optional logical value. If |
... |
optional arguments passed to |
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdCompSymm(3 * diag(2) + 1, form = ~age + age^2, data = Orthodont) print(summary(pd1), sigma = 1.2, resid = TRUE)
pd1 <- pdCompSymm(3 * diag(2) + 1, form = ~age + age^2, data = Orthodont) print(summary(pd1), sigma = 1.2, resid = TRUE)
The class and the coefficients associated with x
are printed.
## S3 method for class 'varFunc' print(x, ...)
## S3 method for class 'varFunc' print(x, ...)
x |
an object inheriting from class |
... |
optional arguments passed to |
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(0.3, form = ~age) vf1 <- Initialize(vf1, Orthodont) print(vf1)
vf1 <- varPower(0.3, form = ~age) vf1 <- Initialize(vf1, Orthodont) print(vf1)
Diagnostic plots for assessing the normality of residuals the
generalized least squares fit are obtained. The form
argument
gives considerable flexibility in the type of plot specification. A
conditioning expression (on the right side of a |
operator)
always implies that different panels are used for each level of the
conditioning factor, according to a Trellis display.
## S3 method for class 'gls' qqnorm(y, form, abline, id, idLabels, grid, ...)
## S3 method for class 'gls' qqnorm(y, form, abline, id, idLabels, grid, ...)
y |
an object inheriting from class |
form |
an optional one-sided formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
abline |
an optional numeric value, or numeric vector of length two. If given as a single value, a horizontal line will be added to the plot at that coordinate; else, if given as a vector, its values are used as the intercept and slope for a line added to the plot. If missing, no lines are added to the plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for a two-sided outlier
test for the standardized residuals (random effects). Observations with
absolute standardized residuals (random effects) greater than the
|
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
observations identified according to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default depends on the type of Trellis plot used:
if |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot for assessing normality of residuals.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) qqnorm(fm1, abline = c(0,1))
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) qqnorm(fm1, abline = c(0,1))
Diagnostic plots for assessing the normality of residuals and random
effects in the linear mixed-effects fit are obtained. The
form
argument gives considerable flexibility in the type of
plot specification. A conditioning expression (on the right side of a
|
operator) always implies that different panels are used for
each level of the conditioning factor, according to a Trellis
display.
## S3 method for class 'lme' qqnorm(y, form, abline, id, idLabels, grid, ...)
## S3 method for class 'lme' qqnorm(y, form, abline, id, idLabels, grid, ...)
y |
an object inheriting from class |
form |
an optional one-sided formula specifying the desired type of
plot. Any variable present in the original data frame used to obtain
|
abline |
an optional numeric value, or numeric vector of length two. If given as a single value, a horizontal line will be added to the plot at that coordinate; else, if given as a vector, its values are used as the intercept and slope for a line added to the plot. If missing, no lines are added to the plot. |
id |
an optional numeric value, or one-sided formula. If given as
a value, it is used as a significance level for a two-sided outlier
test for the standardized residuals (random effects). Observations with
absolute standardized residuals (random effects) greater than the
|
idLabels |
an optional vector, or one-sided formula. If given as a
vector, it is converted to character and used to label the
observations identified according to |
grid |
an optional logical value indicating whether a grid should
be added to plot. Default is |
... |
optional arguments passed to the Trellis plot function. |
a diagnostic Trellis plot for assessing normality of residuals or random effects.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) ## normal plot of standardized residuals by gender qqnorm(fm1, ~ resid(., type = "p") | Sex, abline = c(0, 1)) ## normal plots of random effects qqnorm(fm1, ~ranef(.))
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) ## normal plot of standardized residuals by gender qqnorm(fm1, ~ resid(., type = "p") | Sex, abline = c(0, 1)) ## normal plots of random effects qqnorm(fm1, ~ranef(.))
The Quinidine
data frame has 1471 rows and 14 columns.
This data frame contains the following columns:
a factor identifying the patient on whom the data were collected.
a numeric vector giving the time (hr) at which the drug was administered or the blood sample drawn. This is measured from the time the patient entered the study.
a numeric vector giving the serum quinidine concentration (mg/L).
a numeric vector giving the dose of drug administered (mg). Although there were two different forms of quinidine administered, the doses were adjusted for differences in salt content by conversion to milligrams of quinidine base.
a numeric vector giving the when the drug has been given at regular intervals for a sufficiently long period of time to assume steady state behavior, the interval is recorded.
a numeric vector giving the age of the subject on entry to the study (yr).
a numeric vector giving the height of the subject on entry to the study (in.).
a numeric vector giving the body weight of the subject (kg).
a factor with levels
Caucasian
,
Latin
, and
Black
identifying the race of the subject.
a factor with levels
no
and
yes
giving smoking status at the time of the
measurement.
a factor with levels
none
,
current
,
former
giving ethanol (alcohol) abuse status at the
time of the measurement.
a factor with levels
No/Mild
,
Moderate
, and
Severe
indicating congestive heart failure for the subject.
an ordered factor with levels
< 50
< >= 50
indicating the creatinine clearance (mg/min).
a numeric vector giving the alpha-1 acid glycoprotein concentration (mg/dL). Often measured at the same time as the quinidine concentration.
Verme et al. (1992) analyze routine clinical data on patients receiving the drug quinidine as a treatment for cardiac arrhythmia (atrial fibrillation or ventricular arrhythmias). All patients were receiving oral quinidine doses. At irregular intervals blood samples were drawn and serum concentrations of quinidine were determined. These data are analyzed in several publications, including Davidian and Giltinan (1995, section 9.3).
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.25)
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London.
Verme, C. N., Ludden, T. M., Clementi, W. A. and Harris, S. C. (1992), Pharmacokinetics of quinidine in male patients: A population analysis, Clinical Pharmacokinetics, 22, 468-480.
A model function for a model used with the Quinidine
data.
This function calls compiled C code.
quinModel(Subject, time, conc, dose, interval, lV, lKa, lCl)
quinModel(Subject, time, conc, dose, interval, lV, lKa, lCl)
Subject |
a factor identifying the patient on whom the data were collected. |
time |
a numeric vector giving the time (hr) at which the drug was administered or the blood sample drawn. This is measured from the time the patient entered the study. |
conc |
a numeric vector giving the serum quinidine concentration (mg/L). |
dose |
a numeric vector giving the dose of drug administered (mg). Although there were two different forms of quinidine administered, the doses were adjusted for differences in salt content by conversion to milligrams of quinidine base. |
interval |
a numeric vector giving the when the drug has been given at regular intervals for a sufficiently long period of time to assume steady state behavior, the interval is recorded. |
lV |
numeric. A vector of values of the natural log of the
effective volume of distribution according to |
lKa |
numeric. A vector of values of the natural log of the
absorption rate constant according to |
lCl |
numeric. A vector of values of the natural log of the
clearance parameter according to |
See the details section of Quinidine
for a description
of the model function that quinModel
evaluates.
a numeric vector of predicted quinidine concentrations.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J. C. and Bates, D. M. (2000) Mixed-effects Models in S and S-PLUS, Springer. (section 8.2)
The Rail
data frame has 18 rows and 2 columns.
This data frame contains the following columns:
an ordered factor identifying the rail on which the measurement was made.
a numeric vector giving the travel time for ultrasonic head-waves in the rail (nanoseconds). The value given is the original travel time minus 36,100 nanoseconds.
Devore (2000, Example 10.10, p. 427) cites data from an article in Materials Evaluation on “a study of travel time for a certain type of wave that results from longitudinal stress of rails used for railroad track.”
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.26)
Devore, J. L. (2000), Probability and Statistics for Engineering and the Sciences (5th ed), Duxbury, Boston, MA.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include lmList
and lme
.
random.effects(object, ...) ranef(object, ...)
random.effects(object, ...) ranef(object, ...)
object |
any fitted model object from which random effects estimates can be extracted. |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
## see the method function documentation
## see the method function documentation
The estimated random effects at level are represented as a
data frame with rows given by the different groups at that level and
columns given by the random effects. If a single level of
grouping is specified, the returned object is a data frame; else, the
returned object is a list of such data frames. Optionally, the
returned data frame(s) may be augmented with covariates summarized
over groups.
## S3 method for class 'lme' ranef(object, augFrame, level, data, which, FUN, standard, omitGroupingFactor, subset, ...)
## S3 method for class 'lme' ranef(object, augFrame, level, data, which, FUN, standard, omitGroupingFactor, subset, ...)
object |
an object inheriting from class |
augFrame |
an optional logical value. If |
level |
an optional vector of positive integers giving the levels of grouping to be used in extracting the random effects from an object with multiple nested grouping levels. Defaults to all levels of grouping. |
data |
an optional data frame with the variables to be used for
augmenting the returned data frame when |
which |
an optional positive integer vector specifying which
columns of |
FUN |
an optional summary function or a list of summary functions
to be applied to group-varying variables, when collapsing |
standard |
an optional logical value indicating whether the
estimated random effects should be "standardized" (i.e. divided by
the estimate of the standard deviation of that group of random
effects). Defaults to |
omitGroupingFactor |
an optional logical value. When |
subset |
an optional expression indicating for which rows the random effects should be extracted. |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame, or list of data frames, with the estimated
random effects at the grouping level(s) specified in level
and,
optionally, other covariates summarized over groups. The returned
object inherits from classes random.effects.lme
and
data.frame
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
coef.lme
,
gsummary
,
lme
,
plot.ranef.lme
,
random.effects
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) ranef(fm1) random.effects(fm1) # same as above random.effects(fm1, augFrame = TRUE)
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) ranef(fm1) random.effects(fm1) # same as above random.effects(fm1, augFrame = TRUE)
The difference between the individual lm
components
coefficients and their average is calculated.
## S3 method for class 'lmList' ranef(object, augFrame, data, which, FUN, standard, omitGroupingFactor, ...)
## S3 method for class 'lmList' ranef(object, augFrame, data, which, FUN, standard, omitGroupingFactor, ...)
object |
an object inheriting from class |
augFrame |
an optional logical value. If |
data |
an optional data frame with the variables to be used for
augmenting the returned data frame when |
which |
an optional positive integer vector specifying which
columns of |
FUN |
an optional summary function or a list of summary functions
to be applied to group-varying variables, when collapsing |
standard |
an optional logical value indicating whether the
estimated random effects should be "standardized" (i.e. divided by
the corresponding estimated standard error). Defaults to
|
omitGroupingFactor |
an optional logical value. When |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the differences between the individual lm
coefficients in object
and their average.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer, esp. pp. 100, 461.
fixed.effects.lmList
,
lmList
,
random.effects
fm1 <- lmList(distance ~ age | Subject, Orthodont) ranef(fm1) random.effects(fm1) # same as above
fm1 <- lmList(distance ~ age | Subject, Orthodont) ranef(fm1) random.effects(fm1) # same as above
The RatPupWeight
data frame has 322 rows and 5 columns.
This data frame contains the following columns:
a numeric vector
a factor with levels
Male
Female
an ordered factor with levels
9
< 8
< 7
< 4
< 2
< 10
< 1
< 3
< 5
< 6
< 21
< 22
< 24
< 27
< 26
< 25
< 23
< 17
< 11
< 14
< 13
< 15
< 16
< 20
< 19
< 18
< 12
a numeric vector
an ordered factor with levels
Control
< Low
< High
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include: corStruct
, modelStruct
,
reStruct
, and varFunc
.
recalc(object, conLin, ...)
recalc(object, conLin, ...)
object |
any object which induces a recalculation of the condensed
linear model object |
conLin |
a condensed linear model object, consisting of a list
with components |
... |
some methods for this generic can take additional arguments. |
the recalculated condensed linear model object.
This function is only used inside model fitting functions, such as
lme
and gls
, that require recalculation of a condensed
linear model object.
José Pinheiro and Douglas Bates [email protected]
recalc.corStruct
,
recalc.modelStruct
,
recalc.reStruct
,
recalc.varFunc
## see the method function documentation
## see the method function documentation
This method function pre-multiples the "Xy"
component of
conLin
by the transpose square-root factor(s) of the
correlation matrix (matrices) associated with object
and adds
the log-likelihood contribution of object
, given by
logLik(object)
, to the "logLik"
component of
conLin
.
## S3 method for class 'corStruct' recalc(object, conLin, ...)
## S3 method for class 'corStruct' recalc(object, conLin, ...)
object |
an object inheriting from class |
conLin |
a condensed linear model object, consisting of a list
with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the recalculated condensed linear model object.
This method function is only used inside model
fitting functions, such as lme
and gls
,
that allow correlated error terms.
José Pinheiro and Douglas Bates [email protected]
This method function recalculates the condensed linear model object
using each element of object
sequentially from last to first.
## S3 method for class 'modelStruct' recalc(object, conLin, ...)
## S3 method for class 'modelStruct' recalc(object, conLin, ...)
object |
an object inheriting from class |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the recalculated condensed linear model object.
This method function is generally only used inside model fitting
functions, such as lme
and gls
, that allow model
components, such as correlated error terms and variance functions.
José Pinheiro and Douglas Bates [email protected]
recalc.corStruct
,
recalc.reStruct
,
recalc.varFunc
The log-likelihood, or restricted log-likelihood, of the
Gaussian linear mixed-effects model represented by object
and
conLin
(assuming spherical within-group covariance structure),
evaluated at coef(object)
is calculated and added to the
logLik
component of conLin
. The settings
attribute of object
determines whether the log-likelihood, or
the restricted log-likelihood, is to be calculated. The computational
methods for the (restricted) log-likelihood calculations are described
in Bates and Pinheiro (1998).
## S3 method for class 'reStruct' recalc(object, conLin, ...)
## S3 method for class 'reStruct' recalc(object, conLin, ...)
object |
an object inheriting from class |
conLin |
a condensed linear model object, consisting of a list
with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the condensed linear model with its logLik
component updated.
José Pinheiro and Douglas Bates [email protected]
This method function pre-multiples the "Xy"
component of
conLin
by a diagonal matrix with diagonal elements given by the
weights corresponding to the variance structure represented by
object
e and adds the log-likelihood contribution of
object
, given by logLik(object)
, to the "logLik"
component of conLin
.
## S3 method for class 'varFunc' recalc(object, conLin, ...)
## S3 method for class 'varFunc' recalc(object, conLin, ...)
object |
an object inheriting from class |
conLin |
a condensed linear model object, consisting of a list
with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
the recalculated condensed linear model object.
This method function is only used inside model fitting functions,
such as lme
and gls
, that allow heteroscedastic error
terms.
José Pinheiro and Douglas Bates [email protected]
recalc
,
varWeights
,
logLik.varFunc
The Relaxin
data frame has 198 rows and 3 columns.
This data frame contains the following columns:
an ordered factor with levels
5
< 8
< 9
< 3
< 4
< 2
< 7
< 1
< 6
a numeric vector
a numeric vector
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
Intravenous infusion of remifentanil (a strong analgesic) in different
rates over varying time periods was applied to a total of 65 patients.
Concentration measurements of remifentanil were taken along with several
covariates resulting in the Remifentanil
data frame with 2107 rows
and 12 columns.
data("Remifentanil", package = "nlme")
data("Remifentanil", package = "nlme")
This data frame (of class "groupedData"
, specifically
"nfnGroupedData"
) contains the following columns:
ID
:numerical (patient) IDs.
Subject
:an ordered
factor with 65 levels (of the
ID
s): 30
< 21
< 25
< 23
<
29
< ... ... < 36
< 6
< 5
< 10
< 9
.
Time
:time from beginning of infusion in minutes (numeric
).
conc
:remifentanil concentration in [ng / ml] (numeric).
Rate
:infusion rate in [µg / min].
Amt
:amount of remifentanil given in the current time interval in [µg].
Age
:age of the patient in years.
Sex
:gender of the patient, a factor
with levels
Female
and Male
.
Ht
:height of the patient in cm.
Wt
:weight of the patient in kg.
BSA
:body surface area (DuBois and DuBois 1916): .
LBM
:lean body mass (James 1976), with slightly different
formula for
men , and
women
.
of this help page: Niels Hagenbuch and Martin Maechler, SfS ETH Zurich.
Pinheiro, J. C. and Bates, D. M. (2000). Mixed-Effects Models in S and S-PLUS, Springer, New York.
Minto CF, Schnider TW, Egan TD, Youngs E, Lemmens HJM, Gambus PL, Billard V, Hoke JF, Moore KHP, Hermann DJ, Muir KT, Mandema JW, Shafer SL (1997). Influence of age and gender on the pharmacokinetics and pharmacodynamics of remifentanil: I. Model development. Anesthesiology 86 1, 10–23. doi:10.1097/00000542-199701000-00004
Charles F. Minto, Thomas W. Schnider and Steven L. Shafer (1997). Pharmacokinetics and Pharmacodynamics of Remifentanil: II. Model Application. Anesthesiology 86 1, 24–33. doi:10.1097/00000542-199701000-00005
plot(Remifentanil, type = "l", lwd = 2) # shows the 65 patients' remi profiles ## The same on log-log scale (*more* sensible for modeling ?): plot(Remifentanil, type = "l", lwd = 2, scales = list(log=TRUE)) str(Remifentanil) summary(Remifentanil) plot(xtabs(~Subject, Remifentanil)) summary(unclass(table(Remifentanil$Subject))) ## between 20 and 54 measurements per patient (median: 24; mean: 32.42) ## Only first measurement of each patient : dim(Remi.1 <- Remifentanil[!duplicated(Remifentanil[,"ID"]),]) # 65 x 12 LBMfn <- function(Wt, Ht, Sex) ifelse(Sex == "Female", 1.07 * Wt - 148*(Wt/Ht)^2, 1.1 * Wt - 128*(Wt/Ht)^2) with(Remi.1, stopifnot(all.equal(BSA, Wt^{0.425} * Ht^{0.725} * 0.007184, tolerance = 1.5e-5), all.equal(LBM, LBMfn(Wt, Ht, Sex), tolerance = 7e-7) )) ## Rate: typically 3 µg / kg body weight, but : sunflowerplot(Rate ~ Wt, Remifentanil) abline(0,3, lty=2, col=adjustcolor("black", 0.5))
plot(Remifentanil, type = "l", lwd = 2) # shows the 65 patients' remi profiles ## The same on log-log scale (*more* sensible for modeling ?): plot(Remifentanil, type = "l", lwd = 2, scales = list(log=TRUE)) str(Remifentanil) summary(Remifentanil) plot(xtabs(~Subject, Remifentanil)) summary(unclass(table(Remifentanil$Subject))) ## between 20 and 54 measurements per patient (median: 24; mean: 32.42) ## Only first measurement of each patient : dim(Remi.1 <- Remifentanil[!duplicated(Remifentanil[,"ID"]),]) # 65 x 12 LBMfn <- function(Wt, Ht, Sex) ifelse(Sex == "Female", 1.07 * Wt - 148*(Wt/Ht)^2, 1.1 * Wt - 128*(Wt/Ht)^2) with(Remi.1, stopifnot(all.equal(BSA, Wt^{0.425} * Ht^{0.725} * 0.007184, tolerance = 1.5e-5), all.equal(LBM, LBMfn(Wt, Ht, Sex), tolerance = 7e-7) )) ## Rate: typically 3 µg / kg body weight, but : sunflowerplot(Rate ~ Wt, Remifentanil) abline(0,3, lty=2, col=adjustcolor("black", 0.5))
The residuals for the linear model represented by object
are extracted.
## S3 method for class 'gls' residuals(object, type, ...)
## S3 method for class 'gls' residuals(object, type, ...)
object |
an object inheriting from class |
type |
an optional character string specifying the type of
residuals to be used. If |
... |
some methods for this generic function require additional arguments. None are used in this method. |
a vector with the residuals for the linear model represented by
object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) residuals(fm1)
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) residuals(fm1)
The residuals for the linear model represented by object
are extracted.
## S3 method for class 'glsStruct' residuals(object, glsFit, ...)
## S3 method for class 'glsStruct' residuals(object, glsFit, ...)
object |
an object inheriting from class |
glsFit |
an optional list with components |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the residuals for the linear model represented by
object
.
This method function is primarily used inside gls
and
residuals.gls
.
José Pinheiro and Douglas Bates [email protected]
gls
,
glsStruct
,
residuals.gls
,
fitted.glsStruct
The residuals for the nonlinear model represented by object
are extracted.
## S3 method for class 'gnlsStruct' residuals(object, ...)
## S3 method for class 'gnlsStruct' residuals(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a vector with the residuals for the nonlinear model represented by
object
.
This method function is primarily used inside gnls
and
residuals.gnls
.
José Pinheiro and Douglas Bates [email protected]
gnls
,
residuals.gnls
,
fitted.gnlsStruct
The residuals at level are obtained by subtracting the fitted
levels at that level from the response vector (and dividing
by the estimated within-group standard error, if
type="pearson"
). The fitted values at level are obtained
by adding together the population fitted values (based only on the
fixed effects estimates) and the estimated contributions of the random
effects to the fitted values at grouping levels less or equal to
.
## S3 method for class 'lme' residuals(object, level = Q, type = c("response", "pearson", "normalized"), asList = FALSE, ...)
## S3 method for class 'lme' residuals(object, level = Q, type = c("response", "pearson", "normalized"), asList = FALSE, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the residuals from |
type |
an optional character string specifying the type of
residuals to be used. If |
asList |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
if a single level of grouping is specified in level
, the
returned value is either a list with the residuals split by groups
(asList = TRUE
) or a vector with the residuals
(asList = FALSE
); else, when multiple grouping levels are
specified in level
, the returned object is a data frame with
columns given by the residuals at different levels and the grouping
factors. For a vector or data frame result the naresid
method is applied.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) head(residuals(fm1, level = 0:1)) summary(residuals(fm1) / residuals(fm1, type = "p")) # constant scaling factor 1.432
fm1 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1) head(residuals(fm1, level = 0:1)) summary(residuals(fm1) / residuals(fm1, type = "p")) # constant scaling factor 1.432
The residuals at level are obtained by subtracting the fitted
values at that level from the response vector. The fitted values at
level
are obtained by adding together the population fitted
values (based only on the fixed effects estimates) and the estimated
contributions of the random effects to the fitted values at grouping
levels less or equal to
.
## S3 method for class 'lmeStruct' residuals(object, level, conLin, lmeFit, ...)
## S3 method for class 'lmeStruct' residuals(object, level, conLin, lmeFit, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the residuals from |
conLin |
an optional condensed linear model object, consisting of
a list with components |
lmeFit |
an optional list with components |
... |
some methods for this generic accept optional arguments. |
if a single level of grouping is specified in level
,
the returned value is a vector with the residuals at the desired
level; else, when multiple grouping levels are specified in
level
, the returned object is a matrix with
columns given by the residuals at different levels.
This method function is primarily used within the lme
function.
José Pinheiro and Douglas Bates [email protected]
lme
,
residuals.lme
,
fitted.lmeStruct
The residuals are extracted from each lm
component of
object
and arranged into a list with as many components as
object
, or combined into a single vector.
## S3 method for class 'lmList' residuals(object, type, subset, asList, ...)
## S3 method for class 'lmList' residuals(object, type, subset, asList, ...)
object |
an object inheriting from class |
subset |
an optional character or integer vector naming the
|
type |
an optional character string specifying the type of
residuals to be extracted. Options include |
asList |
an optional logical value. If |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with components given by the residuals of each lm
component of object
, or a vector with the residuals for all
lm
components of object
.
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) residuals(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) residuals(fm1)
The residuals at level are obtained by subtracting the fitted
values at that level from the response vector. The fitted values at
level
are obtained by adding together the contributions from
the estimated fixed effects and the estimated random effects at levels
less or equal to
and evaluating the model function at the
resulting estimated parameters.
## S3 method for class 'nlmeStruct' residuals(object, level, conLin, ...)
## S3 method for class 'nlmeStruct' residuals(object, level, conLin, ...)
object |
an object inheriting from class |
level |
an optional integer vector giving the level(s) of grouping
to be used in extracting the residuals from |
conLin |
an optional condensed linear model object, consisting of
a list with components |
... |
optional arguments to the residuals generic. Not used. |
if a single level of grouping is specified in level
,
the returned value is a vector with the residuals at the desired
level; else, when multiple grouping levels are specified in
level
, the returned object is a matrix with
columns given by the residuals at different levels.
This method function is primarily used within the nlme
function.
José Pinheiro and Douglas Bates [email protected]
Bates, D.M. and Pinheiro, J.C. (1998) "Computational methods for multilevel models" available in PostScript or PDF formats at http://nlme.stat.wisc.edu
This function is a constructor for the reStruct
class,
representing a random effects structure and consisting of a list of
pdMat
objects, plus a settings
attribute containing
information for the optimization algorithm used to fit the associated
mixed-effects model.
reStruct(object, pdClass, REML, data) ## S3 method for class 'reStruct' print(x, sigma, reEstimates, verbose, ...)
reStruct(object, pdClass, REML, data) ## S3 method for class 'reStruct' print(x, sigma, reEstimates, verbose, ...)
object |
any of the following: (i) a one-sided formula of the form
|
pdClass |
an optional character string with the name of the
|
REML |
an optional logical value. If |
data |
an optional data frame in which to evaluate the variables
used in the random effects formulas in |
x |
an object inheriting from class |
sigma |
an optional numeric value used as a multiplier for
the square-root factors of the |
reEstimates |
an optional list with the random effects estimates
for each level of grouping. Only used when |
verbose |
an optional logical value determining if the random
effects estimates should be printed. Defaults to |
... |
Optional arguments can be given to other methods for this generic. None are used in this method. |
an object inheriting from class reStruct
, representing a random
effects structure.
José Pinheiro and Douglas Bates [email protected]
groupedData
,
lme
,
pdMat
,
solve.reStruct
,
summary.reStruct
,
update.reStruct
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) rs1 # 2 entries "Uninitialized" str(rs1) # a bit more
rs1 <- reStruct(list(Dog = ~day, Side = ~1), data = Pixel) rs1 # 2 entries "Uninitialized" str(rs1) # a bit more
lme
ModelsThe model object
is fit to the data. Using
the fitted values of the parameters, nsim
new data vectors from
this model are simulated. Both object
and m2
are fit by
maximum likelihood (ML) and/or by restricted maximum likelihood (REML)
to each of the simulated data vectors.
## S3 method for class 'lme' simulate(object, nsim = 1, seed = , m2, method = c("REML", "ML"), niterEM = c(40, 200), useGen, ...)
## S3 method for class 'lme' simulate(object, nsim = 1, seed = , m2, method = c("REML", "ML"), niterEM = c(40, 200), useGen, ...)
object |
an object inheriting from class |
m2 |
an |
seed |
an optional integer that is passed to |
method |
an optional character array. If it includes
|
nsim |
an optional positive integer specifying the number of
simulations to perform. Defaults to |
niterEM |
an optional integer vector of length 2 giving the number of
iterations of the EM algorithm to apply when fitting the |
useGen |
an optional logical value. If |
... |
optional additional arguments. None are used. |
an object of class simulate.lme
with components null
and
alt
. Each of these has components ML
and/or REML
which are matrices. An attribute called seed
contains
the seed that was used for the random number generator.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) Mixed-Effects Models in S and S-PLUS, Springer.
orthSim <- simulate.lme(list(fixed = distance ~ age, data = Orthodont, random = ~ 1 | Subject), nsim = 3, # limited here for speed m2 = list(random = ~ age | Subject))
orthSim <- simulate.lme(list(fixed = distance ~ age, data = Orthodont, random = ~ 1 | Subject), nsim = 3, # limited here for speed m2 = list(random = ~ age | Subject))
The positive-definite matrix represented by a
is inverted and
assigned to a
.
## S3 method for class 'pdMat' solve(a, b, ...)
## S3 method for class 'pdMat' solve(a, b, ...)
a |
an object inheriting from class |
b |
this argument is only included for consistency with the generic function and is not used in this method function. |
... |
some methods for this generic require additional arguments. None are used in this method. |
a pdMat
object similar to a
, but with coefficients
corresponding to the inverse of the positive-definite matrix
represented by a
.
José Pinheiro and Douglas Bates [email protected]
pd1 <- pdCompSymm(3 * diag(3) + 1) solve(pd1)
pd1 <- pdCompSymm(3 * diag(3) + 1) solve(pd1)
Solve
is applied to each pdMat
component of a
,
which results in inverting the positive-definite matrices they
represent.
## S3 method for class 'reStruct' solve(a, b, ...)
## S3 method for class 'reStruct' solve(a, b, ...)
a |
an object inheriting from class |
b |
this argument is only included for consistency with the generic function and is not used in this method function. |
... |
some methods for this generic require additional arguments. None are used in this method. |
an reStruct
object similar to a
, but with the
pdMat
components representing the inverses of the
matrices represented by the components of a
.
José Pinheiro and Douglas Bates [email protected]
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) solve(rs1)
rs1 <- reStruct(list(A = pdSymm(diag(1:3), form = ~Score), B = pdDiag(2 * diag(4), form = ~Educ))) solve(rs1)
The Soybean
data frame has 412 rows and 5 columns.
This data frame contains the following columns:
a factor giving a unique identifier for each plot.
a factor indicating the variety; Forrest (F) or Plant Introduction #416937 (P).
a factor indicating the year the plot was planted.
a numeric vector giving the time the sample was taken (days after planting).
a numeric vector giving the average leaf weight per plant (g).
These data are described in Davidian and Giltinan (1995, 1.1.3, p.7) as “Data from an experiment to compare growth patterns of two genotypes of soybeans: Plant Introduction #416937 (P), an experimental strain, and Forrest (F), a commercial variety.”
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.27)
Davidian, M. and Giltinan, D. M. (1995), Nonlinear Models for Repeated Measurement Data, Chapman and Hall, London.
summary(fm1 <- nlsList(SSlogis, data = Soybean))
summary(fm1 <- nlsList(SSlogis, data = Soybean))
Splits the right hand side of form
into a list of subformulas
according to the presence of sep
. The left hand side of
form
, if present, will be ignored. The length of the returned
list will be equal to the number of occurrences of sep
in
form
plus one.
splitFormula(form, sep)
splitFormula(form, sep)
form |
a |
sep |
an optional character string specifying the separator to be
used for splitting the formula. Defaults to |
a list of formulas, corresponding to the split of form
according to sep
.
José Pinheiro and Douglas Bates [email protected]
splitFormula(~ g1/g2/g3)
splitFormula(~ g1/g2/g3)
The Spruce
data frame has 1027 rows and 4 columns.
This data frame contains the following columns:
a factor giving a unique identifier for each tree.
a numeric vector giving the number of days since the beginning of the experiment.
a numeric vector giving the logarithm of an estimate of the volume of the tree trunk.
a factor identifying the plot in which the tree was grown.
Diggle, Liang, and Zeger (1994, Example 1.3, page 5) describe data on the growth of spruce trees that have been exposed to an ozone-rich atmosphere or to a normal atmosphere.
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York. (Appendix A.28)
Diggle, Peter J., Liang, Kung-Yee and Zeger, Scott L. (1994), Analysis of longitudinal data, Oxford University Press, Oxford.
This method function prepares object
to be printed using the
print.summary
method, by changing its class and adding a
structName
attribute to it.
## S3 method for class 'corStruct' summary(object, structName, ...)
## S3 method for class 'corStruct' summary(object, structName, ...)
object |
an object inheriting from class |
structName |
an optional character string defining the type of
correlation structure associated with |
... |
some methods for this generic require additional arguments. None are used in this method. |
an object identical to object
, but with its class changed to
summary.corStruct
and an additional attribute
structName
. The returned value inherits from the same classes
as object
.
José Pinheiro and Douglas Bates
corClasses
,
corNatural
,
Initialize.corStruct
,
summary
cs1 <- corAR1(0.2) summary(cs1)
cs1 <- corAR1(0.2) summary(cs1)
gls
ObjectAdditional information about the linear model fit represented
by object
is extracted and included as components of
object
.
## S3 method for class 'gls' summary(object, verbose, ...)
## S3 method for class 'gls' summary(object, verbose, ...)
object |
an object inheriting from class |
verbose |
an optional logical value used to control the amount of
output when the object is printed. Defaults to |
... |
some methods for this generic require additional arguments. None are used in this method. |
an object inheriting from class summary.gls
with all components
included in object
(see glsObject
for a full
description of the components) plus the following components:
corBeta |
approximate correlation matrix for the coefficients estimates |
tTable |
a matrix with columns |
residuals |
if more than five observations are used in the
|
AIC |
the Akaike Information Criterion corresponding to
|
BIC |
the Bayesian Information Criterion corresponding to
|
José Pinheiro and Douglas Bates [email protected]
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) summary(fm1) coef(summary(fm1)) # "the matrix"
fm1 <- gls(follicles ~ sin(2*pi*Time) + cos(2*pi*Time), Ovary, correlation = corAR1(form = ~ 1 | Mare)) summary(fm1) coef(summary(fm1)) # "the matrix"
Additional information about the linear mixed-effects fit represented
by object
is extracted and included as components of
object
. The returned object has a print
and a
coef
method, the latter returning the coefficient's
tTtable
.
## S3 method for class 'lme' summary(object, adjustSigma, verbose, ...) ## S3 method for class 'summary.lme' print(x, verbose = FALSE, ...)
## S3 method for class 'lme' summary(object, adjustSigma, verbose, ...) ## S3 method for class 'summary.lme' print(x, verbose = FALSE, ...)
object |
an object inheriting from class |
adjustSigma |
an optional logical value. If |
verbose |
an optional logical value used to control the amount of
output in the |
... |
additional optional arguments passed to methods, mainly
for the |
x |
a |
an object inheriting from class summary.lme
with all components
included in object
(see lmeObject
for a full
description of the components) plus the following components:
corFixed |
approximate correlation matrix for the fixed effects estimates. |
tTable |
a matrix with columns named |
residuals |
if more than five observations are used in the
|
AIC |
the Akaike Information Criterion corresponding to
|
BIC |
the Bayesian Information Criterion corresponding to
|
José Pinheiro and Douglas Bates [email protected]
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) (s1 <- summary(fm1)) coef(s1) # the (coef | Std.E | t | P-v ) matrix
fm1 <- lme(distance ~ age, Orthodont, random = ~ age | Subject) (s1 <- summary(fm1)) coef(s1) # the (coef | Std.E | t | P-v ) matrix
The summary.lm
method is applied to each lm
component of
object
to produce summary information on the individual fits,
which is organized into a list of summary statistics. The returned
object is suitable for printing with the print.summary.lmList
method.
## S3 method for class 'lmList' summary(object, pool, ...)
## S3 method for class 'lmList' summary(object, pool, ...)
object |
an object inheriting from class |
pool |
an optional logical value indicating whether a pooled
estimate of the residual standard error should be used. Default is
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with summary statistics obtained by applying summary.lm
to the elements of object
, inheriting from class
summary.lmList
. The components of value
are:
call |
a list containing an image of the |
coefficients |
a three dimensional array with summary information
on the |
correlation |
a three dimensional array with the
correlations between the individual |
cov.unscaled |
a three dimensional array with the unscaled
variances/covariances for the individual |
df |
an array with the number of degrees of freedom for the model
and for residuals, for each |
df.residual |
the total number of degrees of freedom for
residuals, corresponding to the sum of residuals df of all |
fstatistics |
an array with the F test statistics and
corresponding degrees of freedom, for each |
pool |
the value of the |
r.squared |
a vector with the multiple R-squared statistics for
each |
residuals |
a list with components given by the residuals from
individual |
RSE |
the pooled estimate of the residual standard error. |
sigma |
a vector with the residual standard error estimates for
the individual |
terms |
the terms object used in fitting the individual |
José Pinheiro and Douglas Bates [email protected]
fm1 <- lmList(distance ~ age | Subject, Orthodont) summary(fm1)
fm1 <- lmList(distance ~ age | Subject, Orthodont) summary(fm1)
This method function applies summary
to each element of
object
.
## S3 method for class 'modelStruct' summary(object, ...)
## S3 method for class 'modelStruct' summary(object, ...)
object |
an object inheriting from class |
... |
some methods for this generic require additional arguments. None are used in this method. |
a list with elements given by the summarized components of
object
. The returned value is of class
summary.modelStruct
, also inheriting from the same classes as
object
.
José Pinheiro and Douglas Bates [email protected]
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), corStruct = corAR1(0.3)) summary(lms1)
lms1 <- lmeStruct(reStruct = reStruct(pdDiag(diag(2), ~age)), corStruct = corAR1(0.3)) summary(lms1)
The summary
function is applied to each nls
component of
object
to produce summary information on the individual fits,
which is organized into a list of summary statistics. The returned
object is suitable for printing with the print.summary.nlsList
method.
## S3 method for class 'nlsList' summary(object, ...)
## S3 method for class 'nlsList' summary(object, ...)
object |
an object inheriting from class |
... |
optional arguments to the |
a list with summary statistics obtained by applying summary
to the elements of object
, inheriting from class
summary.nlsList
. The components of value
are:
call |
a list containing an image of the |
parameters |
a three dimensional array with summary information
on the |
correlation |
a three dimensional array with the
correlations between the individual |
cov.unscaled |
a three dimensional array with the unscaled
variances/covariances for the individual |
df |
an array with the number of degrees of freedom for the model
and for residuals, for each |
df.residual |
the total number of degrees of freedom for
residuals, corresponding to the sum of residuals df of all |
pool |
the value of the |
RSE |
the pooled estimate of the residual standard error. |
sigma |
a vector with the residual standard error estimates for
the individual |
José Pinheiro and Douglas Bates [email protected]
fm1 <- nlsList(SSasymp, Loblolly) summary(fm1)
fm1 <- nlsList(SSasymp, Loblolly) summary(fm1)
Attributes structName
and noCorrelation
, with the values
of the corresponding arguments to the method function, are appended to
object
and its class is changed to summary.pdMat
.
## S3 method for class 'pdMat' summary(object, structName, noCorrelation, ...)
## S3 method for class 'pdMat' summary(object, structName, noCorrelation, ...)
object |
an object inheriting from class |
structName |
an optional character string with a description of
the |
noCorrelation |
an optional logical value indicating whether
correlations are to be printed in |
... |
some methods for this generic require additional arguments. None are used in this method. |
an object similar to object
, with additional attributes
structName
and noCorrelation
, inheriting from class
summary.pdMat
.
José Pinheiro and Douglas Bates [email protected]
summary(pdSymm(diag(4)))
summary(pdSymm(diag(4)))
A structName
attribute, with the value of corresponding
argument, is appended to object
and its class is changed to
summary.varFunc
.
## S3 method for class 'varFunc' summary(object, structName, ...)
## S3 method for class 'varFunc' summary(object, structName, ...)
object |
an object inheriting from class |
structName |
an optional character string with a description of
the
|
... |
some methods for this generic require additional arguments. None are used in this method. |
an object similar to object
, with an additional attribute
structName
, inheriting from class summary.varFunc
.
José Pinheiro and Douglas Bates [email protected]
vf1 <- varPower(0.3, form = ~age) vf1 <- Initialize(vf1, Orthodont) summary(vf1)
vf1 <- varPower(0.3, form = ~age) vf1 <- Initialize(vf1, Orthodont) summary(vf1)
The Tetracycline1
data frame has 40 rows and 4 columns.
This data frame contains the following columns:
a numeric vector
a numeric vector
an ordered factor with levels
5
< 3
< 2
< 4
< 1
a factor with levels
tetrachel
tetracyn
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
The Tetracycline2
data frame has 40 rows and 4 columns.
This data frame contains the following columns:
a numeric vector
a numeric vector
an ordered factor with levels
4
< 5
< 2
< 1
< 3
a factor with levels
Berkmycin
tetramycin
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
This method function updates each element of object
, allowing
the access to data
.
## S3 method for class 'modelStruct' update(object, data, ...)
## S3 method for class 'modelStruct' update(object, data, ...)
object |
an object inheriting from class |
data |
a data frame in which to evaluate the variables needed for
updating the elements of |
... |
some methods for this generic require additional arguments. None are used in this method. |
an object similar to object
(same class, length, and names),
but with updated elements.
This method function is primarily used within model fitting
functions, such as lme
and gls
, that allow model
components such as variance functions.
José Pinheiro and Douglas Bates [email protected]
If the formula(object)
includes a "."
term, representing
a fitted object, the variance covariate needs to be updated upon
completion of an optimization cycle (in which the variance function
weights are kept fixed). This method function allows a reevaluation of
the variance covariate using the current fitted object and,
optionally, other variables in the original data.
## S3 method for class 'varFunc' update(object, data, ...)
## S3 method for class 'varFunc' update(object, data, ...)
object |
an object inheriting from class |
data |
a list with a component named |
... |
some methods for this generic require additional arguments. None are used in this method. |
if formula(object)
includes a "."
term, an
varFunc
object similar to object
, but with the
variance covariate reevaluated at the current fitted object value;
else object
is returned unchanged.
José Pinheiro and Douglas Bates [email protected]
needUpdate
,
covariate<-.varFunc
Standard classes of variance function structures (varFunc
)
available in the nlme
package. Covariates included in the
variance function, denoted by variance covariates, may involve
functions of the fitted model object, such as the fitted values and
the residuals. Different coefficients may be assigned to the levels of
a classification factor.
Available standard classes:
varExp |
exponential of a variance covariate. |
varPower |
power of a variance covariate. |
varConstPower |
constant plus power of a variance covariate. |
varConstProp |
constant plus proportion of a variance covariate. |
varIdent |
constant variance(s), generally used to allow different variances according to the levels of a classification factor. |
varFixed |
fixed weights, determined by a variance covariate. |
varComb |
combination of variance functions. |
Users may define their own varFunc
classes by specifying a
constructor
function and, at a minimum, methods for the
functions coef
, coef<-
, and initialize
. For
examples of these functions, see the methods for class
varPower
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varComb
,
varConstPower
,
varConstProp
,
varExp
,
varFixed
,
varIdent
,
varPower
,
summary.varFunc
This function is a constructor for the varComb
class,
representing a combination of variance functions. The corresponding
variance function is equal to the product of the variance functions of
the varFunc
objects listed in ...
.
varComb(...)
varComb(...)
... |
objects inheriting from class |
a varComb
object representing a combination of variance
functions, also inheriting from class varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varClasses
,
varWeights.varComb
,
coef.varComb
vf1 <- varComb(varIdent(form = ~1|Sex), varPower())
vf1 <- varComb(varIdent(form = ~1|Sex), varPower())
This function is a constructor for the varConstPower
class,
representing a constant plus power variance function
structure. Letting denote the variance covariate and
denote the variance function evaluated at
, the constant plus power variance function is defined as
, where
are the variance
function coefficients. When a grouping factor is present, different
are used for each factor level.
varConstPower(const, power, form, fixed)
varConstPower(const, power, form, fixed)
const , power
|
optional numeric vectors, or lists of numeric
values, with, respectively, the coefficients for the constant
and the power terms. Both arguments must have length one, unless a
grouping factor is specified in |
form |
an optional one-sided formula of the form |
fixed |
an optional list with components |
a varConstPower
object representing a constant plus power
variance function structure, also inheriting from class
varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varClasses
,
varWeights.varFunc
,
coef.varConstPower
vf1 <- varConstPower(1.2, 0.2, form = ~age|Sex)
vf1 <- varConstPower(1.2, 0.2, form = ~age|Sex)
This function is a constructor for the varConstProp
class,
representing a variance function structure corresponding to
a two-component error model (additive and proportional error). Letting
denote the variance covariate and
denote the variance function evaluated at
, the two-component variance
function is defined as
, where a is
the additive component and b is the relative error component. In order
to avoid overparameterisation of the model, it is recommended to use
the possibility to fix sigma, preferably to a value of 1 (see examples).
varConstProp(const, prop, form, fixed)
varConstProp(const, prop, form, fixed)
const , prop
|
optional numeric vectors, or lists of numeric
values, with, respectively, the coefficients for the constant
and the proportional error terms. Both arguments must have length one,
unless a grouping factor is specified in |
form |
an optional one-sided formula of the form |
fixed |
an optional list with components |
a varConstProp
object representing a constant plus proportion variance
function structure, also inheriting from class varFunc
.
The error model underlying this variance function structure can be understood
to result from two uncorrelated sequences of standardized random variables
(Lavielle(2015), p. 55) and has been proposed for use in analytical chemistry
(Werner et al. (1978), Wilson et al. (2004)) and chemical degradation
kinetics (Ranke and Meinecke (2019)). Note that the two-component error
model proposed by Rocke and Lorenzato (1995) assumed a log-normal
distribution of residuals at high absolute values, which is not
compatible with the varFunc
structures in package nlme.
José Pinheiro and Douglas Bates (for varConstPower
) and
Johannes Ranke (adaptation to varConstProp()
).
Lavielle, M. (2015) Mixed Effects Models for the Population Approach: Models, Tasks, Methods and Tools, Chapman and Hall/CRC. doi:10.1201/b17203
Pinheiro, J.C., and Bates, D.M. (2000) Mixed-Effects Models in S and S-PLUS, Springer. doi:10.1007/b98882
Ranke, J., and Meinecke, S. (2019) Error Models for the Kinetic Evaluation of Chemical Degradation Data. Environments 6(12), 124 doi:10.3390/environments6120124
Rocke, David M. and Lorenzato, Stefan (1995) A Two-Component Model for Measurement Error in Analytical Chemistry. Technometrics 37(2), 176–184. doi:10.1080/00401706.1995.10484302
Werner, Mario, Brooks, Samuel H., and Knott, Lancaster B. (1978) Additive, Multiplicative, and Mixed Analytical Errors. Clinical Chemistry 24(11), 1895–1898. doi:10.1093/clinchem/24.11.1895
Wilson, M.D., Rocke, D.M., Durbin, B. and Kahn, H.D (2004) Detection Limits and Goodness-of-Fit Measures for the Two-Component Model of Chemical Analytical Error. Analytica Chimica Acta 2004, 509, 197–208 doi:10.1016/j.aca.2003.12.047
varClasses
,
varWeights.varFunc
,
coef.varFunc
# Generate some synthetic data using the two-component error model and use # different variance functions, also with fixed sigma in order to avoid # overparameterisation in the case of a constant term in the variance function times <- c(0, 1, 3, 7, 14, 28, 56, 120) pred <- 100 * exp(- 0.03 * times) sd_pred <- sqrt(3^2 + 0.07^2 * pred^2) n_replicates <- 2 set.seed(123456) syn_data <- data.frame( time = rep(times, each = n_replicates), value = rnorm(length(times) * n_replicates, rep(pred, each = n_replicates), rep(sd_pred, each = n_replicates))) syn_data$value <- ifelse(syn_data$value < 0, NA, syn_data$value) f_const <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3)) f_varPower <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varPower()) f_varConstPower <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varConstPower()) f_varConstPower_sf <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, control = list(sigma = 1), start = list(parent_0 = 100, lrc = -3), weights = varConstPower()) f_varConstProp <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varConstProp()) f_varConstProp_sf <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), control = list(sigma = 1), weights = varConstProp()) AIC(f_const, f_varPower, f_varConstPower, f_varConstPower_sf, f_varConstProp, f_varConstProp_sf) # The error model parameters 3 and 0.07 are approximately recovered intervals(f_varConstProp_sf)
# Generate some synthetic data using the two-component error model and use # different variance functions, also with fixed sigma in order to avoid # overparameterisation in the case of a constant term in the variance function times <- c(0, 1, 3, 7, 14, 28, 56, 120) pred <- 100 * exp(- 0.03 * times) sd_pred <- sqrt(3^2 + 0.07^2 * pred^2) n_replicates <- 2 set.seed(123456) syn_data <- data.frame( time = rep(times, each = n_replicates), value = rnorm(length(times) * n_replicates, rep(pred, each = n_replicates), rep(sd_pred, each = n_replicates))) syn_data$value <- ifelse(syn_data$value < 0, NA, syn_data$value) f_const <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3)) f_varPower <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varPower()) f_varConstPower <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varConstPower()) f_varConstPower_sf <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, control = list(sigma = 1), start = list(parent_0 = 100, lrc = -3), weights = varConstPower()) f_varConstProp <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), weights = varConstProp()) f_varConstProp_sf <- gnls(value ~ SSasymp(time, 0, parent_0, lrc), data = syn_data, na.action = na.omit, start = list(parent_0 = 100, lrc = -3), control = list(sigma = 1), weights = varConstProp()) AIC(f_const, f_varPower, f_varConstPower, f_varConstPower_sf, f_varConstProp, f_varConstProp_sf) # The error model parameters 3 and 0.07 are approximately recovered intervals(f_varConstProp_sf)
This function calculates the estimated variances, standard
deviations, and correlations between the random-effects terms in a
linear mixed-effects model, of class "lme"
, or a nonlinear
mixed-effects model, of class "nlme"
. The within-group error
variance and standard deviation are also calculated.
VarCorr(x, sigma = 1, ...) ## S3 method for class 'lme' VarCorr(x, sigma = x$sigma, rdig = 3, ...) ## S3 method for class 'pdMat' VarCorr(x, sigma = 1, rdig = 3, ...) ## S3 method for class 'pdBlocked' VarCorr(x, sigma = 1, rdig = 3, ...)
VarCorr(x, sigma = 1, ...) ## S3 method for class 'lme' VarCorr(x, sigma = x$sigma, rdig = 3, ...) ## S3 method for class 'pdMat' VarCorr(x, sigma = 1, rdig = 3, ...) ## S3 method for class 'pdBlocked' VarCorr(x, sigma = 1, rdig = 3, ...)
x |
a fitted model object, usually an object inheriting from
class |
sigma |
an optional numeric value used as a multiplier for the
standard deviations. The default is |
rdig |
an optional integer value specifying the number of digits
used to represent correlation estimates. Default is |
... |
further optional arguments passed to other methods (none for the methods documented here). |
a matrix with the estimated variances, standard deviations, and
correlations for the random effects. The first two columns, named
Variance
and StdDev
, give, respectively, the variance
and the standard deviations. If there are correlation components in
the random effects model, the third column, named Corr
,
and the remaining unnamed columns give the estimated correlations
among random effects within the same level of grouping. The
within-group error variance and standard deviation are included as
the last row in the matrix.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) Mixed-Effects Models in S and S-PLUS, Springer, esp. pp. 100, 461.
fm1 <- lme(distance ~ age, data = Orthodont, random = ~age) VarCorr(fm1)
fm1 <- lme(distance ~ age, data = Orthodont, random = ~age) VarCorr(fm1)
This function is a constructor for the varExp
class,
representing an exponential variance function structure. Letting
denote the variance covariate and
denote the variance function evaluated at
, the exponential
variance function is defined as
, where
is the variance
function coefficient. When a grouping factor is present, a different
is used for each factor level.
varExp(value, form, fixed)
varExp(value, form, fixed)
value |
an optional numeric vector, or list of numeric values,
with the variance function coefficients. |
form |
an optional one-sided formula of the form |
fixed |
an optional numeric vector, or list of numeric values,
specifying the values at which some or all of the coefficients in
the variance function should be fixed. If a grouping factor is
specified in |
a varExp
object representing an exponential variance function
structure, also inheriting from class varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varClasses
,
varWeights.varFunc
,
coef.varExp
vf1 <- varExp(0.2, form = ~age|Sex)
vf1 <- varExp(0.2, form = ~age|Sex)
This function is a constructor for the varFixed
class,
representing a variance function with fixed variances. Letting
denote the variance covariate defined in
value
, the variance
function for this class is
. The variance covariate
is
evaluated once at initialization and remains fixed thereafter. No
coefficients are required to represent this variance function.
varFixed(value)
varFixed(value)
value |
a one-sided formula of the form |
a varFixed
object representing a fixed variance function
structure, also inheriting from class varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varClasses
,
varWeights.varFunc
,
varFunc
vf1 <- varFixed(~age)
vf1 <- varFixed(~age)
If object
is a one-sided formula, it is used as the argument to
varFixed
and the resulting object is returned. Else, if
object
inherits from class varFunc
, it is returned
unchanged.
varFunc(object)
varFunc(object)
object |
either an one-sided formula specifying a variance
covariate, or an object inheriting from class |
an object from class varFunc
, representing a variance function
structure.
José Pinheiro and Douglas Bates [email protected]
summary.varFunc
,
varFixed
,
varWeights.varFunc
,
coef.varFunc
vf1 <- varFunc(~age)
vf1 <- varFunc(~age)
This function is a constructor for the varIdent
class,
representing a constant variance function structure. If no grouping
factor is present in form
, the variance function is constant
and equal to one, and no coefficients required to represent it. When
form
includes a grouping factor with levels, the
variance function allows M different variances, one for each level of
the factor. For identifiability reasons, the coefficients of the
variance function represent the ratios between the variances and a
reference variance (corresponding to a reference group
level). Therefore, only
coefficients are needed to represent
the variance function. By default, if the elements in
value
are
unnamed, the first group level is taken as the reference level.
varIdent(value, form, fixed)
varIdent(value, form, fixed)
value |
an optional numeric vector, or list of numeric values,
with the variance function coefficients. If no grouping factor is
present in |
form |
an optional one-sided formula of the form |
fixed |
an optional numeric vector, or list of numeric values,
specifying the values at which some or all of the coefficients in
the variance function should be fixed. It must have names
identifying which coefficients are to be fixed. Coefficients
included in |
a varIdent
object representing a constant variance function
structure, also inheriting from class varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varClasses
,
varWeights.varFunc
,
coef.varIdent
vf1 <- varIdent(c(Female = 0.5), form = ~ 1 | Sex)
vf1 <- varIdent(c(Female = 0.5), form = ~ 1 | Sex)
This function is generic; method functions can be written to handle
specific classes of objects. Classes which already have methods for
this function include default
, gls
and lme
. See
the appropriate method documentation for a description of the
arguments.
Variogram(object, distance, ...)
Variogram(object, distance, ...)
object |
a numeric vector with the values to be used for calculating the semi-variogram, usually a residual vector from a fitted model. |
distance |
a numeric vector with the pairwise distances
corresponding to the elements of |
... |
some methods for this generic function require additional arguments. |
will depend on the method function used; see the appropriate documentation.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
Variogram.corExp
,
Variogram.corGaus
,
Variogram.corLin
,
Variogram.corRatio
,
Variogram.corSpatial
,
Variogram.corSpher
,
Variogram.default
,
Variogram.gls
,
Variogram.lme
,
plot.Variogram
## see the method function documentation
## see the method function documentation
This method function calculates the semi-variogram values
corresponding to the Exponential correlation model, using the estimated
coefficients corresponding to object
, at the distances defined
by distance
.
## S3 method for class 'corExp' Variogram(object, distance, sig2, length.out, ...)
## S3 method for class 'corExp' Variogram(object, distance, sig2, length.out, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corExp
,
plot.Variogram
,
Variogram
stopifnot(require("stats", quietly = TRUE)) cs1 <- corExp(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
stopifnot(require("stats", quietly = TRUE)) cs1 <- corExp(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
This method function calculates the semi-variogram values
corresponding to the Gaussian correlation model, using the estimated
coefficients corresponding to object
, at the distances defined
by distance
.
## S3 method for class 'corGaus' Variogram(object, distance, sig2, length.out, ...)
## S3 method for class 'corGaus' Variogram(object, distance, sig2, length.out, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corGaus
,
plot.Variogram
,
Variogram
cs1 <- corGaus(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
cs1 <- corGaus(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
This method function calculates the semi-variogram values
corresponding to the Linear correlation model, using the estimated
coefficients corresponding to object
, at the distances defined
by distance
.
## S3 method for class 'corLin' Variogram(object, distance, sig2, length.out, ...)
## S3 method for class 'corLin' Variogram(object, distance, sig2, length.out, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corLin
,
plot.Variogram
,
Variogram
cs1 <- corLin(15, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
cs1 <- corLin(15, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
This method function calculates the semi-variogram values
corresponding to the Rational Quadratic correlation model, using the
estimated coefficients corresponding to object
, at the
distances defined by distance
.
## S3 method for class 'corRatio' Variogram(object, distance, sig2, length.out, ...)
## S3 method for class 'corRatio' Variogram(object, distance, sig2, length.out, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corRatio
,
plot.Variogram
Variogram
cs1 <- corRatio(7, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
cs1 <- corRatio(7, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
This method function calculates the semi-variogram values
corresponding to the model defined in FUN
, using the estimated
coefficients corresponding to object
, at the distances defined
by distance
.
## S3 method for class 'corSpatial' Variogram(object, distance, sig2, length.out, FUN, ...)
## S3 method for class 'corSpatial' Variogram(object, distance, sig2, length.out, FUN, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
FUN |
a function of two arguments, the distance and the range
corresponding to |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corSpatial
,
Variogram
,
Variogram.default
,
Variogram.corExp
,
Variogram.corGaus
,
Variogram.corLin
,
Variogram.corRatio
,
Variogram.corSpher
,
plot.Variogram
cs1 <- corExp(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1, FUN = function(x, y) (1 - exp(-x/y)))[1:10,]
cs1 <- corExp(3, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1, FUN = function(x, y) (1 - exp(-x/y)))[1:10,]
This method function calculates the semi-variogram values
corresponding to the Spherical correlation model, using the estimated
coefficients corresponding to object
, at the distances defined
by distance
.
## S3 method for class 'corSpher' Variogram(object, distance, sig2, length.out, ...)
## S3 method for class 'corSpher' Variogram(object, distance, sig2, length.out, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances at
which the semi-variogram is to be calculated. Defaults to
|
sig2 |
an optional numeric value representing the process
variance. Defaults to |
length.out |
an optional integer specifying the length of the
sequence of distances to be used for calculating the semi-variogram,
when |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
corSpher
,
plot.Variogram
,
Variogram
cs1 <- corSpher(15, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
cs1 <- corSpher(15, form = ~ Time | Rat) cs1 <- Initialize(cs1, BodyWeight) Variogram(cs1)[1:10,]
This method function calculates the semi-variogram for an arbitrary
vector object
, according to the distances in distance
.
For each pair of elements in
object
, the
corresponding semi-variogram is . The semi-variogram is
useful for identifying and modeling spatial correlation structures in
observations with constant expectation and constant variance.
## Default S3 method: Variogram(object, distance, ...)
## Default S3 method: Variogram(object, distance, ...)
object |
a numeric vector with the values to be used for calculating the semi-variogram, usually a residual vector from a fitted model. |
distance |
a numeric vector with the pairwise distances
corresponding to the elements of |
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. The returned value inherits from class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
Variogram
,
Variogram.gls
,
Variogram.lme
,
plot.Variogram
fm1 <- lm(follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time), Ovary, subset = Mare == 1) Variogram(resid(fm1), dist(1:29))[1:10,]
fm1 <- lm(follicles ~ sin(2 * pi * Time) + cos(2 * pi * Time), Ovary, subset = Mare == 1) Variogram(resid(fm1), dist(1:29))[1:10,]
This method function calculates the semi-variogram for the residuals
from a gls
fit. The semi-variogram values are calculated for
pairs of residuals within the same group level, if a grouping factor
is present. If collapse
is different from "none"
, the
individual semi-variogram values are collapsed using either a robust
estimator (robust = TRUE
) defined in Cressie (1993), or the
average of the values within the same distance interval. The
semi-variogram is useful for modeling the error term correlation
structure.
## S3 method for class 'gls' Variogram(object, distance, form, resType, data, na.action, maxDist, length.out, collapse, nint, breaks, robust, metric, ...)
## S3 method for class 'gls' Variogram(object, distance, form, resType, data, na.action, maxDist, length.out, collapse, nint, breaks, robust, metric, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances between
residual pairs. If a grouping variable is present, only the
distances between residual pairs within the same group should be
given. If missing, the distances are calculated based on the
values of the arguments |
form |
an optional one-sided formula specifying the covariate(s)
to be used for calculating the distances between residual pairs and,
optionally, a grouping factor for partitioning the residuals (which
must appear to the right of a |
resType |
an optional character string specifying the type of
residuals to be used. If |
data |
an optional data frame in which to interpret the variables
in |
na.action |
a function that indicates what should happen when the
data contain |
maxDist |
an optional numeric value for the maximum distance used for calculating the semi-variogram between two residuals. By default all residual pairs are included. |
length.out |
an optional integer value. When |
collapse |
an optional character string specifying the type of
collapsing to be applied to the individual semi-variogram values. If
equal to |
nint |
an optional integer with the number of intervals to be
used when collapsing the semi-variogram values. Defaults to |
robust |
an optional logical value specifying if a robust
semi-variogram estimator should be used when collapsing the
individual values. If |
breaks |
an optional numeric vector with the breakpoints for the
distance intervals to be used in collapsing the semi-variogram
values. If not missing, the option specified in |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. If the semi-variogram values are collapsed, an extra
column, n.pairs
, with the number of residual pairs used in each
semi-variogram calculation, is included in the returned data frame. If
object
includes a corSpatial
element, a data frame with
its corresponding semi-variogram is included in the returned value, as
an attribute "modelVariog"
. The returned value inherits from
class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
gls
,
Variogram
,
Variogram.default
,
Variogram.lme
,
plot.Variogram
fm1 <- gls(weight ~ Time * Diet, BodyWeight) Vm1 <- Variogram(fm1, form = ~ Time | Rat) print(head(Vm1), digits = 3)
fm1 <- gls(weight ~ Time * Diet, BodyWeight) Vm1 <- Variogram(fm1, form = ~ Time | Rat) print(head(Vm1), digits = 3)
This method function calculates the semi-variogram for the
within-group residuals from an lme
fit. The semi-variogram
values are calculated for pairs of residuals within the same group. If
collapse
is different from "none"
, the individual
semi-variogram values are collapsed using either a robust estimator
(robust = TRUE
) defined in Cressie (1993), or the average of
the values within the same distance interval. The semi-variogram is
useful for modeling the error term correlation structure.
## S3 method for class 'lme' Variogram(object, distance, form, resType, data, na.action, maxDist, length.out, collapse, nint, breaks, robust, metric, ...)
## S3 method for class 'lme' Variogram(object, distance, form, resType, data, na.action, maxDist, length.out, collapse, nint, breaks, robust, metric, ...)
object |
an object inheriting from class |
distance |
an optional numeric vector with the distances between
residual pairs. If a grouping variable is present, only the
distances between residual pairs within the same group should be
given. If missing, the distances are calculated based on the
values of the arguments |
form |
an optional one-sided formula specifying the covariate(s)
to be used for calculating the distances between residual pairs and,
optionally, a grouping factor for partitioning the residuals (which
must appear to the right of a |
resType |
an optional character string specifying the type of
residuals to be used. If |
data |
an optional data frame in which to interpret the variables
in |
na.action |
a function that indicates what should happen when the
data contain |
maxDist |
an optional numeric value for the maximum distance used for calculating the semi-variogram between two residuals. By default all residual pairs are included. |
length.out |
an optional integer value. When |
collapse |
an optional character string specifying the type of
collapsing to be applied to the individual semi-variogram values. If
equal to |
nint |
an optional integer with the number of intervals to be
used when collapsing the semi-variogram values. Defaults to |
robust |
an optional logical value specifying if a robust
semi-variogram estimator should be used when collapsing the
individual values. If |
breaks |
an optional numeric vector with the breakpoints for the
distance intervals to be used in collapsing the semi-variogram
values. If not missing, the option specified in |
metric |
an optional character string specifying the distance
metric to be used. The currently available options are
|
... |
some methods for this generic require additional arguments. None are used in this method. |
a data frame with columns variog
and dist
representing,
respectively, the semi-variogram values and the corresponding
distances. If the semi-variogram values are collapsed, an extra
column, n.pairs
, with the number of residual pairs used in each
semi-variogram calculation, is included in the returned data frame. If
object
includes a corSpatial
element, a data frame with
its corresponding semi-variogram is included in the returned value, as
an attribute "modelVariog"
. The returned value inherits from
class Variogram
.
José Pinheiro and Douglas Bates [email protected]
Cressie, N.A.C. (1993), "Statistics for Spatial Data", J. Wiley & Sons.
lme
,
Variogram
,
Variogram.default
,
Variogram.gls
,
plot.Variogram
fm1 <- lme(weight ~ Time * Diet, data=BodyWeight, ~ Time | Rat) Variogram(fm1, form = ~ Time | Rat, nint = 10, robust = TRUE)
fm1 <- lme(weight ~ Time * Diet, data=BodyWeight, ~ Time | Rat) Variogram(fm1, form = ~ Time | Rat, nint = 10, robust = TRUE)
This function is a constructor for the varPower
class,
representing a power variance function structure. Letting
denote the variance covariate and
denote the variance function evaluated at
, the power
variance function is defined as
, where
is the variance
function coefficient. When a grouping factor is present, a different
is used for each factor level.
varPower(value, form, fixed)
varPower(value, form, fixed)
value |
an optional numeric vector, or list of numeric values,
with the variance function coefficients. |
form |
an optional one-sided formula of the form |
fixed |
an optional numeric vector, or list of numeric values,
specifying the values at which some or all of the coefficients in
the variance function should be fixed. If a grouping factor is
specified in |
a varPower
object representing a power variance function
structure, also inheriting from class varFunc
.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
varWeights.varFunc
,
coef.varPower
vf1 <- varPower(0.2, form = ~age|Sex)
vf1 <- varPower(0.2, form = ~age|Sex)
The inverse of the standard deviations corresponding to the variance
function structure represented by object
are returned.
varWeights(object)
varWeights(object)
object |
an object inheriting from class |
if object
has a weights
attribute, its value is
returned; else NULL
is returned.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
vf1 <- varPower(form=~age) vf1 <- Initialize(vf1, Orthodont) coef(vf1) <- 0.3 varWeights(vf1)[1:10]
vf1 <- varPower(form=~age) vf1 <- Initialize(vf1, Orthodont) coef(vf1) <- 0.3 varWeights(vf1)[1:10]
If object
includes a varStruct
component, the inverse of
the standard deviations of the variance function structure represented
by the corresponding varFunc
object are returned; else, a
vector of ones of length equal to the number of observations in the
data frame used to fit the associated linear model is returned.
## S3 method for class 'glsStruct' varWeights(object)
## S3 method for class 'glsStruct' varWeights(object)
object |
an object inheriting from class |
if object
includes a varStruct
component, a vector with
the corresponding variance weights; else, or a vector of ones.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
If object
includes a varStruct
component, the inverse of
the standard deviations of the variance function structure represented
by the corresponding varFunc
object are returned; else, a
vector of ones of length equal to the number of observations in the
data frame used to fit the associated linear mixed-effects model is
returned.
## S3 method for class 'lmeStruct' varWeights(object)
## S3 method for class 'lmeStruct' varWeights(object)
object |
an object inheriting from class |
if object
includes a varStruct
component, a vector with
the corresponding variance weights; else, or a vector of ones.
José Pinheiro and Douglas Bates [email protected]
Pinheiro, J.C., and Bates, D.M. (2000) "Mixed-Effects Models in S and S-PLUS", Springer.
The Wafer
data frame has 400 rows and 4 columns.
This data frame contains the following columns:
a factor with levels
1
2
3
4
5
6
7
8
9
10
a factor with levels
1
2
3
4
5
6
7
8
a numeric vector
a numeric vector
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
The Wheat
data frame has 48 rows and 4 columns.
This data frame contains the following columns:
an ordered factor with levels
3
< 1
< 2
< 4
< 5
< 6
< 8
< 9
< 7
< 12
< 11
< 10
a numeric vector
a numeric vector
a numeric vector
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.
The Wheat2
data frame has 224 rows and 5 columns.
This data frame contains the following columns:
an ordered factor with levels
4
< 2
< 3
< 1
a factor with levels
ARAPAHOE
BRULE
BUCKSKIN
CENTURA
CENTURK78
CHEYENNE
CODY
COLT
GAGE
HOMESTEAD
KS831374
LANCER
LANCOTA
NE83404
NE83406
NE83407
NE83432
NE83498
NE83T12
NE84557
NE85556
NE85623
NE86482
NE86501
NE86503
NE86507
NE86509
NE86527
NE86582
NE86606
NE86607
NE86T666
NE87403
NE87408
NE87409
NE87446
NE87451
NE87457
NE87463
NE87499
NE87512
NE87513
NE87522
NE87612
NE87613
NE87615
NE87619
NE87627
NORKAN
REDLAND
ROUGHRIDER
SCOUT66
SIOUXLAND
TAM107
TAM200
VONA
a numeric vector
a numeric vector
a numeric vector
Pinheiro, J. C. and Bates, D. M. (2000), Mixed-Effects Models in S and S-PLUS, Springer, New York.