+ Reply to Thread
Results 1 to 6 of 6

Thread: Both categorical and continuous predictors?

  1. #1
    Points: 2,038, Level: 27
    Level completed: 26%, Points required for next Level: 112

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Both categorical and continuous predictors?




    I'm sure this is very simple but I just want to be sure. I have actually been searching the web for a while now and can't seem to find a clear answer/simple explanation.

    With linear regression, is it ok to have both categorical and continuous predictors in the same model?

    For instance, say I have a continuous response variable and I want to test the effects (including interactions) of three predictors: one is continuous, one is binary, one is categorical with 5 levels.

    i.e. lm(response ~ continuous * binary * categorical, dat)

    Is there anything inherently wrong with this?

  2. #2
    Fortran must die
    Points: 58,790, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,532
    Thanks
    692
    Thanked 915 Times in 874 Posts

    Re: Both categorical and continuous predictors?

    Formally you can have both categorical and interval variables because regression makes no distributional assumptions of predictors, but while that is sometimes done [particularly with likert scaled data] it is far more common to use interval and dummy variables [the latter created from the categorical variables]. At my master's defense my supervising professor stated that having categorical variables as predictors [with their original scale not as dummies] could lead to nonsensical results, although I have not seen that stated elsewhere [but he was very very bright so who knows].
    "Very few theories have been abandoned because they were found to be invalid on the basis of empirical evidence...." Spanos, 1995

  3. #3
    Human
    Points: 12,676, Level: 73
    Level completed: 57%, Points required for next Level: 174
    Awards:
    Master Tagger
    GretaGarbo's Avatar
    Posts
    1,362
    Thanks
    455
    Thanked 462 Times in 402 Posts

    Re: Both categorical and continuous predictors?

    Quote Originally Posted by dt87 View Post
    With linear regression, is it ok to have both categorical and continuous predictors in the same model?
    Yes, it is OK.
    (And it is very common.)

    Of course, internally in the computer, the categorical variables will be recoded as dummy variables.

  4. #4
    Fortran must die
    Points: 58,790, Level: 100
    Level completed: 0%, Points required for next Level: 0
    noetsi's Avatar
    Posts
    6,532
    Thanks
    692
    Thanked 915 Times in 874 Posts

    Re: Both categorical and continuous predictors?

    Not always GretaGarbo. For example I saw a likert scale variable with about 55 levels entered directly into the model. And I suspect this is done with far fewer levels.

    Not all software will recognize variables as categorical and automatically transform them into dummies. PROC REG in SAS (the primary method to do linear regression in SAS) does not do this as it has no CLASS statement declaring variables to be categorical. You have to code them that way yourself. I believe SPSS does this as well although I do not work with it very often.

    http://www.psychstat.missouristate.e...ok/mlt08m.html
    "Very few theories have been abandoned because they were found to be invalid on the basis of empirical evidence...." Spanos, 1995

  5. #5
    Points: 3,006, Level: 33
    Level completed: 71%, Points required for next Level: 44

    Posts
    177
    Thanks
    1
    Thanked 29 Times in 29 Posts

    Re: Both categorical and continuous predictors?

    r automatically does this when you specify a variable as categorical. And given your syntax thats what you are doing.

    BUT you need to specify categorical <- as.factor(dat$categorical.variable)

  6. #6
    Points: 2,038, Level: 27
    Level completed: 26%, Points required for next Level: 112

    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Both categorical and continuous predictors?


    Thank you all very much! Much appreciated

+ Reply to Thread

           




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats