1
votes

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?

1
we can't debug this without a reproducible example. At the very least, can you edit your question to include the results of str(BR_Click34_Crows_pos[10]) ? - Ben Bolker
Hi, welcome to stack overflow. Can you please include a reproducible example, which will make it easier for others to help you.Consider looking at this and this stackoverflow.com/questions/5963269/…. Including your data, or a subset of it would be a great first step. - Mark Neal
Thank you @BenBolker, I'd misunderstood the data format required. - MzEdd
Thank you @MarkNeal, I'd misunderstood the data format required. - MzEdd

1 Answers

1
votes

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)