MzEdd
MzEdd

Reputation: 15

R StepReg stepwise gives 'y' should be numeric or character vector

I'm trying to do a stepwise regression on a data frame using StepReg, like this:

library(StepReg)

stepwise(BR_Click34_Crowd_pos[,c(10:45)], 
         y = BR_Click34_Crowd_pos[,c(10)], 
         exclude = BR_Click34_Crowd_pos[,c(15,17,23:25,31,32)], 
         selection = "bidirection", 
         select = 'adjRsq', 
         0.01, 
         0.05)

The data frame holds 45 columns of numeric data, with columns 10 - 45 passed in with column 10 as the output variable and columns 11 - 45 as the input variables, but with some columns excluded. The error message is " 'y' should be numeric or character vector " which refers to column 10 and using as.numeric on column 10 gives a different error ('list' object cannot be coerced to type 'double') and as.vector on column 10 gives the error ('y' should be numeric or character vector). Any thoughts, please?

Upvotes: 1

Views: 348

Answers (1)

Chuck P
Chuck P

Reputation: 3923

This error is produced because the function is expecting the name of the y variable in quotes or as a numeric column number not as a pointer to a column in the dataframe BR_Click34_Crowd_pos[,c(10)]

See the documentation for examples...

stepwise(yx[,3:12], y = "Y1", exclude = "Y3", 
         selection = "bidirection", select='adjRsq', sle = 0.01, sls = 0.05)

Upvotes: 1

Related Questions