Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 多元线性回归预警_R_Linear Regression - Fatal编程技术网

R 多元线性回归预警

R 多元线性回归预警,r,linear-regression,R,Linear Regression,我试图拟合一个线性模型,但我面临这个警告 > reg=lm(Data.readmitted ~., newdata) 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 fact

我试图拟合一个线性模型,但我面临这个警告

> reg=lm(Data.readmitted ~., newdata)

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
以及我的数据集中的
str()

> str(newdata)


'data.frame':  94613 obs. of  4 variables:
    $ Data.race      : Factor w/ 5 levels "AfricanAmerican",..: 3 3 1 3 3 3 3 3 3 3 ...
    $ Data.gender    : Factor w/ 3 levels "Female","Male",..: 1 1 1 2 2 2 2 2 1 1 ...
    $ Data.age       : Factor w/ 10 levels "[0-10)","[10-20)",..: 1 2 3 4 5 6 7 8 9 10 ..
    $ Data.readmitted: Factor w/ 3 levels "<30",">30","NO": 3 2 3 3 3 2 3 2 3 3 ...
     - attr(*, "na.action")=Class 'omit'  Named int [1:2153] 20 21 22 55 66 88 100 112 128 178 ...
    .. ..- attr(*, "names")= chr [1:2153] "20" "21" "22" "55" ...
str(新数据) “数据帧”:94613 obs。共有4个变量: $Data.race:Factor w/5级别“非洲裔美国人”…:3 1 3。。。 $数据。性别:系数w/3级“女性”、“男性”、..:1 1 2 1。。。 $Data.age:系数w/10级“[0-10]”,“[10-20]”,..:1 2 3 4 5 6 7 8 9 10。。 $Data.READMITED:系数w/3级别“30”,“否”:3 2 3 3 3。。。 -attr(*,“na.action”)=名为int[1:2153]202122556688100112128178的类“省略”。。。 ..-attr(*,“name”)=chr[1:2153]“20”“21”“22”“55”。。。
这些是警告,而不是错误。如果您不想要因子,请在数据上使用
as.numeric()
,或者在导入数据时使用
stringsAsFactors=FALSE
。lm是分类因变量的错误模型类型。因此,它无法正确处理。那么,我能做什么?我的go to resource是google: