Questions tagged [glm]

For questions relating to generalized linear models. For the GLM math library, see the [glm-math] tag.

Generalized linear models are a class that encompasses a variety of standard statistical models, including ordinary least squares (a.k.a. linear models, OLS) regression, probit, logistic regression, Poisson regression, and other methods that can be expressed in the standard GLM form.

Consider whether your question is better suited to Cross Validated, the Stack Exchange site for statistics and machine learning. Questions on Stack Overflow should be about programming issues arising from fitting models to data.

In scientific software for statistical computing and graphics, a GLM can be estimated by the function glm.

2019 questions
4
votes
1 answer

Is it possible to fit a linear model with only a response variable?

If I do this, I get two coefficients (intercept and year) data <- data.frame(accidents=c(3,1,5,0,2,3,4), year=1:7) glm(accidents ~ year, family=poisson(link = log), data) Coefficients: (Intercept) year 0.7155 0.0557 But the…
nachocab
  • 13,328
  • 21
  • 91
  • 149
4
votes
1 answer

Bigglm in R: Limitations and Improvements of source code (E.g. Call to Fortran)

I have recently been using R to run a Generalised Linear Model(GLM) on a 100 mb csv file ( 9 million rows by 5 columns). The contents of this file includes 5 columns called depvar, var1,var2,var3,var4 and are all randomly distributed such that the…
Naz
  • 91
  • 1
  • 5
4
votes
0 answers

nlme error "Invalid formula for groups" although random effect specified

I have done some searching for this, but the mailing list posts I have found are associated with the person not specifying a random effect in nlme whereas I have done this. I also own the book Mixed Effect Models in S and S-Plus by Pinheiro and…
Michelle
  • 1,281
  • 2
  • 16
  • 31
4
votes
1 answer

Why is the quantile function not working for this dplyr function?

I'm working through Faraway's 2016 book Extending the Linear Model with R and have encountered an issue with the code that I don't know how to fix. Here is the relevant syntax leading up to the error: #### Load Data & Libraries…
Shawn Hemelstrand
  • 2,676
  • 4
  • 17
  • 30
4
votes
1 answer

How do I take the derivative of a line of best fit at a point without knowing the equation?

Model: mylogit <- glm(Result ~ kickLength, data = RegFg, family = "binomial") Probability plot: plot.dat <- data.frame(prob = RegFg$NumMade/RegFg$NumKick, kl = RegFg$kickLength, fit = predict(mylogit, RegFg)) plot.dat$fit_prob <-…
4
votes
1 answer

Why does summary() show different standard errors than coeftest()?

I run a glm() using robust standard errors. For a subsequent model comparison I calculate the difference of two regression models (coefficients & se). For that calculation I use the summary() function. However, the summary function of the models…
P_MA1
  • 43
  • 3
4
votes
1 answer

How to fit polynomial model of all predictors using "." in R?

I'm trying to fit a logistic regression model using all predictors as a polynomial model. I've tried doing this but didn't work: poly_model = glm(type~ poly(., 2), data=train_data, family=binomial) I'm using the built in dataset: train_data =…
user15300490
4
votes
3 answers

Correcting (or bootstrapping) the standard errors for a two stage glm (subscript out of bounds)

Cross posted on CrossValidated. I am trying to bootstrap my results for a variation of the 2SLS approach (2SRI), based on this link. For some reason, the bootstrap does not produce any results. library(sure) # for residual function and sample data…
Tom
  • 2,173
  • 1
  • 17
  • 44
4
votes
0 answers

How do you compute average marginal effects for glm.cluster models?

I am looking for a way to compute average marginal effects with clustered standard errors which i seem to be having a few problems with. My model is as follows: cseLogit <- miceadds::glm.cluster(data = data_long, …
4
votes
0 answers

Using mice inputed data sets in GLM analysis; can pooled model fit indices be obtained?

I used mice to impute five missing data sets, saved as the object "allImputations" in the code below. I then needed to complete linear and dichotomous regression analyses across the imputed data sets (see below for a successful…
Clar_k
  • 41
  • 2
4
votes
2 answers

AIC/AICc/BIC Formula in R for GLM

I'm trying to check that I understand how R calculates the statistic AIC, AICc (corrected AIC) and BIC for a glm() model object (so that I can perform the same calculations on revoScaleR::rxGlm() objects - particularly the AICc, which isn't…
Alan
  • 619
  • 6
  • 19
4
votes
2 answers

What is the difference between GLM and Logit model with statsmodels?

Can anyone please explain the difference between generalized linear model and logistic regression model table with statsmodels. Why do I get different results with both the models while performing logistic regression??
4
votes
1 answer

Simplest way to calculate AME, MEM, MER?

What is the simplest way to calculate average marginal effect, marginal effect at the mean and marginal effect at representative values for a logit model? I found this example, but the explanation is messy and frankly I don't understand…
4
votes
1 answer

Fit many glm models: improve speed

I am writing a function to fit many glm models. To just give you some ideas about the function, I include a small section of my code. With the help of several SO users, the function works for my analysis purpose now. However, sometimes, particularly…
Zhiqiang Wang
  • 6,206
  • 2
  • 13
  • 27
4
votes
2 answers

R probit regression marginal effects

I am using R to replicate a study and obtain mostly the same results the author reported. At one point, however, I calculate marginal effects that seem to be unrealistically small. I would greatly appreciate if you could have a look at my reasoning…
Tobias
  • 45
  • 1
  • 3