在car
包,我試圖通過lm
功能預測稱爲prestige
響應變量數據集中基礎上income
,education
也叫Prestige
,並且因素type
。但在我符合數據之前,我想要縮放education
和income
。如果複製和R中stuido運行下面的代碼時,控制檯會說Error: variables ‘income’, ‘I(income^2)’, ‘education’, ‘I(education^2)’ were specified with different types from the fit
錯誤:變量與不同類型的規定從擬合
library(car)
summary(Prestige)
Prestige$education <- scale(Prestige$education)
Prestige$income <- scale(Prestige$income)
fit <- lm(prestige ~ income + I(income^2) + education + I(education^2)
+ income:education + type + type:income + type:I(income^2)
+ type:education + type:I(education^2)+ type:income:education, Prestige)
summary(fit)
pred <- expand.grid(income = c(1000, 20000), education = c(10,20),type = levels(Prestige $ type))
pred $ prestige.pred <- predict(fit, newdata = pred)
pred
無調整的預測,它可以成功地工作。所以這個錯誤肯定是由於預測之前的縮放比例造成的,我想知道如何解決這個問題?