1

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?

Chuck P
  • 3,862
  • 3
  • 9
  • 20
MzEdd
  • 15
  • 2
  • 2
    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 Aug 02 '20 at 20:52
  • 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](https://stackoverflow.com/help/minimal-reproducible-example) and this https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Including your data, or a subset of it would be a great first step. – Mark Neal Aug 02 '20 at 21:55
  • Thank you @BenBolker, I'd misunderstood the data format required. – MzEdd Aug 04 '20 at 17:48
  • Thank you @MarkNeal, I'd misunderstood the data format required. – MzEdd Aug 04 '20 at 17:49

1 Answers1

1

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)
Chuck P
  • 3,862
  • 3
  • 9
  • 20
  • Many thanks @ChuckP. I'd read "Numeric or character vector ..." as wanting a vector of numeric data. Many thanks for pointing me in the right direction. – MzEdd Aug 04 '20 at 17:45
  • No problem your idea was perfectly logical just not what the function author meant. – Chuck P Aug 04 '20 at 19:08