我一直试图用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)
这是我正在使用的数据集的链接:http://speedy.sh/YNXxj/FINAL-alldata-norowsunder90-subgroups.csv
为我的逐步设置范围后,我收到此错误:
步骤中的错误(Reduced_model,scope = list(lower = Reduced_model,upper = Full_model),: 使用的行数已更改:删除缺失值? 另外:警告信息: 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行
我查看了其他帖子的错误相同,解决方案通常是从所使用的数据中省略NA,但这并没有解决我的问题,我仍然得到完全相同的错误。