pigs.lm <- lm(log(conc) ~ source * factor(percent), data = pigs)
(jt <- joint_tests(pigs.lm)) ## will be same as type III ANOVA
### Estimable functions associated with "percent"
attr(jt, "est.fcns") $ "percent"
joint_tests(pigs.lm, weights = "outer") ## differently weighted
joint_tests(pigs.lm, by = "source") ## separate joint tests of 'percent'
### Comparisons with type III tests in SAS
toy = data.frame(
treat = rep(c("A", "B"), c(4, 6)),
female = c(1, 0, 0, 1, 0, 0, 0, 1, 1, 0 ),
resp = c(17, 12, 14, 19, 28, 26, 26, 34, 33, 27))
toy.fac = lm(resp ~ treat * factor(female), data = toy)
toy.cov = lm(resp ~ treat * female, data = toy)
# (These two models have identical fitted values and residuals)
# -- SAS output we'd get with toy.fac --
## Source DF Type III SS Mean Square F Value Pr > F
## treat 1 488.8928571 488.8928571 404.60 <.0001
## female 1 78.8928571 78.8928571 65.29 0.0002
## treat*female 1 1.7500000 1.7500000 1.45 0.2741
#
# -- SAS output we'd get with toy.cov --
## Source DF Type III SS Mean Square F Value Pr > F
## treat 1 252.0833333 252.0833333 208.62 <.0001
## female 1 78.8928571 78.8928571 65.29 0.0002
## female*treat 1 1.7500000 1.7500000 1.45 0.2741
joint_tests(toy.fac)
joint_tests(toy.cov) # female is regarded as a 2-level factor by default
## Treat 'female' as a numeric covariate (via cov.keep = 0)
## ... then tests depend on where we center things
# Center around the mean
joint_tests(toy.cov, cov.keep = 0, cov.reduce = make.meanint(delta = 1))
# Center around zero (like SAS's results for toy.cov)
joint_tests(toy.cov, cov.keep = 0, cov.reduce = make.symmint(ctr = 0, delta = 1))
# Center around 0.5 (like SAS's results for toy.fac)
joint_tests(toy.cov, cov.keep = 0, cov.reduce = range)
### Example with empty cells and confounded effects
low3 <- unlist(attr(ubds, "cells")[1:3])
ubds.lm <- lm(y ~ A*B*C, data = ubds, subset = -low3)
# Show overall joint tests by C:
ref_grid(ubds.lm, by = "C") |> contrast("consec") |> test(joint = TRUE)
# Break each of the above into smaller components:
joint_tests(ubds.lm, by = "C")
Run the code above in your browser using DataLab