[英]Fitting multiple linear regression model in R software
I was attempting to fit a multiple linear regression model in R but I kept getting this error message in my program:我试图在 R 中拟合多元线性回归模型,但我一直在我的程序中收到此错误消息:
Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
Here's the code I have so far:这是我到目前为止的代码:
# Fit a multiple linear regression model
> mlr <- lm(y~x1+x2+x3+x4+x5,data=steam)
Warning messages:
1: In model.response(mf, "numeric") :
using type = "numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : ‘-’ not meaningful for factors
> summary(mlr)
Call:
lm(formula = y ~ x1 + x2 + x3 + x4 + x5, data = steam)
Residuals:
Error in quantile.default(resid) : factors are not allowed
In addition: Warning message:
In Ops.factor(r, 2) : ‘^’ not meaningful for factors
> names(mlr)
[1] "coefficients" "residuals" "effects" "rank"
[5] "fitted.values" "assign" "qr" "df.residual"
[9] "xlevels" "call" "terms" "model"
> mlrs <- summary(mlr)
Warning message:
In Ops.factor(r, 2) : ‘^’ not meaningful for factors
> names(mlrs)
[1] "call" "terms" "residuals" "coefficients"
[5] "aliased" "sigma" "df" "r.squared"
[9] "adj.r.squared" "fstatistic" "cov.unscaled"
The running str(steam) shows this正在运行的 str(steam) 显示了这一点
>str(steam)
'data.frame': 25 obs. of 6 variables:
$ y : Factor w/ 25 levels "10","11","12",..: 25 11 18 19 20 21 22 23 24 1 ...
$ x1: num 10.98 11.13 12.51 8.4 9.27 ...
$ x2: num 5.2 5.12 6.19 3.89 6.28 5.76 3.45 6.57 5.69 6.14 ...
$ x3: num 0.61 0.64 0.78 0.49 0.84 0.74 0.42 0.87 0.75 0.76 ...
$ x4: num 7.4 8 7.4 7.5 5.5 8.9 4.1 4.1 4.1 4.5 ...
$ x5: int 31 29 31 30 31 30 31 31 30 31 ...
I would like to know what has caused the warning message shown.我想知道是什么导致了显示的警告消息。 Thank you!谢谢!
Dependent variable should not be factor, character or categorical.因变量不应是因子、字符或分类变量。 So, the following code would be best.所以,下面的代码是最好的。
# Fit a multiple linear regression model
mlr <- lm(as.numeric(y)~x1+x2+x3+x4+x5,data=steam)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.