# Why is logistic regression in R creating multiple coefficients for one variable?

Thank you so much for your input to my question. My variable is HPtsLag and is continuous (although integers, and <=18 - perhaps this could be the issue?). Anyway, here is my code and output. Hopefully this explains it better.

> mylog = glm(cbind(HW,NotHW) ~ HPtsLag, data = g, family = binomial)
> summary (mylog)


Call:

> glm(formula = cbind(HW, NotHW) ~ HPtsLag, family = binomial, data = g)

Deviance Residuals:
Min       1Q   Median       3Q      Max
-1.5898  -1.0787  -0.9431   1.2142   1.6259

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)  -1.0116     0.3371  -3.001  0.00269 **
HPtsLag1      0.3998     0.4023   0.994  0.32031
HPtsLag10     0.9255     0.3527   2.624  0.00869 **
HPtsLag11     0.9694     0.3613   2.683  0.00729 **
HPtsLag12     1.0722     0.3659   2.931  0.00338 **
HPtsLag13     1.5224     0.3652   4.168 3.07e-05 ***
HPtsLag14     1.7693     0.4032   4.388 1.15e-05 ***
HPtsLag15     1.2658     0.4004   3.161  0.00157 **
HPtsLag16     1.8348     0.3919   4.681 2.85e-06 ***
HPtsLag18     1.9432     0.4700   4.135 3.55e-05 ***
HPtsLag2      0.4318     0.3883   1.112  0.26615
HPtsLag3      0.7807     0.3700   2.110  0.03488 *
HPtsLag4      0.5873     0.3565   1.648  0.09944 .
HPtsLag5      0.6881     0.3544   1.942  0.05219 .
HPtsLag6      0.6862     0.3545   1.936  0.05292 .
HPtsLag7      0.6956     0.3508   1.983  0.04739 *
HPtsLag8      0.7749     0.3532   2.194  0.02824 *
HPtsLag9      0.9588     0.3541   2.708  0.00677 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 5432.7  on 3929  degrees of freedom
Residual deviance: 5314.6  on 3912  degrees of freedom
AIC: 5350.6

Number of Fisher Scoring iterations: 4


Why is this happening?

• Is your variable VAR continuous or categorical? – FMZ Jan 9 '12 at 6:27
• Could you provide your R code with the R function you use? As such your question does not make sense. – Xi'an Jan 9 '12 at 7:38
• The extra terns could be coefficients of the higher order terms $x^2$, $x^3$, $x^4$. – Itamar Jan 9 '12 at 8:25

The object var is stored as a factor - or perhaps as a character. You can check this by examining str(var) - to get the structure of {var}. By what you write, I guess you want to store {var} as a numeric variable; in this case create var2 <- as.numeric(var) and use var2 in your regression.
The problem also often occurs when the data hasn't been read in correctly, from wherever it's been stored. You could check your use of read.table(), or similar commands to read in data.
• R treats variables stored as numeric (like var2 above) as continuous. So, using var2 should give you what you want - check the output has just one coefficient. – guest Jan 9 '12 at 18:00