-1
有人知道預測函數如何在迴歸模型中存在交互項時計算項?我知道如何解決迴歸時沒有交互條件的問題,但是當我添加一個時,我不能再手動解決這些問題。這裏是一些示例數據,我想看看如何手動計算這些值。謝謝! -Aleksi迴歸有交互項時,如何從預測函數手動計算「項」
set.seed(2)
a <- c(4,3,2,5,3) # first I make some data
b <- c(2,1,4,3,5)
e <- rnorm(5)
y= 0.6*a+e
data <- data.frame(a,b,y)
model1 <- lm(y~a*b,data=data) # regression
predict(model1,type='terms',data) # terms
#This gives the result:
a b a:b
1 0.04870807 -0.3649011 0.2049069
2 -0.03247205 -0.7298021 0.7740928
3 -0.11365216 0.3649011 0.2049069
4 0.12988818 0.0000000 -0.5919534
5 -0.03247205 0.7298021 -0.5919534
attr(,"constant")
[1] 1.973031