I have a binary dependent variable, and some numeric, binary, and ordinal independent variables. The whole idea is to create a predictive model based on all these data, which can be reported to others, i.e. an equation.  So let's say I clean my data, and use the glm function, I get something like this from coef(summary(my.model)):                          Estimate   Std. Error      z value     Pr(&gt;|z|) (Intercept)        -4.327404e+01 4.900553e+02 -0.088304404 9.296347e-01 var1                6.789180e-02 2.593766e-02  2.617499440 8.857663e-03 var21               1.826271e+00 4.428294e-01  4.124096884 3.721922e-05 var3.L             -3.871398e+00 1.179214e+03 -0.003283033 9.973805e-01 var3.Q             -1.228205e+01 8.789344e+02 -0.013973801 9.888509e-01 var3.C             -5.066052e-01 3.930721e+02 -0.001288835 9.989717e-01 var4.L             -7.128841e+00 3.728134e+02 -0.019121740 9.847440e-01 var4.Q             -2.954424e+00 2.152443e+02 -0.013725909 9.890487e-01   In this case the first var1 is just numeric values, var21 is binary (hence the 1 at the end?), and then the others are ordinal predictors with 4 and 3 factors respectively.  So let's just say this is the final model (it is most definitely not). How would I interpret this, and what should I report ?  I'm guessing that I will have some kind of term, which is inputted into the regular logistic regression equation, i.e:  prob = 1 / (1 + exp(-P))   where:  P = -43.2 + 0.067*var1 + 1.8*var2(1 or 0) + ...   And then what ? Do I use/keep both the linear term, quadratic term, and cubic term, or only select the one who has the lowest p-value (although in this case they are pretty similar and very high), or some other metric ?
123004
I have a Java code that performs a linear regression on a set of data using the Gauss-Jordan elimination. It calculates a linear, quadratic and cubic functions using the least squares method.  My problem is choosing a function out of the three that best models my data. This is ofcourse, without plotting the curve. So lets say I have a set of data {x:1,2,3,4} {y:3,8,910}, and I get a linear, quadratic and cubic function for it using the least squares method.   How do I choose which function is the right model for my data?
9039
I am analysing data of covid19 patients and trying to determine which illnesses could be detrimental for the outcome. In the original data table there are three possible outcomes - 1 (recovered), 2 (dead) and 3 (transferred to another department). For the binomial regression (glm) I reduced the data frame by filtering out the patients with the 3rd outcome. There are approx. 60 patients with the third outcome out of 230. Almost all the predictors are factorial. When I do the multinomial regression using multinom() the coefficient for a variable x ( the variable is factorial, takes values of 1 / 0) is 1.078e+00 with p-value 1.227e-04. However when I am doing binomial regression using function glm(family = &quot;binomial&quot;) for the same variable the coefficient is 21.435 with p-value 7.163e-05. Also, the confidence interval for the coefficient in the binomial model is very wide (approx. 3 - 52). The same goes with the multinomial model, the confidence intervals are 1e+00 - e+01 wide. What could be the problem? Which result is more reliable?
18328
If I want to use some proportion type independent variables in a logistic regression, then what will be the interpretation of the regression coefficients corresponding to those proportion type variables? Will that mean- "The change in log odds for per unit change in the proportions"?   But what will be meant by "per unit change" in this case? As the proportions lie within [0,1], I am getting a little confused with what a "per unit change" will mean in this scale. Does it mean 0.01 or 1%? (I am sorry for my noob thoughts!)  In my data the range of the proportions is 0 to 1, not multiplied by 100. Do I need to multiply them by 100? So that I can say "per unit change" means 1% change? I have seen that the coefficients do differ in scale if I multiply the proportions by 100. For example, a coefficient of -1.3 for proportions becomes -0.013 for percentages (when the proportions are multiplied by 100).
71408
Using R, I have fitted a linear model for a single response variable from a mix of continuous and discrete predictors. This is uber-basic, but I'm having trouble grasping how a coefficient for a discrete factor works.   Concept: Obviously, the coefficient of the continuous variable 'x' is applied in the form y = coefx(varx) + intercept but how does that work for a factor z if the factor is non-numeric? y = coefx(varx) + coefz(factorz???) + intercept   Specific: I have fitted a model in R as lm(log(c) ~ log(d) + h + a + f + h:a) where h and f are discrete, non-numeric factors. The coefficients are:  Coefficients:               Estimate  (Intercept)  -0.679695  log(d)        1.791294  h1            0.870735   h2           -0.447570   h3            0.542033    a             0.037362   f1           -0.588362   f2            0.816825  f3            0.534440 h1:a         -0.085658 h2:a         -0.034970  h3:a         -0.040637   How do I use these to create the predictive equation:  log(c) =  1.791294(log(d)) + 0.037362(a) + h??? + f???? + h:a???? + -0.679695   Or am I doing it wrong?   I THINK that that concept is if the subject falls in category h1 and f2, the equation becomes:   log(c) =  1.791294(log(d)) + 0.037362(a) +  0.870735  + 0.816825  + h:a???? + -0.679695   But I'm really not clear on how the h:a interactive term gets parsed. Thanks for going easy on me.
102727
Could someone advise me on how to interpret the estimates from a logistic regression using a cloglog link?  I have fitted the following model in lme4:  glm(cbind(dead, live) ~ time + factor(temp) * biomass,     data=mussel, family=binomial(link=cloglog))   For example, the estimate of time is 0.015.  Is it correct to say the odds of mortality per unit time is multiplied by exp(0.015) = 1.015113 (~1.5% increase per unit time). In other words are the estimates obtained in a cloglog expressed in log odds as is the case for a logit logistic regression?
9221
I am using logistic regression to solve the classification problem.  g = glm(target ~ ., data=trainData, family = binomial("logit"))   There are two classes (target): 0 and 1   When I run the prediction function, it returns probabilities.  p = predict(g, testData, type = "response")   However, it is not clear to me how to understand which class has been assigned?  Real  p   1   0.17568578 1   0.41698474 1   0.19151927 1   0.25587242 1   0.25604452 0   0.39976069 0   0.39910282 0   0.16879320   I appreciate if someone can explain me how this works based on the above example. Thanks
88765
I have a question about the interpretation of the coefficients of an interaction between continuous and categorical variable. here is my model:  model_glm3=glm(cog~lg_hag+race+pdg+sex+as.factor(educa)+(lg_hag:as.factor(educa)),                 data=base_708)  Coefficients:                          Estimate Std. Error t value Pr(&gt;|t|)     (Intercept)               21.4836     2.0698  10.380  &lt; 2e-16 *** lg_hag                     8.5691     3.7688   2.274  0.02334 *   raceblack                 -8.4715     1.7482  -4.846 1.61e-06 *** racemexican               -3.0483     1.7073  -1.785  0.07469 .   racemulti/other           -4.6002     2.3098  -1.992  0.04687 *   pdg                        2.8038     0.4268   6.570 1.10e-10 *** sexfemale                  4.5691     1.1203   4.078 5.15e-05 *** as.factor(educa)2         13.8266     2.6362   5.245 2.17e-07 *** as.factor(educa)3         21.7913     2.4424   8.922  &lt; 2e-16 *** as.factor(educa)4         19.0179     2.5219   7.541 1.74e-13 *** as.factor(educa)5         23.7470     2.7406   8.665  &lt; 2e-16 *** lg_hag:as.factor(educa)2 -21.2224     6.5904  -3.220  0.00135 **  lg_hag:as.factor(educa)3 -19.8083     6.1255  -3.234  0.00129 **  lg_hag:as.factor(educa)4  -8.5502     6.6018  -1.295  0.19577     lg_hag:as.factor(educa)5 -17.2230     6.3711  -2.703  0.00706 ***   lets say the equation of the model is:  E[cog] = a + b1(lg_hag) + b2(educa2*lg_hag) + b3(educa3*lg_hag) + b4(educa4*lg_hag)  + b5(pdg, centered) + other covars, where  b1 = difference in cog  with higher lg_hag among lowest education (coded as 1) b1 + b2 = difference in cog with higher lg_hag among middle education (coded as 2) b1 + b3 = difference in cog with higher lg_hag among high education (coded as 3) b1 + b3 = difference in cog with higher lg_hag among very high education (coded as 4) b5 = difference in cog with each unit increase in pdg   My question is: if my interpretation is right, how to construct confidence intervals for each effect estimate of interactions (e.g: b1+b2) from the confidence intervals of b1 and b2.
2225
If you have a variable which perfectly separates zeroes and ones in target variable, R will yield the following "perfect or quasi perfect separation" warning message:  Warning message: glm.fit: fitted probabilities numerically 0 or 1 occurred    We still get the model but the coefficient estimates are inflated.   How do you deal with this in practice?
39424
When I analyze my variables in two separate (univariate) logistic regression models, I get the following:  Predictor 1:    B= 1.049,    SE=.352,    Exp(B)=2.85,    95% CI=(1.43, 5.69),    p=.003    Constant:    B=-0.434,    SE=.217,    Exp(B)=0.65,                            p=.046  Predictor 2:    B= 1.379,    SE=.386,    Exp(B)=3.97,    95% CI=(1.86, 8.47),    p&lt;.001    Constant:    B=-0.447,    SE=.205,    Exp(B)=0.64,                            p=.029   but when I enter them into a single multiple logistic regression model, I get:  Predictor 1:    B= 0.556,    SE=.406,    Exp(B)=1.74,    95% CI=(0.79, 3.86),    p=.171 Predictor 2:    B= 1.094,    SE=.436,    Exp(B)=2.99,    95% CI=(1.27, 7.02),    p=.012    Constant:    B=-0.574,    SE=.227,    Exp(B)=0.56,                            p=.012   Both predictors are dichotomous (categorical). I have checked for multicollinearity.  I am not sure if I have given enough info, but I cannot understand why predictor 1 has gone from being significant to non-significant and why the odds ratios are so different in the multiple regression model. Can anyone provide a basic explanation of what is going on?
22322
What is the meaning of t value and Pr(&gt;|t|) when using summary() function on linear regression model in R?  Coefficients:                               Estimate Std. Error t value Pr(&gt;|t|)     (Intercept)                    10.1595     1.3603   7.469 1.11e-13 *** log(var)                        0.3422     0.1597   2.143   0.0322 *
100180
I'm running a GEE on 3-level  unbalanced data, using a logit link. How does this differ (in terms of the conclusions I can draw and the meaning of the coefficients) from a GLM with mixed effects (GLMM) and logit link?  More detail: The observations are single bernoulli trials. They are grouped clustered into classrooms and schools. Using R. Casewise omission of NAs. 6 predictors also interaction terms.   (I am not flipping children to see if they land heads-up.)  I'm inclined to exponentiate the coefficients  to odds-ratios. Does this have the same meaning in both?  There is something lurking in the back of my mind about "marginal means" in GEE models. I need that bit explained to me.  Thanks.
31320
In R I have a categorical variable that I performed logistic regression on and got the following result:  glm(formula = mortality ~ SMOKE, family = binomial, data = c.data)  Deviance Residuals:      Min       1Q   Median       3Q      Max   -0.2155  -0.2155  -0.2155  -0.1860   2.8515    Coefficients:             Estimate Std. Error z value Pr(&gt;|z|)     (Intercept)  -4.0483     0.3189 -12.694   &lt;2e-16 *** SMOKEN        0.2968     0.3559   0.834    0.404     --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  (Dispersion parameter for binomial family taken to be 1)      Null deviance: 492.45  on 2369  degrees of freedom Residual deviance: 491.72  on 2368  degrees of freedom AIC: 495.72  Number of Fisher Scoring iterations: 6   Is the value for the intercept the same as SMOKEY (has a history of smoking)?
43807
I am running a binomial logistic regression with a logit link function in R. My response is factorial [0/1] and I have two multilevel factorial predictors - let's call them $a$ and $b$ where $a$ has 4 factor levels  $(a_1,a_2,a_3,a_4)$ and $b$ has 9 factor levels $(b_1,b_2,\dotsc,b_9)$. Therefore:  mod &lt;- glm(y ~ a + b, family = binomial(logit), data=pretend) summary(mod)   The model output would then show all the information about the model as well as the coefficients.  There is a factor level for both a and b missing (a1 and b1) from the summary output. I understand that it is constrained in the "intercept" of the model. I have read that if I want to remove the intercept term and see the estimates for those factor levels I can just add -1 to the model formula, i.e.:  mod2 &lt;- glm(y ~ a + b - 1, family=binomial(logit), data=pretend) summary(mod2)   In the new model (mod2) the intercept term is then gone and variable a's factor-level a1 is given amongst the list of coefficients. But, variable b's factor-level b1 is still missing and given that there is no intercept term anymore, how can I interpret the odds-ratio for that factor level then?  Could someone please explain to me how to get the coefficient for b1 too and why this is happening?
83229
I am running an ordinal logistic regression in R and running into trouble when I include dummy variables.  My model works great with my first set of predictors.  Next I want to add dummy variables for each of the years represented in my dataset.    I created the dummy variables with car:recode in this manner (one statement like this for each of the 11 years)  fsd$admityear2000 &lt;- recode(fsd$ApplicationYear ,"2000=1;else=0")   The lrm model is specified as follows  library(Design) ddist&lt;- datadist(fsd) options(datadist='ddist') m4 &lt;- lrm(Outcome ~ relGPA + mcAvgGPA + Interview_Z + WorkHistory_years + GMAT + UGI_Gourman + admityear1999 + admityear2000 + admityear2001 + admityear2002 + admityear2003 + admityear2004 + admityear2005 + admityear2006 + admityear2007 + admityear2008 + admityear2009, data=fsd)   (sorry for all of the other random variables, but I don't want to introduce confusion by changing my code)  I get the error  singular information matrix in lrm.fit (rank= 22 ).  Offending variable(s): admityear2009 admityear2000 admityear1999  Error in lrm(Outcome ~ relGPA + mcAvgGPA + Interview_Z + WorkHistory_years +  :    Unable to fit model using “lrm.fit”   I understand that including all options of a dummy variable over-defines the model, but I get the error whether I include all 11 years or just 10.  I found a suggestion  to set the penalty parameter of lrm to a small positive value.  Setting it to 1 or 5 changes the error such that it only names one of the variables as offending.  The error doesn't go away even with penalty=100.  I'm pretty new to R, but loving the freedom so far.  Thanks for any help!  Responses and Lessons   Factors are awesome and I can't believe I didn't notice them earlier. Man that cleans up my code a lot.  Thanks! My DV, 'Outcome' is indeed ordinal and after making it a factor(), I also made it ordered(). The str() command is also awesome and this is what my data now looks like (with some of the non-relevant variables omitted)   output:  str(fsd)      Outcome      : Ord.factor w/ 3 levels "0"&lt;"1"&lt;"2" relGPA       : num   mcAvgGPA     : num  admitschool  : Factor w/ 4 levels "1","2","3","4" appyear      : Factor w/ 11 levels "1999","2000",..    both lrm() and polr() now run successfully, and they both deal with appyear by dropping some values of the factor.  lrm() drops 1999, 2000, and 2001 while polr() just drops 1999 and 2000.  lrm() gives no warnings while polr() says "design appears to be rank-deficient, so dropping some coefs."  This is an improvement, but I still don't understand why more than one value needs to be dropped. xtabs shows that there isn't full seperation right?   output:  xtabs(~fsd$appyear + fsd$Outcome)            fsd$Outcome fsd$appyear    0    1    2        1999 1207  123  418        2000 1833  246  510        2001 1805  294  553        2002 1167  177  598        2003 4070  158 1076        2004 2803  106 1138        2005 3749  513 2141        2006 4429  519 2028        2007 6134  670 1947        2008 7446  662 1994        2009 4411   86 1118
60604
First I'm a little bit confused with the assumptions of a model with binomial response and logit link function. Since it is basically a logistic regression. Today one of my professors told me that I had to prove normality of my residuals, but of what I know the assumptions are:  First, binary logistic regression requires the dependent variable to be binary and ordinal logistic regression requires the dependent variable to be ordinal.  Second, logistic regression requires the observations to be independent of each other.  In other words, the observations should not come from repeated measurements or matched data.  Third, logistic regression requires there to be little or no multicollinearity among the independent variables.  This means that the independent variables should not be too highly correlated with each other.  Also these are the plots I have:     So basically my question is: what assumptions can I prove/not prove with these plots?
80561
How can I account for a nonlinear independent variable in a logistic regression?  For example, consider this data set:  b1  b2  b3  b4  b5 1   1   0   0   20 0   1   0   0   20 1   0   0   0   13 1   1   1   0   8 1   1   0   1   5 0   1   0   1   4 1   1   0   1   5 0   0   0   0   8 0   0   1   0   13 1   0   0   1   20 1   0   0   0   29 1   1   0   1   40 1   0   0   0   53 0   1   1   0   68   Suppose I gathered some data like the above (suppose I had 10,000 rows) and I want to use them to predict future sets of similar data with an equation generated by a logistic regression. I get the above data. My independent variables are b1 through b5. By looking at the data, I can clearly see that independent variables b1 through b4 are binary (maybe they are male/female, rent/own, etc).   However I see that b5 is clearly not binary. Upon graphing it and looking at the numbers I determine that the b5 variable has a bathtub shaped U curve with an equation of b5=(x-4)^2+4.   I understand that using the b5 variable as it is would screw up my logistic regression - since any interval independent variables must have a linear relationship with the dependent variable.   Yet, I must account for the variable b5 in my data set while doing a logistic regression for it to be accurate and predict well (right?).  Given the above data, how would I go about making a predictive model with a logistic regression? Any references online or in books would greatly be appreciated as I am having trouble finding a good explanation of the above.  Cheers =)  EDIT:  Sorry if my question is unclear.  Consider this: Suppose we had the following data on many people:  Y: Whether they had a stroke before the age of 50 or not 1. Whether they own a pet or not. 2. Whether they graduated college or not. 3. Whether they are male or female. 4. The number of hours they exercise every week.  We want to train a logistic regression model based on historical data to predict if someone in the future with the same data will be more apt or not to have a stroke before the age of 50.  The problem I am having is with the last variable. A continuous ratio variable like "number of hours exercised each week."  Exercising more each week may have diminishing returns on health and thus having a stroke. For example decreasing an increasing rate. Or maybe (totally made up) exercising a little bit is really good for you, exercising a moderate amount is really bad for you, and exercising a lot is really good for you again. We might have a U shaped curve like (x-4)^2+4 for example when plotting health to exercise.   I would image that having a curved, non-linear independent variable in a logistic regression like the one I described above would cause problems. Am I right? And if so, what kinds of things can you do to still include the variable in the logistic regression. Perhaps a transformation? Is that all?
122822
I am using a binomial regression model for presence/absence, with 20 independent variables to test. The data has x and y coordinates and I would like to understand how can I take into account the spatial autocorrelation.  I already studied the correlation between the variables and run the same model for 1000 different samples (I have a big dataset that allows me to do this) to understand the distribution of each parameter and check for variables that might be introducing problems in my model.   glm_model &lt;- glm(PA ~ Var1 + Var2 + Var3 + Var4 + Var5,family=binomial(link=logit))  However I believe I also need to account for spatial autocorrelation. I saw that there is a package that might help me (spdep), however I am not sure I completely understand if I can use my model or not. My question is what are my options ?