All,  I have a dataset that contains more than 45k rows and 2 columns. Below is dput() of first 50 rows. One thing to consider is that category  column contains 34 factor of different levels. I am using Logistic regression model to predict the category based on other two columns. Below is my model. However, I am getting warning in my model. I Googled the warning, and found that there might be linear relationship between my DV(Dependent Variable) and IV (Independent Variable). I am not sure how to deal with this warning. Some post suggested to perform Log transformation, but not sure How to perform in my model. Being a newbie to R if you could provide an explanation of how to deal with the warning that will be great.  &gt; dput(droplevels(head(new_df1, 10))) structure(list(category = structure(c(1L, 5L, 7L, 8L, 9L, 10L,  2L, 3L, 4L, 6L), .Label = c("", "baking", "canned", "crackers",  "DELI", "dessert", "MEAT", "NUTRITION", "PASTRY", "PRODUCE"), class = "factor"),      quantity = c(5L, 27L, 3L, 1L, 29L, 94L, 70L, 20L, 12L, 122L     ), sales_value = c(11.6, 86.83, 13.46, 2, 52.4, 133.75, 160.15,      38.81, 29.91, 208.75)), row.names = c(NA, 10L), class = "data.frame") &gt; dput(droplevels(head(new_df1, 50))) structure(list(category = structure(c(1L, 5L, 20L, 21L, 24L,  27L, 2L, 3L, 4L, 6L, 7L, 8L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,  17L, 18L, 19L, 22L, 23L, 25L, 26L, 28L, 1L, 5L, 20L, 21L, 24L,  27L, 2L, 3L, 4L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 15L, 16L,  17L, 18L, 19L, 22L), .Label = c("", "baking", "canned", "crackers",  "DELI", "dessert", "drinks", "drug", "ethnic", "food", "food add-ons",  "frozen dessert", "frozen food", "frozen meat", "fruit", "health",  "household", "instant dinner", "meat", "MEAT", "NUTRITION", "other",  "packaged foods", "PASTRY", "personal care", "produce", "PRODUCE",  "seasonal"), class = "factor"), quantity = c(5L, 27L, 3L, 1L,  29L, 94L, 70L, 20L, 12L, 122L, 81L, 1L, 78L, 82L, 30L, 7L, 1L,  33L, 5L, 56L, 4L, 66L, 5L, 45L, 37L, 36L, 3L, 1L, 41L, 2L, 18L,  20L, 115L, 83L, 32L, 24L, 118L, 72L, 2L, 1L, 73L, 92L, 44L, 16L,  21L, 1L, 57L, 1L, 68L, 14L), sales_value = c(11.6, 86.83, 13.46,  2, 52.4, 133.75, 160.15, 38.81, 29.91, 208.75, 204.38, 3.99,  128.27, 193.84, 56.27, 11.75, 1.5, 41.59, 33.51, 140.42, 7, 170.11,  14.08, 84.93, 111.53, 33.62, 2.07, 2.99, 125.34, 4.45, 46.33,  42.91, 132.35, 181.04, 51.64, 59.91, 260.86, 189.15, 12.68, 1.09,  115.18, 210.44, 111.53, 31.4, 25.16, 2.29, 142.57, 2.5, 179.86,  59.28)), row.names = c(NA, 50L), class = "data.frame")   My model  fit_glm = glm(category~.,new_df1,family = 'binomial')   Warning:  Warning message: glm.fit: fitted probabilities numerically 0 or 1 occurred
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?
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?
53856
I am running logistic regression on a small dataset which looks like this:    After implementing gradient descent and the cost function, I am getting a 100% accuracy in the prediction stage, However I want to be sure that everything is in order so I am trying to plot the decision boundary line which separates the two datasets.  Below I present plots showing the cost function and theta parameters. As can be seen, currently I am printing the decision boundary line incorrectly.    Extracting data  clear all; close all; clc;  alpha = 0.01; num_iters = 1000;  %% Plotting data x1 = linspace(0,3,50); mqtrue = 5; cqtrue = 30; dat1 = mqtrue*x1+5*randn(1,50);  x2 = linspace(7,10,50); dat2 = mqtrue*x2 + (cqtrue + 5*randn(1,50));  x = [x1 x2]'; % X  subplot(2,2,1); dat = [dat1 dat2]'; % Y  scatter(x1, dat1); hold on; scatter(x2, dat2, '*'); hold on; classdata = (dat&gt;40);   Computing Cost, Gradient and plotting  %  Setup the data matrix appropriately, and add ones for the intercept term [m, n] = size(x);  % Add intercept term to x and X_test x = [ones(m, 1) x];  % Initialize fitting parameters theta = zeros(n + 1, 1); %initial_theta = [0.2; 0.2];  J_history = zeros(num_iters, 1);   plot_x = [min(x(:,2))-2,  max(x(:,2))+2]  for iter = 1:num_iters  % Compute and display initial cost and gradient     [cost, grad] = logistic_costFunction(theta, x, classdata);     theta = theta - alpha * grad;     J_history(iter) = cost;      fprintf('Iteration #%d - Cost = %d... \r\n',iter, cost);       subplot(2,2,2);     hold on; grid on;     plot(iter, J_history(iter), '.r');  title(sprintf('Plot of cost against number of iterations. Cost is %g',J_history(iter)));     xlabel('Iterations')     ylabel('MSE')     drawnow      subplot(2,2,3);     grid on;     plot3(theta(1), theta(2), J_history(iter),'o')     title(sprintf('Tita0 = %g, Tita1=%g', theta(1), theta(2)))     xlabel('Tita0')     ylabel('Tita1')     zlabel('Cost')     hold on;     drawnow      subplot(2,2,1);     grid on;         % Calculate the decision boundary line     plot_y = theta(2).*plot_x + theta(1);  % &lt;--- Boundary line      % Plot, and adjust axes for better viewing     plot(plot_x, plot_y)     hold on;     drawnow  end  fprintf('Cost at initial theta (zeros): %f\n', cost); fprintf('Gradient at initial theta (zeros): \n'); fprintf(' %f \n', grad);   The above code is implementing gradient descent correctly (I think) but I am still unable to show the boundary line plot. Any suggestions would be appreciated.    logistic_costFunction.m  function [J, grad] = logistic_costFunction(theta, X, y)      % Initialize some useful values     m = length(y); % number of training examples      grad = zeros(size(theta));      h = sigmoid(X * theta);     J = -(1 / m) * sum( (y .* log(h)) + ((1 - y) .* log(1 - h)) );      for i = 1 : size(theta, 1)         grad(i) = (1 / m) * sum( (h - y) .* X(:, i) );     end  end   EDIT:  As per the below answer by @Esmailian, now I have something like this:  [m, n] = size(x);  x1_class = [ones(m, 1) x1' dat1']; x2_class = [ones(m, 1) x2' dat2'];  x = [x1_class ; x2_class]
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?
119859
I have a model similar to below with a continuous outcome, continuous predictor and a categorical variable. the goal of this analysis is to make inferences on the group variable. The issue is that y is bounded by x in the form of y >= -x. When the model makes predictions you can see in the plot below that the predicted value is outside the possible range. See the last plot.   How can this be remedied? A custom loss function to penalize going beyond the bound and use gradient descent regression? Or is there some other way? Thank you.   x =   rep(seq(-10,10,1),each=5)  y =  rep(0,length(x) ) weights = sample( seq(1,1000,1) ,length(x)) groups = rep( letters[1:5], times =length(x)/5  )   ## the outcome y has the relationship y &gt;= -x for(i in 1:length(x)){   y[i] = sample(  seq(-x[i],-x[i]+ ifelse(x[i]&lt;0 ,                                            sample(seq(1,10,.1),1),                                           sample(seq(5,40,.1),1) ),1)                        ,1) }   dat =data.frame(x = x, y = y, weights = weights, group = groups) model = lm(dat = dat, y ~ x + group + group * x, weights = weights) dat$FIT= predict(model, dat, allow.new.levels = TRUE)  library(ggplot2) ggplot(data = dat, aes(x = x, y = y, color = group))+geom_point( aes(size = weights))+ geom_line(data = dat, aes(x = x, y = FIT, color = group))    #data for new predictions newdata = data.frame( x = seq(-100,100,1) ,                        group = rep("c", length( seq(-100,100,1) )),                       bound = -seq(-100,100,1)                       )  ## when pridicting new data the outcome y has the relationship y &gt;= -x ## but the predicted vales are below the bound. See how red line is below blue to the left of zero new_preds  = predict(model, newdata, allow.new.levels = TRUE) ggplot(data = newdata, aes(x = x, y = new_preds, color = group))+geom_line()  +   geom_line(data = newdata, aes(x = x, y = bound, color = "green"))
53093
I'm working on a multiple logistic regression in R using glm. The predictor variables are continuous and categorical. An extract of the summary of the model shows the following:  Coefficients:                Estimate Std. Error z value Pr(&gt;|z|) (Intercept)   2.451e+00  2.439e+00   1.005   0.3150 Age           5.747e-02  3.466e-02   1.658   0.0973 . BMI          -7.750e-02  7.090e-02  -1.093   0.2743 ... --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1   Confidence intervals:                    2.5 %       97.5 % (Intercept)  0.10969506 1.863217e+03 Age          0.99565783 1.142627e+00 BMI          0.80089276 1.064256e+00 ...   Odd ratios:                   Estimate Std. Error   z value Pr(&gt;|z|) (Intercept)  1.159642e+01  11.464683 2.7310435 1.370327 Age          1.059155e+00   1.035269 5.2491658 1.102195 B            9.254228e-01   1.073477 0.3351730 1.315670 ...   The first output shows that $Age$ is significant. However, the confidence interval for $Age$ includes the value 1 and the odds ratio for $Age$ is very close to 1. What does the significant p-value from the first output mean? Is $Age$ a predictor of the outcome or not?
103364
In  titled "CHOOSING AMONG GENERALIZED LINEAR MODELS APPLIED TO MEDICAL DATA" the authors write:     In a generalized linear model, the mean is transformed, by the link   function, instead of transforming the response itself. The two methods   of transformation can lead to quite different results; for example,   the mean of log-transformed responses is not the same as the logarithm   of the mean response. In general, the former cannot easily be   transformed to a mean response. Thus, transforming the mean often   allows the results to be more easily interpreted, especially in that   mean parameters remain on the same scale as the measured responses.   It appears they advise the fitting of a generalized linear model (GLM) with log link instead of a linear model (LM) with log-transformed response. I do not grasp the advantages of this approach, and it seems quite unusual to me.  My response variable looks log-normally distributed. I get similar results in terms of the coefficients and their standard errors with either approach.  Still I wonder: If a variable has a log-normal distribution, isn't the mean of the log-transformed variable preferable over the log of the mean untransformed variable, as the mean is the natural summary of a normal distribution, and the log-transformed variable is normally distributed, whereas the variable itself is not?
73641
Perhaps a very basic question but one that has me confused. Say, in a correlation table the relationship between A and the DV (B) is .351, but -.150 in the OLS model (where you have added C, D and E variables), what does this then mean? In other words: if the C to E variables not only change the coefficient of A but even make it go from negative to positive, does that indicate an undesirable interaction effect between the variables used in the OLS? I have been checking the VIF scores for this but based on low VIF I have no reason to fear multicollinearity. What (if anything) is wrong?  I'm trying to wrap my head around this constructing a simple example for myself to understand. Say A is a person's height and B is the distance this person jumps. There probably is a positive correlation (higher means longer legs, means longer distance jumping). What variables C to E would offset this person's height, even to the extent that this person's height is working against him when jumping (making the coefficient between A and DV B in the OLS negative)?
97309
In linear regression, I've seen (granted, not many) situations where basic transformations to some of the predictors can significantly improve the fit and stability of the model, and often a scatterplot of the response variable vs each individual predictor can provide useful clues as to whether a transformation can help.   Is there a similar approach that would work for logistic regression -  i.e., what is an intuitive way to determine whether any predictor transformations can help?
109942
Is there i.i.d. assumption on the response variable of logistic regression?  For example, suppose we have $1000$ data points. It seems the response $Y_i$ is coming from a Bernoulli distribution with $p_i=\text{logit}^{-1}(\beta_0+\beta_1 x_i)$. Therefore, we should have $1000$ Bernoulli distributions, with different parameter $p$.  So, they are "independent", but are not "identical".  Am I right?    PS. I learned logistic regression from "machine learning" literature, where we optimize the objective function and check if it is good in testing data, without talking too much about assumptions.   My question started with this post  Where I try to learn more on statistical assumptions.
92430
I'm exploring the effects of removing the intercept in a logistic regression model.  Assume a model:  $$logit(Y = 1) = \beta_1 x + \beta_2z + 0$$  with $x$ and $z$ being categorical variables with 2 levels each and no intercept.  I understood that having no intercept with categorical predictors produce coefficients that compare the $P(Y = 1)$ in each level of the two predictor against a null case where $P(Y=1) = 0.5$ or $logit(Y=1) = 0$.  I noticed a phenomenon that can understand. Using glm() function in R if you change the order of the variable in the right hand part of the formula, the coefficients change too. But even more oddly, the coefficient of the first variable is always the same.  Here's an R demo:  y &lt;- as.factor(sample(rep(1:2), 30, T)) x &lt;- as.factor(sample(rep(1:2), 30, T)) z &lt;- as.factor(sample(rep(1:2), 30, T))  coef(glm(y ~ x + z - 1, binomial) #        x1         x2         z2  #-0.1764783  0.3260739 -0.1335192  coef(glm(y ~ z + x - 1, binomial)) #        z1         z2         x2  #-0.1764783 -0.3099976  0.5025523    As you can see the first predictors have the same coefficient while the other are different in the two models.  Here is what I expected and instead behave differently than what I though:   Since every level of the two predictors is compared to the same null case, I expected to have the same coefficients in the two models, independently from the order in which I use them. I expected to see the coefficients of every level of every predictor, instead the coefficient for the 1 level of the second predictor is not shown. I therefore assume that only the first variable is compared against the null case, while the second is compared against a reference level; but what is this level? Is it $P(Y = 1 | X = 1 \cap Z = 1)$? Reproducing one of the models WITH the intercept we get:  coef(glm(y ~ x + z - 1, binomial) #        x1         x2         z2  #-0.1764783  0.3260739 -0.1335192  coef(glm(y ~ x + z, binomial)) #(Intercept)         x2          z2  #-0.1764783   0.5025523  -0.1335192    As expected x1 become the intercept, and x2 is likely relative to x1. z1 is missing also in this case and z2 is the same as in the model without intercept.  Thus should I assume that the comparison against the null case $P(Y = 1) = 0.5$ is made only for the first variable in a formula, while the other are compared against the usual intercept? Is this behavior normal? What about the fact that the first coefficient has the same value whichever the order of the predictors in the formula? What if I want to compare all level of each predictor against the null case and have a coefficient for all levels? Or it's theoretically impossible for some reason I don't get?
69991
I am learning logistic regression from The elements of statistical learning: data mining, inference, and prediction, by Trevor Hastie, Robert Tibshirani, Jerome H. Friedman.  Suppose $G$ is a random variable representing response taking class label in $\{1,\ldots,K \}$, and $X$ is a random vector representing predictor taking values in $\mathbb{R}^n$.  After modeling $P(G = k|X = x; \theta), k=1,\ldots,K, x \in \mathbb{R}^n$ by logistic model in , the parameter $\theta$ is estimated from samples $\{(x_i,k_i), i=1,\ldots,N \}$ in section :     Logistic regression models are usually ﬁt by maximum likelihood, using   the conditional likelihood of $G$ given $X$. Since $P(G|X)$ completely   specifies the conditional distribution, the multinomial distribution   is appropriate. The log likelihood for $N$ observations is  $$ℓ(θ) = \sum_{i=1}^N \log P(G = k_i|X = x_i; \theta) $$   My question is how the estimation method is maximum likelihood.   Generally speaking, MLE is to estimate parameter $\theta$ of a single distribution $p(z;\theta)$ from its i.i.d. samples $\{z_i, i=1,\ldots,N \}$ by maximizing $\log p(x_1,\ldots, x_N; \theta) = \sum_{i=1}^N \log p(x_i; \theta) $, the log of joint distribution of the samples.  The estimation for logistic regression as in the quote seems not using MLE, because:   $P(G = k|X = x_i; \theta), i=1,\ldots,N $ are $N$ different distributions, instead of just one distribution as for MLE; in $ℓ(θ) = \sum_{i=1}^N \log P(G = k|X = x_i; \theta) = \log     \prod_{i=1}^N P(G = k|X = x_i; \theta)$, I wonder how to explain that "${ (k_i|x_i), i=1,\ldots,N }$" are independent and therefore $\prod_{i=1}^N P(G = k_i|X = x_i; \theta)$ is their joint distribution, as I don't know how to understand $(k_i|x_i)$ which seems not make sense.   My guess answer is that $\{(x_i,k_i), i=1,\ldots,N \}$ are assumed to be i.i.d. samples of the single distribution for $(X,G)$. So MLE for the distribution of $(X,G)$ is to maximize $$ \log P((x_1,k_1),\ldots,(x_N,k_N))  = \log \prod_{i=1}^N P(x_i,k_i)  $$ $$ = \log \prod_{i=1}^N P(k_i | x_i) P(x_i) = \log \prod_{i=1}^N P(k_i | x_i) + \log \prod_{i=1}^N P(x_i) $$ $P(k_i | x_i)$ is parameterized by $\theta$ as $P(k_i | x_i;\theta$, while $P(x_i)$ is assumed to be independent of $\theta$, so to solve for $\theta$ by MLE for the distribution of $(X,G)$ is equivalent to maximize $\log \prod_{i=1}^N P(k_i | x_i; \theta)$. I wonder if this is a reasonable explanation, and what yours are?  Thanks and regards!
31278
I have eight independent variables and one dependent.  I have run a correlation matrix, and 5 of them have a low correlation with the DV.  I have then run a stepwise multiple regression to see whether any/all of the IVs can predict the DV.  The regression showed that only two IVs can predict the DV (can only account for about 20% of the variance though), and SPSS removed the rest from the model.  My supervisor reckons that I have not run the regression correctly, as due to the strength of the correlations, I should have found more predictors in the regression model. But the correlations were tiny, so my question is: if IVs and the DV hardly correlate, can IVs still be good predictors of the DV?
90412
I need to analyse data and am unsure whether or not I should use a multinomial logistic regression analysis or a binary logistic regression analysis. I have just conducted a latent class analysis and am interested in seeing if my variables can predict class membership. There are only two classes and so my response variable only has two categories; however the variables range from having 2 to 3 to 4 and are mostly nominal categorical data.
62633
I am running an analysis on the probability of loan default using logistic regression and random forests.    When I use logistic regression, the prediction is always all '1' (which means good loan).  I have never seen this before, and do not know where to start in terms of trying to sort out the issue.  There are 22 columns with 600K rows.  When I decrease the # of columns I get the same result with logistic regression.   Why could the logistic regression be so wrong?  **Actual from the data**  0 :   41932  1 :   573426  **Logistic regression output**   prediction for 1 when actually 0: 41932 prediction for 1 when actually 1:573426  A**s you can see, it always predicts a 1**   **Random forests does better:**  actual 0, pred 0 : 38800  actual 1, pred 0 : 27  actual 0, pred 1 : 3132 actual 1, pred 1 : 573399
32541
I am new to data analysis and now working on a Mixed Effects Logistic Regression Model.  Currently, I have the following data frame (model_data):  Road Id Vehicle_id  entry_time           exit_time          1        1        2017-01-31 00:00:00  2017-01-31 00:00:00 last_veh_time  vehicle_type     status 300            4 wheel          0    Likewise, I have the information (nearly a million rows) of all the vehicles entering a place and exiting the same place.  Status can be either $1$ or $0$ for all of these.  last_veh_time is the last vehicle passed the same place before how much time.    I want to know the probability of a getting status $0$ for a vehicle based on the entry_time and last_veh_time. To do this, I created the model:   model = glmer(status ~last_veh_time + (1 |link ),               data=model_data, REML=FALSE)   Is this the right approach?  Any help is appreciated.
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.