您好,我想缩放模型的系数。这就是为什么我准备了这个小例子。 我想将 MPG.city,MPG.highway,马力的系数与“校正系数” 相乘。任何想法如何乘或校正系数?
library(MASS)
data("Cars93")
Cars_new = Cars93[,c(4,5,6,7,8,13,14)]
fit<-lm(Price~.,data=Cars_new)
#model output should be list
fit<-list(fit)
#correction factor for MPG.city, MPG.highway,Horsepower
correction<-c(1.2,1.23,1.6)
编辑 模型输出是一个列表!
答案 0 :(得分:2)
您可以按名称选择系数
fit[[1]]$coefficients[c("MPG.city", "MPG.highway", "Horsepower")] <-
fit[[1]]$coefficients[c("MPG.city", "MPG.highway", "Horsepower")] * correction
#[[1]]
#Call:
#lm(formula = Price ~ ., data = Cars_new)
#Coefficients:
#(Intercept) Min.Price Max.Price MPG.city MPG.highway Horsepower RPM
# -2.424e-02 5.010e-01 4.999e-01 -1.639e-04 1.029e-03 -1.504e-04 -1.293e-07