Description Usage Arguments Value Note Author(s) References Examples
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.
1 2 3 4 5 6 7 8 9 |
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 |
object |
an object of class |
modelType2Plot |
a character letter, "A", "B", "C", or "D", to indicate which model, with its associated fitted lines (abline), to plot. |
... |
not used. |
Returns an object of class "sla", which is a list containing the following components:
Call |
model call |
INPUT.df |
input data frame |
Summary of Input Data Frame |
produced from the generic function summary(). |
Mod.A |
an object of class "lm" for the fit of Model A. |
Mod.B |
an object of class "lm" for the fit of Model B. |
Mod.C |
an object of class "lm" for the fit of Model C. |
Mod.D |
an object of class "lm" for the fit of Model D. |
Fit.Table |
a data frame containing a description of the fit, number of parameters estimated, residual degrees of freedom, residual sum of squares, and residual mean square for each model "lm" fit, i.e., for models A, B, C and D. |
Test.Table |
a data frame containing a description of three tests of (reduced) models B, C, and D vs. the (full) model A, the degrees of freedom associated with the anova() comparison of the reduced and full models [note: always 2, 1, and 1], the difference between the residual sums of squares between the reduced and full models, the F statistic associated with the test, and the probability associated with the corresponding F statistic for the test. |
Fit.Table.Pretty |
a data frame containing essentially the same information as in Fit.Table but displayed in a prettier format. |
Test.Table.Pretty |
a data frame containing essentially the same information as in Test.Table but displayed in a prettier format. |
(1) The hellung data frame with conc and diameter raw values is available in the ISwR library from Dalgaard P (2002) Introductory Statistics with R. Springer.
(2) Simulated data sets (without setting the seed) using the code provided in the examples yield the desired outcomes 95 percent of the time.
W Greg Alvord
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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')
|
Call: sla.default(facxy = eqslo)
Coefficients for Models A, B, C and D:
Model A:
Int_1 Slo_1 Int_2 Slo_2
1.2 2.6 11.6 2.4
Model B:
Com_Int Com_Slo
6.4 2.5
Model C:
Int_1 Int_2 Com_Slo
1.5 11.3 2.5
Model D:
Com_Int Slo_1 Slo_2
6.400000 1.181818 3.818182
Call: sla.default(facxy = eqslo)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 6 3.60 0.60
2 Mod B: Com I,Com S 2 8 243.90 30.49
3 Mod C: Ind I,Com S 3 7 3.80 0.54
4 Mod D: Com I,Ind S 3 7 52.76 7.54
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 240.30 200.25 0.0000
2 Ho: Equiv Slopes 1 0.20 0.33 0.5847
3 Ho: Equiv Inters 1 49.16 81.94 0.0001
$names
[1] "Call" "INPUT.df"
[3] "Summary of Input Data Frame" "Mod.A"
[5] "Mod.B" "Mod.C"
[7] "Mod.D" "Fit.Table"
[9] "Test.Table" "Fit.Table.Pretty"
[11] "Test.Table.Pretty"
$class
[1] "sla"
Call:
lm(formula = y ~ X.C - 1)
Coefficients:
X.Ci1 X.Ci2 X.Cx
1.5 11.3 2.5
Call:
lm(formula = y ~ X.C - 1)
Residuals:
Min 1Q Median 3Q Max
-1.000 -0.450 0.100 0.425 1.000
Coefficients:
Estimate Std. Error t value Pr(>|t|)
X.Ci1 1.5000 0.5940 2.525 0.0395 *
X.Ci2 11.3000 0.5940 19.023 2.76e-07 ***
X.Cx 2.5000 0.1648 15.174 1.30e-06 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.7368 on 7 degrees of freedom
Multiple R-squared: 0.9983, Adjusted R-squared: 0.9976
F-statistic: 1411 on 3 and 7 DF, p-value: 4.259e-10
Call: sla.default(facxy = eqint)
Coefficients for Models A, B, C and D:
Model A:
Int_1 Slo_1 Int_2 Slo_2
1.20 2.60 1.06 -0.02
Model B:
Com_Int Com_Slo
1.13 1.29
Model C:
Int_1 Int_2 Com_Slo
5.13 -2.87 1.29
Model D:
Com_Int Slo_1 Slo_2
1.13000000 2.61909091 -0.03909091
Call: sla.default(facxy = eqint)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 6 2.44 0.41
2 Mod B: Com I,Com S 2 8 196.76 24.59
3 Mod C: Ind I,Com S 3 7 36.76 5.25
4 Mod D: Com I,Ind S 3 7 2.44 0.35
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 194.32 239.31 0.0000
2 Ho: Equiv Slopes 1 34.32 84.54 0.0001
3 Ho: Equiv Inters 1 0.01 0.02 0.8871
$names
[1] "Call" "INPUT.df"
[3] "Summary of Input Data Frame" "Mod.A"
[5] "Mod.B" "Mod.C"
[7] "Mod.D" "Fit.Table"
[9] "Test.Table" "Fit.Table.Pretty"
[11] "Test.Table.Pretty"
$class
[1] "sla"
Call:
lm(formula = y ~ X.D - 1)
Coefficients:
X.D X.Di1x X.Di2x
1.13000 2.61909 -0.03909
Call:
lm(formula = y ~ X.D - 1)
Residuals:
Min 1Q Median 3Q Max
-0.98727 -0.10727 0.00682 0.21977 0.77455
Coefficients:
Estimate Std. Error t value Pr(>|t|)
X.D 1.13000 0.43829 2.578 0.0366 *
X.Di1x 2.61909 0.14366 18.231 3.7e-07 ***
X.Di2x -0.03909 0.14366 -0.272 0.7934
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.591 on 7 degrees of freedom
Multiple R-squared: 0.9949, Adjusted R-squared: 0.9927
F-statistic: 455.8 on 3 and 7 DF, p-value: 2.191e-08
Call: sla.default(facxy = whiteside)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 52 5.43 0.10
2 Mod B: Com I,Com S 2 54 39.99 0.74
3 Mod C: Ind I,Com S 3 53 6.77 0.13
4 Mod D: Com I,Ind S 3 53 20.02 0.38
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 34.57 165.67 0e+00
2 Ho: Equiv Slopes 1 1.35 12.89 7e-04
3 Ho: Equiv Inters 1 14.59 139.88 0e+00
Call: sla.default(facxy = hellunglog)
Coefficients for Models A, B, C and D:
Model A:
Int_1 Slo_1 Int_2 Slo_2
1.63134359 -0.05319626 1.63476114 -0.05967671
Model B:
Com_Int Com_Slo
1.62731289 -0.05451464
Model C:
Int_1 Int_2 Com_Slo
1.6421324 1.6138945 -0.0553927
Model D:
Com_Int Slo_1 Slo_2
1.63251608 -0.05343178 -0.05922119
Call: sla.default(facxy = hellunglog)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 47 0.00 0
2 Mod B: Com I,Com S 2 49 0.01 0
3 Mod C: Ind I,Com S 3 48 0.00 0
4 Mod D: Com I,Ind S 3 48 0.00 0
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 0.01 58.75 0.0000
2 Ho: Equiv Slopes 1 0.00 1.81 0.1853
3 Ho: Equiv Inters 1 0.00 0.02 0.8859
Call: sla.default(facxy = esdf)
Coefficients for Models A, B, C and D:
Model A:
Int_1 Slo_1 Int_2 Slo_2
-0.08734404 0.19831531 6.97037298 0.19924832
Model B:
Com_Int Com_Slo
3.4415145 0.1987818
Model C:
Int_1 Int_2 Com_Slo
-0.0992400 6.9822689 0.1987818
Model D:
Com_Int Slo_1 Slo_2
3.44151447 0.09349773 0.30406590
Call: sla.default(facxy = esdf)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 96 115.51 1.20
2 Mod B: Com I,Com S 2 98 1369.21 13.97
3 Mod C: Ind I,Com S 3 97 115.51 1.19
4 Mod D: Com I,Ind S 3 97 417.58 4.30
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 1253.70 520.98 0.0000
2 Ho: Equiv Slopes 1 0.00 0.00 0.9512
3 Ho: Equiv Inters 1 302.07 251.05 0.0000
Call: sla.default(facxy = eidf)
Coefficients for Models A, B, C and D:
Model A:
Int_1 Slo_1 Int_2 Slo_2
0.03787834 0.02713860 -0.07378883 0.24299515
Model B:
Com_Int Com_Slo
-0.01795525 0.13506688
Model C:
Int_1 Int_2 Com_Slo
-2.7142926 2.6783821 0.1350669
Model D:
Com_Int Slo_1 Slo_2
-0.01795525 0.02879703 0.24133672
Call: sla.default(facxy = eidf)
Summary of ANCOVA Tests. . .
Description of Fits for 4 ANCOVA Models
Description of Fit Np Res df Res SS Res MS
1 Mod A: Ind I,Ind S 4 96 120.87 1.26
2 Mod B: Com I,Com S 2 98 1090.48 11.13
3 Mod C: Ind I,Com S 3 97 363.45 3.75
4 Mod D: Com I,Ind S 3 97 120.95 1.25
ANCOVA Tests: Two Groups/Straight Line Fits
Test df SS F Stat prob
1 Ho: Equiv D.Sets 2 969.60 385.04 0.0000
2 Ho: Equiv Slopes 1 242.58 192.66 0.0000
3 Ho: Equiv Inters 1 0.08 0.06 0.8069
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.