check.hom: Check linear models for homoscedasticity

View source: R/check.hom.R

check.homR Documentation

Check linear models for homoscedasticity

Description

This function takes a linear model object as an argument and checks whether the residuals are homoscedastic, in relation to a stratification variable or covariate, that is given as an argument.

Usage

check.hom(obj, var, alternative)

Arguments

obj

a linear model object fitted with lm()

var

a vector containing a stratification variable. If missing, the fitted values from obj are taken as a covariate

alternative

The null (homogeneous variances) is tested against the alternative, that is (i) different variances for each level of the stratification variable given as argument ("varIdent"), (ii) variance is a power function of a covariate, that is given as argument ("varPower"; the fitted values are taken as the covariate, in case the argument 'var' is missing and (iii) the variance is an exponential function of a covariate, that is given as argument ("varExp"; the fitted values are taken as the covariate, in case the argument 'var' is missing)

Details

The function fits a gls with same structure as the input model, together with a heteroscedastic gls, where residuals are allowed to be heteroscedastic, according to the 'alternative' argument. The two models are compared by a LRT

Value

LRT

the value of LRT

LRT

the P-value of LRT

aovtable

a summary table for the LRT

modHet

the gls object containing the heteroscedastic fit

Author(s)

Andrea Onofri

Examples

fileName <- "https://www.casaonofri.it/_datasets/FGP_rape.csv"
library(statforbiology)
dataset <- read.csv(fileName)
dataset[,1:5] <- lapply(dataset[,1:5], factor)
mod <- lm(FGP ~ Genotype * Run, data = dataset)
check <- check.hom(mod, Run)
check$aovtable

statforbiology documentation built on Oct. 30, 2024, 9:13 a.m.