簡體   English   中英

如何通過交互從 GLM 獲取 Tukey 緊湊字母顯示

[英]How to obtain Tukey compact letter display from a GLM with interactions

我已經用廣義線性模型分析了一組數據,該模型在三向交互中具有三個分類因子(因子A、因子B、因子C)和一個簡單地添加到模型中的第四個連續因子(因子D)。 我試圖從模型中獲取一組 Tukey 字母組(即緊湊字母顯示),但還沒有找到成功包含交互的方法。 我對包含 factorD 不感興趣,只對交互中的三個感興趣。

我已經得到了 Tukey 調整的成對比較:

lsmeans(my.glm, factorA*factorB*factorC)

但是我無法弄清楚如何從中生成緊湊的字母顯示。 它可以用multcomp包來完成,但我只能找到使用該包的主要效果來做到這一點的方法,而不是交互。

然后我嘗試了agricolae包,作為這篇文章( https://stats.stackexchange.com/questions/31547/how-to-obtain-the-results-of-a-tukey-hsd-post-hoc-test- in-a-table-showing-groupe ) 討論這應該有效。 但是,按照該答案中的說明進行操作導致來自 HSD.test 的非功能性響應。 具體來說,我可以讓主效應測試正常工作,例如HSD.test(my.glm,"factorA")但我無法讓交互工作。 我試過這個:

intxns<-with(my.data, interaction(factorA,factorB,factorC))
HSD.test(my.glm,"intxns",group=TRUE)

但是得到一個錯誤,表明 HSD.test 函數沒有將“intxns”識別為有效對象,它看起來像這樣(另外,我檢查了 intxns 對象,它看起來不錯,行數與殘差數匹配我的glm):

Name: inxtns
 factorA factorB factorC factorD

如果我只是在 HSD.test 函數調用中的 factor 字段中放入廢話,我會得到同樣的錯誤。 我檢查了 inxtns 對象,它看起來不錯,行數與殘留數相匹配。 agricolae注釋實際上並未涵蓋 HSD.test 中交互的使用,但我認為它可以工作。

有誰知道如何讓 HSD.test 與交互一起工作? 或者您是否有任何其他功能可以為具有交互功能的 glm 生成緊湊的字母顯示?

我已經為此工作了好幾天,但一直無法找到解決方案,希望我沒有遺漏一些明顯的東西。

謝謝!

我不知道您是如何指定 glm 模型的,但對於HSD.test ,它希望將特定處理名稱與 glm 公式和數據框中指定的相同名稱相匹配。 這就是為什么您的主效應factorA會起作用,而不是 3 向相互作用。 對於交互的多重比較測試,我發現單獨生成交互並將它們作為附加列添加到數據框中最容易。 然后可以使用為交互編碼的新變量來指定 glm 模型。

例如,

set.seed(42)
glm.dat <- data.frame(y = rnorm(1000), factorA = sample(letters[1:2], 
   size = 1000, replace = TRUE),
 factorB = sample(letters[1:2], size = 1000, replace = TRUE),
 factorC = sample(letters[1:2], size = 1000, replace = TRUE))

# Generate interactions explicitly and add them to the data.frame
glm.dat$factorAB <- with(glm.dat, interaction(factorA, factorB))
glm.dat$factorAC <- with(glm.dat, interaction(factorA, factorC))
glm.dat$factorBC <- with(glm.dat, interaction(factorB, factorC))
glm.dat$factorABC <- with(glm.dat, interaction(factorA, factorB, factorC))

# General linear model 
 glm.mod <- glm(y ~ factorA + factorB + factorC +  factorAB + factorAC + 
   factorBC + factorABC, family = 'gaussian', data = glm.dat) 

# Multiple comparison test

library(agricolae)
comp <- HSD.test(glm.mod, trt = "factorABC", group = TRUE)

給予

comp$groups giving

    trt        means M
 1 a.a.a  0.070052189 a
 2 a.b.b  0.035684571 a
 3 b.a.a  0.020517535 a
 4 b.b.b -0.008153257 a
 5 a.b.a -0.036136140 a
 6 a.a.b -0.078891136 a
 7 b.a.b -0.080845419 a
 8 b.b.a -0.115808772 a

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM