Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.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,我一直在尝试用R对变量进行逐步选择。这是我的代码: library(lattice)#to get the matrix plot, assuming this package is already installed library(ftsa) #to get the out-of sample performance metrics, assuming this package is already installed library(car) mydata=read.csv("C:/U

我一直在尝试用R对变量进行逐步选择。这是我的代码:

library(lattice)#to get the matrix plot, assuming this package is already installed
library(ftsa) #to get the out-of sample performance metrics, assuming this package is already installed
library(car) 

mydata=read.csv("C:/Users/jgozal1/Desktop/Multivariate Project/Raw data/FINAL_alldata_norowsunder90_subgroups.csv")

names(mydata)
str(mydata)

mydata$country_name=NULL
mydata$country_code=NULL
mydata$year=NULL
mydata$Unemployment.female....of.female.labor.force...modeled.ILO.estimate.=NULL
mydata$Unemployment.male....of.male.labor.force...modeled.ILO.estimate.=NULL
mydata$Life.expectancy.at.birth.male..years.= NULL
mydata$Life.expectancy.at.birth.female..years. = NULL

str(mydata)

Full_model=lm(mydata$Fertility.rate.total..births.per.woman. + mydata$Immunization.DPT....of.children.ages.12.23.months. + mydata$Immunization.measles....of.children.ages.12.23.months. + mydata$Life.expectancy.at.birth.total..years. + mydata$Mortality.rate.under.5..per.1000.live.births. + mydata$Improved.sanitation.facilities....of.population.with.access. ~ mydata$Primary.completion.rate.female....of.relevant.age.group. + mydata$School.enrollment.primary....gross. + mydata$School.enrollment.secondary....gross. + mydata$School.enrollment.tertiary....gross. + mydata$Internet.users..per.100.people. + mydata$Primary.completion.rate.male....of.relevant.age.group. + mydata$Mobile.cellular.subscriptions..per.100.people. + mydata$Foreign.direct.investment.net.inflows..BoP.current.US.. + mydata$Unemployment.total....of.total.labor.force...modeled.ILO.estimate., data= mydata)

summary(Full_model) #this provides the summary of the model

Reduced_model=lm(mydata$Fertility.rate.total..births.per.woman. + mydata$Immunization.DPT....of.children.ages.12.23.months. + mydata$Immunization.measles....of.children.ages.12.23.months. + mydata$Life.expectancy.at.birth.total..years. + mydata$Mortality.rate.under.5..per.1000.live.births. + mydata$Improved.sanitation.facilities....of.population.with.access. ~1,data= mydata)

step(Reduced_model,scope=list(lower=Reduced_model, upper=Full_model), direction="forward", data=mydata)

step(Full_model, direction="backward", data=mydata)

step(Reduced_model,scope=list(lower=Reduced_model, upper=Full_model), direction="both", data=mydata)
这是指向我正在使用的数据集的链接:

在为我的逐步设置范围后,我得到以下错误:

步骤错误(简化模型,范围=列表(下部=简化模型,上部=完整模型): 正在使用的行数已更改:是否删除缺少的值? 此外:警告信息: 1:在add1.lm中(fit,scope$add,scale=scale,trace=trace,k=k,: 使用组合配合中的548/734行 2:在add1.lm中(fit,scope$add,scale=scale,trace=trace,k=k,: 使用组合配件中的548/734行


我看过其他有相同错误的帖子,解决方法通常是从使用的数据中省略NAs,但这并没有解决我的问题,我仍然得到完全相同的错误。

当你说“这并没有解决我的问题”时你的意思是你得到了完全相同的错误吗?在这里包含一个这样我们就可以确认你的结果会很有帮助。是的,它给了我相同的错误。我很快会包含可复制的示例。谢谢。我刚刚编辑了我的帖子,以便完全可复制。我不确定你做了什么,但是做了
mydataThank you MrFlick。这对我也很有效.我在读取数据时,以及在引用完整模型和简化模型中的数据时,都会将na.omit放在一起。这很有趣,因为它会显示我的观察次数是如何随着之前省略NAs的方法而减少的,但它仍然给了我一个错误