Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.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 如何将因子更改为数值变量或以其他方式处理此错误I';我在做线性回归_R - Fatal编程技术网

R 如何将因子更改为数值变量或以其他方式处理此错误I';我在做线性回归

R 如何将因子更改为数值变量或以其他方式处理此错误I';我在做线性回归,r,R,尝试使用此数据集mro.csv运行线性回归模型,但运行lm()时会显示错误消息: 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 不确定数据集的哪些部分是因子而不是数字,

尝试使用此数据集mro.csv运行线性回归模型,但运行lm()时会显示错误消息:

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
不确定数据集的哪些部分是因子而不是数字,除列名外,所有数据都是数字。也不确定对于因子部分没有意义的“-”,因为数据集中也没有“-”

不确定如何共享数据集,但以下是谷歌表单中的csv:

原始尺寸(原始) [1] 753 22 > >种子(88) >生的 > >raw1尺寸(原始) [1] 753 22 >dim(raw1) [1] 428 22 > >
>reg1 reg1
工资
lwage
被解读为
系数
s,因为它们包含的值
无法解析为数字。此值可以手动处理

df <- read.csv(
  "~/Downloads/mro.csv",
  header = FALSE,
  stringsAsFactors = FALSE,
  col.names = c(
    "inlf", "hours", "kidslt6", "kidsge6", "age", "educ",  "wage",
    "repwage", "hushrs", "husage", "huseduc", "huswage",  "faminc",
    "mtr",  "motheduc",  "fatheduc", "unem", "city", "exper",
    "nwifeinc", "lwage", "expersq"
  )
)

df$wage <- as.numeric(ifelse(df$wage == ".", 0, df$wage))
df$lwage <- as.numeric(ifelse(df$lwage == ".", 0, df$lwage))

这条消息说,响应“工资”是一个因素。你能分享你的数据吗(
dput(raw)
)?其他一些事情:对于参数,你应该使用
=
,而不是
,我不知道如何分享数据@Paul,但我刚刚添加了一个到数据集的链接
df <- read.csv(
  "~/Downloads/mro.csv",
  header = FALSE,
  stringsAsFactors = FALSE,
  col.names = c(
    "inlf", "hours", "kidslt6", "kidsge6", "age", "educ",  "wage",
    "repwage", "hushrs", "husage", "huseduc", "huswage",  "faminc",
    "mtr",  "motheduc",  "fatheduc", "unem", "city", "exper",
    "nwifeinc", "lwage", "expersq"
  )
)

df$wage <- as.numeric(ifelse(df$wage == ".", 0, df$wage))
df$lwage <- as.numeric(ifelse(df$lwage == ".", 0, df$lwage))
df <- df[sample(nrow(df)), ]
df1 <- df[df$inlf == 1, ]

reg1 <- lm(
  wage ~ hours + kidslt6 + kidsge6 + age + educ + hushrs + husage + huseduc +
         huswage + mtr + motheduc + fatheduc + unem + exper + nwifeinc,
  data = df1
)