R語言
se.contrast
位於 stats
包(package)。 說明
返回 aov
對象中一個或多個對比的標準錯誤。
用法
se.contrast(object, ...)
## S3 method for class 'aov'
se.contrast(object, contrast.obj,
coef = contr.helmert(ncol(contrast))[, 1],
data = NULL, ...)
參數
object |
合適的配合,通常來自 |
contrast.obj |
要求標準誤差的對比。這可以通過列表或矩陣來指定。單個對比可以通過給出要對比的單元的邏輯向量列表來指定。多重對比應由矩陣指定,矩陣的每一列都是數值對比向量(總和為零)。 |
coef |
當 |
data |
用於評估 |
... |
傳入或傳出其他方法的進一步參數。 |
細節
對比通常用於測試某些均值是否顯著不同;使用 se.contrast
比直接從係數計算它們更容易。
在多層模型中,對比可能出現在多個層中,在這種情況下,標準誤差在最低層中計算,並根據效率和各層之間的比較進行調整。 (請參閱 aov
幫助中有關使用正交對比的注釋中的注釋。)此類標準錯誤通常是保守的。
通過調用 contrasts
並按因子對列進行索引,可以找到適合與 coef
一起使用的矩陣。
值
給出每個對比的標準誤差的向量。
例子
## From Venables and Ripley (2002) p.165.
N <- c(0,1,0,1,1,1,0,0,0,1,1,0,1,1,0,0,1,0,1,0,1,1,0,0)
P <- c(1,1,0,0,0,1,0,1,1,1,0,0,0,1,0,1,1,0,0,1,0,1,1,0)
K <- c(1,0,0,1,0,1,1,0,0,1,0,1,0,1,1,0,0,0,1,1,1,0,1,0)
yield <- c(49.5,62.8,46.8,57.0,59.8,58.5,55.5,56.0,62.8,55.8,69.5,
55.0, 62.0,48.8,45.5,44.2,52.0,51.5,49.8,48.8,57.2,59.0,53.2,56.0)
npk <- data.frame(block = gl(6,4), N = factor(N), P = factor(P),
K = factor(K), yield = yield)
## Set suitable contrasts.
options(contrasts = c("contr.helmert", "contr.poly"))
npk.aov1 <- aov(yield ~ block + N + K, data = npk)
se.contrast(npk.aov1, list(N == "0", N == "1"), data = npk)
# or via a matrix
cont <- matrix(c(-1,1), 2, 1, dimnames = list(NULL, "N"))
se.contrast(npk.aov1, cont[N, , drop = FALSE]/12, data = npk)
## test a multi-stratum model
npk.aov2 <- aov(yield ~ N + K + Error(block/(N + K)), data = npk)
se.contrast(npk.aov2, list(N == "0", N == "1"))
## an example looking at an interaction contrast
## Dataset from R.E. Kirk (1995)
## 'Experimental Design: procedures for the behavioral sciences'
score <- c(12, 8,10, 6, 8, 4,10,12, 8, 6,10,14, 9, 7, 9, 5,11,12,
7,13, 9, 9, 5,11, 8, 7, 3, 8,12,10,13,14,19, 9,16,14)
A <- gl(2, 18, labels = c("a1", "a2"))
B <- rep(gl(3, 6, labels = c("b1", "b2", "b3")), 2)
fit <- aov(score ~ A*B)
cont <- c(1, -1)[A] * c(1, -1, 0)[B]
sum(cont) # 0
sum(cont*score) # value of the contrast
se.contrast(fit, as.matrix(cont))
(t.stat <- sum(cont*score)/se.contrast(fit, as.matrix(cont)))
summary(fit, split = list(B = 1:2), expand.split = TRUE)
## t.stat^2 is the F value on the A:B: C1 line (with Helmert contrasts)
## Now look at all three interaction contrasts
cont <- c(1, -1)[A] * cbind(c(1, -1, 0), c(1, 0, -1), c(0, 1, -1))[B,]
se.contrast(fit, cont) # same, due to balance.
rm(A, B, score)
## multi-stratum example where efficiencies play a role
## An example from Yates (1932),
## a 2^3 design in 2 blocks replicated 4 times
Block <- gl(8, 4)
A <- factor(c(0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1))
B <- factor(c(0,0,1,1,0,0,1,1,0,1,0,1,1,0,1,0,0,0,1,1,
0,0,1,1,0,0,1,1,0,0,1,1))
C <- factor(c(0,1,1,0,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,
1,0,1,0,0,0,1,1,1,1,0,0))
Yield <- c(101, 373, 398, 291, 312, 106, 265, 450, 106, 306, 324, 449,
272, 89, 407, 338, 87, 324, 279, 471, 323, 128, 423, 334,
131, 103, 445, 437, 324, 361, 302, 272)
aovdat <- data.frame(Block, A, B, C, Yield)
fit <- aov(Yield ~ A + B * C + Error(Block), data = aovdat)
cont1 <- c(-1, 1)[A]/32 # Helmert contrasts
cont2 <- c(-1, 1)[B] * c(-1, 1)[C]/32
cont <- cbind(A = cont1, BC = cont2)
colSums(cont*Yield) # values of the contrasts
se.contrast(fit, as.matrix(cont))
# comparison with lme
library(nlme)
fit2 <- lme(Yield ~ A + B*C, random = ~1 | Block, data = aovdat)
summary(fit2)$tTable # same estimates, similar (but smaller) se's.
也可以看看
相關用法
- R setNames 設置對象中的名稱
- R selfStart 構建自啟動非線性模型
- R stlmethods STL 對象的方法
- R summary.nls 總結非線性最小二乘模型擬合
- R summary.manova 多元方差分析的匯總方法
- R summary.lm 總結線性模型擬合
- R smooth Tukey 的(運行中值)平滑
- R screeplot 屏幕圖
- R sortedXyData 創建一個sortedXyData對象
- R sigma 提取殘餘標準差“Sigma”
- R stat.anova GLM 方差分析統計
- R scatter.smooth 黃土擬合的平滑曲線散點圖
- R splinefun 插值樣條曲線
- R spec.taper 通過餘弦鍾錐化時間序列
- R summary.princomp 主成分分析的匯總方法
- R symnum 符號數字編碼
- R summary.aov 方差模型分析總結
- R stepfun Step Functions - 創建和類
- R shapiro.test 夏皮羅-威爾克正態性檢驗
- R spec.pgram 通過平滑周期圖估計時間序列的譜密度
- R spec.ar 通過 AR Fit 估計時間序列的頻譜密度
- R smooth.spline 擬合平滑樣條曲線
- R supsmu 弗裏德曼的超級平滑
- R stl Loess 時間序列的季節分解
- R summary.glm 廣義線性模型擬合總結
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Standard Errors for Contrasts in Model Terms。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。