0

I'm trying to calculate a multivariate linear regressions in which my independent variables are qualitative but Im not sure im doing it right

the code I have so far is

model_1.a <- lm(formula = V34 ~ no.work + common.poor.housing + no.degree, data = df)

however my variables no.work, common.poor.housing and no.degree where created with the within() function like so:

    df <- within(cr.svy, {
  degree <- as.numeric(V6==4)
  no.degree <- as.numeric(V6 == 1| V7 == 2 | V7 == 3)
  work <- as.numeric(V7==1)
  no.work <- as.numeric(V7 == 2)
  common.poor.housing <- as.numeric(V14 == 1 | V14 == 2)
  uncommon.poor.housing <- as.numeric(V14==3 | V14 == 4)
  degree[is.na(V6)] <- NA
  no.degree[is.na(V6)] <- NA
  work[is.na(V7)] <- NA
  no.work[is.na(V7)] <- NA
  common.poor.housing[is.na(V14)] <- NA
  uncommon.poor.housing[is.na(V14)] <- NA
})

and are either 1 or 0 and Im not sure if the results are what Im looking for, Im trying to test the relationship between my dependent variables and the no.work, common.poor.housing and the no.degree variable I created

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. What makes you think things aren't working? – MrFlick Dec 14 '22 at 14:51
  • the code is working just fine but I'm not sure it is testing the right thing as Im not used to using qualitative variables – monkegobrrrrrr Dec 14 '22 at 14:55

1 Answers1

0

AFAIK, if your data is of class numeric, R will treat it as continuous ( quantitative) variable. For variables to be considered categorical (qualitative), they must be of class factor which can be easily achieve by taking your variable and applying the function factor(). E.g.

degree <- factor(degree)

This is not necessary, however, if the variable is of class character (which in R is very easy to spot, the values will be surronded by quotes). Those variables are automatically converted to factor when you call lm().

By looking at your code, your variables are cleary on the first case, numeric, since they are created by the function as.numeric().

So, no. Your results are exactly what you want.

JMenezes
  • 1,004
  • 1
  • 6
  • 13