“ 如何判断整体交互作用是否有统计学意义:P for interaction大小的计算”
方法一:
model1=lm(mpg~cyl disp hp wt,data=mtcars)
model2=lm(mpg~cyl disp hp wt disp*cyl,data=mtcars)
library(lmtest)
lrtest(model1,model2)
# Likelihood ratio test
# Model 1: mpg ~ cyl disp hp wt
# Model 2: mpg ~ cyl disp
# Df LogLik Df Chisq Pr(>Chisq)
# 1 6 -72.169
# 2 7 -68.269 1 7.7987 0.005228**
# ---
# Signif. codes: 0 '***’ 0.001 '**’ 0.01 '*’ 0.05 '.’ 0.1 ' ’ 1
方法二:
(1)提取两个模型各自的对数似然;
logLik(model1)
# 'log Lik.' -72.1688 (df=6)
logLik(model2)
# 'log Lik.' -68.26944 (df=7)
(2)计算二者的对数似然比;
LLR <- -2*(logLik(model1) -logLik(model2))
(3)与自由度为1(两个模型只差了1个变量:有无交互项)的卡方分布做比较;
1-pchisq(as.numeric(LLR),df=1)# P value for the LLR test
# [1] 0.005228312
可以看出来两种计算方法的结果一样。
联系客服