# Logistic regression analysis after changing variables to factors [closed]

I have done a logistic regression with my binary outcome. Majority of my variables in my model were changed to factors as they are categorical. I put my categories into levels ie. Very Low = 1, Medium=2, High=3. I do not understand why my output is numbered for example: skills2, skills3 & skills4? I just want to know if skills is significant or not, as for all the other variables. Please see my output below:

Call:
glm(formula = FOODLIT$$T1D2 ~ FOODLIT$$EDUCATION + FOODLIT$$SKILLS + FOODLIT$$CONFIDENCE + FOODLIT$$F&V + FOODLIT$$PROTEIN + FOODLIT$$CHOS + FOODLIT$$SKILLSB + FOODLIT$$CONF. W REC. + FOODLIT$$MET W/PDT +
FOODLIT$$KNOWLEDGE + FOODLIT$$AGE + FOODLIT$$AGE DX + FOODLIT$$WHO PREP MEALS,
family = "binomial")

Deviance Residuals:
Min        1Q    Median        3Q       Max
-1.83314  -0.34830  -0.17582  -0.07559   2.88906

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)               -3.477e+00  2.910e+00  -1.195 0.232064
FOODLIT$$EDUCATION2 -4.275e-01 7.822e-01 -0.546 0.584726 FOODLIT$$EDUCATION3        -1.024e+00  8.212e-01  -1.247 0.212366
FOODLIT$$SKILLS2 3.928e-01 1.084e+00 0.362 0.717086 FOODLIT$$SKILLS3            4.590e-01  9.267e-01   0.495 0.620378
FOODLIT$$SKILLS4 1.325e-01 1.571e+00 0.084 0.932796 FOODLIT$$CONFIDENCE2       -5.894e-01  9.072e-01  -0.650 0.515892
FOODLIT$$CONFIDENCE3 -1.470e+00 1.126e+00 -1.305 0.191765 FOODLIT$$F&V2             2.196e+00  7.703e-01   2.851 0.004359 **
FOODLIT$$PROTEIN2 8.357e-02 6.423e-01 0.130 0.896472 FOODLIT$$CHOS2              1.956e+00  7.247e-01   2.699 0.006957 **
FOODLIT$$SKILLSB2 -3.435e-01 1.059e+00 -0.324 0.745600 FOODLIT$$SKILLSB3           9.864e-01  1.083e+00   0.911 0.362428
FOODLIT$$SKILLSB4 1.373e+00 1.181e+00 1.162 0.245046 FOODLIT$$CONF. W REC.2   -2.835e+00  1.040e+00  -2.727 0.006385 **
FOODLIT$$CONF. W REC.3 -3.826e+00 1.106e+00 -3.457 0.000545 *** FOODLIT$$MET W/PDT        4.691e-01  3.484e-01   1.346 0.178189
FOODLIT$$KNOWLEDGE 6.796e-03 1.036e-02 0.656 0.511763 FOODLIT$$AGE                5.011e-02  9.963e-02   0.503 0.614969
FOODLIT$$AGE DX 2.388e-02 4.623e-02 0.516 0.605542 FOODLIT$$WHO PREP MEALS2  1.899e-02  8.339e-01   0.023 0.981829
FOODLIT$$WHO PREP MEALS3 2.159e+00 1.005e+00 2.148 0.031711 * FOODLIT$$WHO PREP MEALS5 -1.097e+01  2.400e+03  -0.005 0.996354
FOODLIT$WHO PREP MEALS6 -1.446e+01 1.691e+03 -0.009 0.993178 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 (Dispersion parameter for binomial family taken to be 1) Null deviance: 167.986 on 220 degrees of freedom Residual deviance: 96.167 on 197 degrees of freedom (15 observations deleted due to missingness) AIC: 144.17 Number of Fisher Scoring iterations: 15  Thanks for your help! It is greatly appreciated. • Welcome to CV. I see SKILLS and SKILLSB in your model. Do you want both? Do you care about the differences between the categories? I only ask because you stated that you only care "if skills is significant or not..." in the regression results. – Thomas Bilach May 6 '20 at 21:17 • It is labeled that way because it is a categorical variable and, by default, level 1 is the reference category. – Peter Flom May 7 '20 at 13:44 ## 1 Answer First, I want to save you time and energy when specifying your equation. For example, inside of the glm() function, I strongly encourage you to use the data = ... argument. It will eliminate the redundancies in your code. See the example R code below: glm(formula = T1D2 ~ EDUCATION + SKILLS + ..., data = FOODLIT, family = "binomial")  Note, specifying the data = ... argument obviates the requirement to explicitly reference your data frame each time you want to extract a column (variable). The $ is a basic extraction operator in R, and the data = ... argument pulls the desired columns you want without further effort on your part. Now for your concerns.

I do not understand why my output is numbered for example: skills2, skills3 & skills4?

R concatenates the level to the variable name to distinguish the categories. For instance, I assume there are four categories associated with the SKILLS variable. By using the factor() function to create an ordered factor, the variable now has four ordered levels (e.g., Levels: 1 2 3 4). R omits the first level, and calculates separate estimates for each category. The first level is the "baseline" (i.e., reference) category; it is absorbed into the overall intercept term. Put simply, each skill level is compared with the omitted level. That is the why.

Furthermore, your levels are ordered (numbered) categories. To ease the readability of the output, try converting the variable to a named factor. See the example code below:

FOODLIT$$... <- factor(FOODLIT$$SKILLS, labels = c("Low", "Medium", "...", "..."))


The order of the labels should follow the numeric ordering. Thus, the label "Low" might correspond to 1, Medium might correspond to 2, so on and so forth.

I just want to know if skills is significant or not, as for all the other variables.

I observe more than one variable designation for "skill" in your specification (i.e., SKILLS and SKILLSB). Each appears to have four levels. Since you specified these variables as factor variables, then each level (category) is a separate estimate in your output. Each category is compared with the omitted category. To demonstrate this explicitly, the discretized version of SKILLS is making the following comparisons:

• SKILLS2 versus SKILLS1
• SKILLS3 versus SKILLS1
• SKILLS4 versus SKILLS1

In sum, the numbers help disambiguate the different factor levels.

I hope this clears things up!

• If I can ask one follow up questions, given that the first level is omitted is there any way to see if that first level is significant? – aliitzkovitz May 7 '20 at 12:20
• I would re-level the categories. Try: relevel(SKILLS, ref = "...") inside of the function. You can force another level to be absorbed into the intercept. If you place this inside of the formula, it won't affect the original variable in your dataset. If you have other coding concerns, SO is the place to go. See this post. – Thomas Bilach May 7 '20 at 15:47