0
votes

My data includes total hospital expenditure, age, gender, length of stay and race. When I loaded the dataset from excel to R, they were all numeric. So I changed gender(2 cats) and race(5cats) to factor.

GENDERfac <- as.factor(hospital$GENDER)
RACEfac <- as.factor(hospital$RACE)

Now I need to build a multiple linear regression to best predict hospital expenditure using the other variables as predictors. So in the model for categorical IVs, should I be using their numerical variables or factor form?

costmodel <- lm(formula= COST ~ AGE+GENDER+LOS+RACE, data=hospital)

Or

costmodel <- lm(formula= hospital$COST ~ hospital$AGE + GENDERfac + hospital$LOS + RACEfac)

What difference do the two have? I understand that using the factor variables, model will return values for each category of that variable. In that case, how would the interpretation be?

RACEfac2       269.7343   408.6436   0.660 0.509563    
RACEfac3       641.3334   862.2531   0.744 0.457413 **   
RACEfac4       106.4079   458.4198   0.232 0.816557    
RACEfac5      1577.1875   908.2736   1.736 0.083201 .  
RACEfac6       -73.8266   566.3145  -0.130 0.896340   

Also, what if few categories of that variable are significant while others are not? How should the interpretation be?

1
Does this answer your question? stats.stackexchange.com/a/34329/102418 - slamballais

1 Answers

0
votes

For categorical variables, you should create dummy variables for each category except one which will be your reference category. So you will create a new variable for Racefac2 where if that category is present it will be coded 1, if it is absent it will be coded 0. Create a new variable for each level except for the reference category. The one that is omitted is recorded in the data as the rows that are zero across all of your dummy variables.

You then can interpret each of these variable coefficients as a change/difference in comparison to the reference category (i.e. the race category that was not included in the model). Here is a short paper describing this

https://www.researchgate.net/profile/Hussain-Alkharusi/publication/256349393_Categorical_Variables_in_Regression_Analysis_A_Comparison_of_Dummy_and_Effect_Coding/links/004635225a56be9d11000000/Categorical-Variables-in-Regression-Analysis-A-Comparison-of-Dummy-and-Effect-Coding.pdf