0

I have a problem with a linear function. I am using categorical variables but when performing a linear function and making a summary I get the error Error in quantile.default (resid): (unordered) factors are not allowed.

I am using the following function:

Reg_Total<- lm(This_6 ~ This_3+ This_12,data = In_GCambio2)

and the following data:

This_1 : Factor w/ 2 levels "No","Sí": 2 2 2 1 2 2 2 2 1 2 ...
 $ This_2 : Factor w/ 5 levels "De acuerdo","En desacuerdo",..: 4 1 4 3 1 3 4 4 1 1 ...
 $ This_3 : Factor w/ 2 levels "No","Sí": 2 2 2 1 2 2 2 2 2 2 ...
 $ This_4 : Factor w/ 2 levels "No","Sí": 1 2 1 1 2 2 2 2 2 2 ...
 $ This_5 : Factor w/ 2 levels "No","Sí": 2 2 2 1 2 2 1 2 2 2 ...
 $ This_6 : Factor w/ 3 levels "3.200.000 a 3.500.000"

Do I have to use another type of model or may my data be wrong?

  • For a linear regression, the dependent / response variable needs to be a continuous numerical variable. Linear regression is a tool designed to predict continuous data. It is not well-suited to discrete data or categorical data (where the order of the values is arbitrary). Is you really want to predict a categorical / discrete / factor variable, then you have a classification problem, not a regression problem. – Ben Norris Jan 17 '21 at 00:12
  • @BenNorris, please post that as an answer? – Ben Bolker Jan 17 '21 at 00:13
  • Sorry they are a bit new, I already updated the data. I was looking and the best option is a glm, how can I get the best model with a glm in an automated way? – Brian Amaya Jan 17 '21 at 00:18

0 Answers0