Learn R Programming

sla (version 0.1)

sla: Two-Group, Straight-Line ANCOVA: Four Models

Description

Fits four linear models ("A", "B", "C", and "D") for the two-group, straight-line ANCOVA problem. (A) Model "A", the full model - fits two intercepts and two slopes (separate intercepts and slopes for each group); (B) Model "B", a reduced model - fits single intercept and single slope to all the data (ignoring group designation); (C) Model "C", a reduced model - fits two different intercepts and a single, common slope; (D) Model "D", a reduced model - fits a single, common intercept and two different slopes.

Usage

sla(facxy, ...) "sla"(facxy, ...) "print"(x, ...) "summary"(object, ...) "plot"(x, modelType2Plot = "A", ...)

Arguments

facxy
a data frame with three columns in specific order: (1) factor (Group) variable, (2) numeric x-axis predictor, regressor (or independent) variable, and (3) numeric y-axis criterion (or dependent) variable.
x
an object of class 'sla', i.e., a list containing data frames, coefficients, and fitted models.
object
an object of class 'sla', i.e., a list containing data frames, coefficients, and fitted models.
modelType2Plot
a character letter, "A", "B", "C", or "D", to indicate which model, with its associated fitted lines (abline), to plot.
...
not used.

Value

Returns an object of class "sla", which is a list containing the following components: Returns an object of class "sla", which is a list containing the following components:

References

Dalgaard P (2002) Introductory Statistics with R. Springer. Draper NR and Smith H (1998) Applied Regression Analysis. 3rd ed. Wiley. Fox J (2008) Applied Regression Analysis and General Linear Models, 2nd ed. Sage. Fox J and Weisberg S (2011) An R Companion to Applied Regression, 2nd ed. Sage. Searle SR (1971) Linear Models, Wiley. Venables WN and Ripley BD (2002) Modern Applied Statistics with S. 4th ed. Springer.

Examples

Run this code
data(eqslo)
eqsloObj <- sla(eqslo)
eqsloObj
summary(eqsloObj)
attributes(eqsloObj)
eqsloObj$Mod.C # best fitting reduced model, equivalent slopes, different intercepts
summary(eqsloObj$Mod.C) # lm summary of Model C
plot(eqsloObj, mod = 'C') # plot of data eqslo, fitted lines with equal slopes, different intercepts
##
data(eqint)
eqintObj <- sla(eqint)
eqintObj
summary(eqintObj)
attributes(eqintObj)
eqintObj$Mod.D # best fitting reduced model, equivalent intercepts, different slopes
summary(eqintObj$Mod.D) # lm summary of Model D
plot(eqintObj, mod = 'D') # plot of data eqint, fitted lines with equal intercepts, different slopes
##
## See MASS, 4th ed., pp 139-144 for ANCOVA of whiteside data
##
library(MASS)
data(whiteside) 
whitesideObj <- sla(whiteside)
summary(whitesideObj) # See MASS, 4th ed., pp 139-144 for ANCOVA of whiteside data
par(mfrow = c(2,2))
plot(whitesideObj, "A") # different intercepts and different slopes
plot(whitesideObj, "B") # common intercept and common slope
plot(whitesideObj, "C") # different intercepts, common slope
plot(whitesideObj, "D") # different slopes, common intercept
##
## See Dalgaard, pp. 172-182 for ANCOVA of (log10) hellung data
##
data(hellunglog)
hellunglogObj <- sla(hellunglog)
hellunglogObj
summary(hellunglogObj) # See Dalgaard, pp. 172-182 for ANCOVA of (log10) hellung data
par(mfrow = c(2,2))
plot(hellunglogObj, "A") # different intercepts and different slopes
plot(hellunglogObj, "B") # common intercept and common slope
plot(hellunglogObj, "C") # different intercepts, common slope
plot(hellunglogObj, "D") # different slopes, common intercept
##
## Simulate data for common slope, different intercepts 
## 
group <- c(rep('A', 50), rep('B', 50))
x <- rep(1:50, 2)
set.seed(50) #
y1 <- rnorm(50) + 4*.05*x[1:50]
set.seed(100)
y2 <- rnorm(50) + 7 + y1
y <- c(y1, y2)
esdf <- data.frame(group, x, y)
esdfObj <- sla(esdf)
esdfObj
summary(esdfObj)
par(mfrow = c(2,2))
plot(esdfObj, mod = 'A')
plot(esdfObj, mod = 'B')
plot(esdfObj, mod = 'C')
plot(esdfObj, mod = 'D')
##
## Simulate data for common intercept, different slopes
## 
group <- c(rep('A', 50), rep('B', 50))
x <- rep(1:50, 2)
set.seed(49) # 
y1 <- rnorm(50) + 1*.03*x[1:50]
set.seed(99) #
y2 <- rnorm(50) + 1*.25*x[51:100]
y <- c(y1, y2)
eidf <- data.frame(group, x, y)
eidfObj <- sla(eidf)
eidfObj
summary(eidfObj)
par(mfrow = c(2,2))
plot(eidfObj, mod = 'A')
plot(eidfObj, mod = 'B')
plot(eidfObj, mod = 'C')
plot(eidfObj, mod = 'D')

Run the code above in your browser using DataLab