Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.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 错误:使用与nlsw88数据拟合不同的类型指定了变量_R - Fatal编程技术网

R 错误:使用与nlsw88数据拟合不同的类型指定了变量

R 错误:使用与nlsw88数据拟合不同的类型指定了变量,r,R,我使用STATA nlsw88中的数据并制作模型 h<-read.dta("nlsw88.dta") h1<-mutate(h,age = log(h$age),wage = log(h$wage)) model2<-lm(data=h1,wage~age+race+married+never_married+grade+collgrad+industry+union+occupation+hours+ttl_exp+tenure+c_city) h在h1数据框中未婚和c\u

我使用STATA nlsw88中的数据并制作模型

h<-read.dta("nlsw88.dta")
h1<-mutate(h,age = log(h$age),wage = log(h$wage))
model2<-lm(data=h1,wage~age+race+married+never_married+grade+collgrad+industry+union+occupation+hours+ttl_exp+tenure+c_city)

h在
h1
数据框中
未婚
c\u城市
的变量类别为
整数

class(h1$never_married)
[1] "integer"    
class(h1$c_city)
[1] "integer"
但是在
nd
数据框中,这些变量的类别是
因子

 class(nd$never_married)
 [1] "factor"
 class(nd$c_city)
 [1] "factor"
因此,
nd
的代码应为:

nd <- data.frame(age=log(37), married="married", union="union",
   race="white", grade=14, never_married=1, collgrad="college grad",
   industry="Manufacturing", occupation="Operatives", hours=48,
   ttl_exp=10, tenure=5, c_city=0)

请勿将您的数据以图片形式发布,请学习如何发布。这将使其他人更容易帮助你。非常感谢
 class(nd$never_married)
 [1] "factor"
 class(nd$c_city)
 [1] "factor"
nd <- data.frame(age=log(37), married="married", union="union",
   race="white", grade=14, never_married=1, collgrad="college grad",
   industry="Manufacturing", occupation="Operatives", hours=48,
   ttl_exp=10, tenure=5, c_city=0)
predict(model2,nd)
       1 
1.902962