Learn R Programming

RcmdrPlugin.TeachStat (version 1.1.0)

aovreml: ANOVA with random effects using the (REstricted) Maximum Likelihood method.

Description

Print the ANOVA table with random effects and compute the point estimations of the variance components using the maximum likelihood method or the REstricted Maximum Likelihood (REML) method. It also provides some confidence intervals.

Usage

aovreml(formula, data = NULL, Lconfint = FALSE, REML = TRUE, ...)

Arguments

formula

data

Lconfint

REML

Value

A list

See Also

aov, lmer, aovremm.

Examples

Run this code
# NOT RUN {
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (formula, data = NULL, Lconfint = FALSE, REML = TRUE, 
    ...) 
{
    vars <- all.vars(formula)
    formulaaov <- as.formula(paste(vars[1], "~", vars[2]))
    ANOV <- aov(formulaaov, data, ...)
    .ANOV <- summary(ANOV)
    cat("-------------------------------")
    cat("\n", gettext("ANOVA table", domain = "R-RcmdrPlugin.TeachStat"), 
        ":\n", sep = "")
    print(.ANOV)
    cat("\n-------------------------------\n")
    .sol <- lme4::lmer(formula, data = data, REML = REML, ...)
    .varcor <- lme4::VarCorr(.sol)
    .sighat2 <- unname(attr(.varcor, "sc"))^2
    .sighatalph2 <- unname(attr(.varcor[[vars[2]]], "stddev"))^2
    .prop <- .sighatalph2/(.sighatalph2 + .sighat2)
    estim <- c(.sighat2, .sighatalph2, .prop)
    names(estim) <- c("var (Error)", "var (Effect)", "% var (Effect)")
    cat("\n", gettext("Components of Variance", domain = "R-RcmdrPlugin.TeachStat"), 
        " (", lme4::methTitle(.sol@devcomp$dims), "):\n", sep = "")
    print(estim)
    if (Lconfint) {
        cat("\n", gettext("Confidence intervals", domain = "R-RcmdrPlugin.TeachStat"), 
            ":\n", sep = "")
        print(confint(.sol, oldNames = FALSE))
    }
    return(invisible(list(model = .sol, estimation = estim)))
  }
# }

Run the code above in your browser using DataLab