2
雖然lmPerm :: LMP(Y〜X * F,中心= TRUE)對LM(Y〜X * F):非常不同的係數
lmp(y~x, center=TRUE,perm="Prob")
lm(y~x)
給出x
和y
是定量變量類似的結果,
lmp(y~x*f, center=TRUE,perm="Prob")
lm(y~x*f)
不同,其中f
是一個因素變量。
require(lmPerm)
## Test data
x <- 1:1000
set.seed(1000)
y1 <- x*2+runif(1000,-100,100)
y1 <- y1+min(y1)
y2 <- 0.75*y1 + abs(rnorm(1000,50,10))
datos <- data.frame(x =c(x,x),y=c(y1,y2),tipo=factor(c(rep("A",1000),rep("B",1000))))
然後如預期,
coefficients(lmp(y~x,perm="Prob",data=datos,center=FALSE))
# [1] "Settings: unique SS "
# (Intercept) x
# -37.69542 1.74498
coefficients(lm(y~x,data=datos))
# (Intercept) x
# -37.69542 1.74498
但
fit.lmp <- lmp(y~x*tipo,perm="Prob",data=datos,center=FALSE)
fit.lm <- lm(y~x*tipo, data=datos)
coefficients(fit.lm)
# (Intercept) x tipoB x:tipoB
# -71.1696395 1.9933827 66.9484438 -0.4968049
coefficients(fit.lmp)
# (Intercept) x tipo1 x:tipo1
# -37.6954176 1.7449803 -33.4742219 0.2484024
我明白係數從lm()
:
coefficients(fit.lm)[1:2] # coefficients for Level A
# (Intercept) x
# -71.169640 1.993383
coefficients(fit.lm)[1:2] + coefficients(fit.lm)[3:4] # coefficients for Level B
# (Intercept) x
# -4.221196 1.496578
相當於
contrasts(datos$tipo)
# B
#A 0
#B 1
#attributes(fit.lm$qr$qr)$contrasts
#$tipo
#[1] "contr.treatment"
而不是那些爲lmp()
:
coefficients(fit.lmp)[1:2] + coefficients(fit.lmp)[3:4] # coefficients for Level A
# (Intercept) x
# -71.169640 1.993383
coefficients(fit.lmp)[1:2] - coefficients(fit.lmp)[3:4] # coefficients for Level B
# (Intercept) x
# -4.221196 1.496578
爲什麼?
謝謝,但這沒有記錄,對不對? – user2955884
再次感謝。但是我指定center = FALSE。我認爲,以center = TRUE爲默認值,即使用戶指出center = FALSE,它們也會保持contr.sum。我認爲這兩件事情都是不幸的,並且令人困惑,因爲幫助頁表明lmp()充當lm(),除了隨機化。另外,爲什麼在lmp中沒有發現R平方概率的任何原因?幫助頁面顯示「將會輸出排列測試p值或通常的F測試p值」,但我總是得到R測試的F測試(也許這應該是另一個問題)。 – user2955884