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
7
votes
1 answer

How to calculate the predicted probability of negative binomial regression model?

I use glm.nb() function in R MASS package to estimate the parameters of a negative binomial regression model. How could I calculate the predicted probability (probability mass function) given new data, which R function can I use? My dataset is as…
user22062
  • 187
  • 2
  • 5
7
votes
1 answer

glmer - predict with binomial data (cbind count data)

I am trying to predict values over time (Days in x axis) for a glmer model that was run on my binomial data. Total Alive and Total Dead are count data. This is my model, and the corresponding steps below.…
user3250522
  • 71
  • 1
  • 1
  • 2
7
votes
4 answers

cost function in cv.glm of boot library in R

I am trying to use the crossvalidation cv.glm function from the boot library in R to determine the number of misclassifications when a glm logistic regression is applied. The function has the following signature: cv.glm(data, glmfit, cost,…
user695652
  • 4,105
  • 7
  • 40
  • 58
7
votes
1 answer

How do I use a custom link function in glm?

I don't want to use the standard log link in glm for Poisson regression, since I have zeros. Consider the following code: foo = 0:10 bar = 2 * foo glm(bar ~ foo, family = poisson(link = "identity")) I get the error: Error: no valid set of…
Xodarap
  • 11,581
  • 11
  • 56
  • 94
7
votes
2 answers

How to extract a p-value when performing anova() between two glm models in R

So, I'm trying to compare two models, fit1 and fit2. Initially, I was just doing anova(fit1,fit2), and this yielded output that I understood (including a p-value). However, when I switched my models from lm()-based models to glm()-based models,…
Atticus29
  • 4,190
  • 18
  • 47
  • 84
7
votes
3 answers

R : Pass argument to glm inside an R function

I am trying to get used to scoping issues in R. I'd like to call the function glm() inside a function but it does not work, apparently for scoping reasons I did not manage to fix with the functions assign() or eval(). Here is a simplified version:…
user1431694
  • 715
  • 1
  • 11
  • 22
6
votes
2 answers

How do I extract lmer fixed effects by observation?

I have a lme object, constructed from some repeated measures nutrient intake data (two 24-hour intake periods per RespondentID): Male.lme2 <- lmer(BoxCoxXY ~ -1 + AgeFactor + IntakeDay + (1|RespondentID), data = Male.Data, weights =…
Michelle
  • 1,281
  • 2
  • 16
  • 31
6
votes
1 answer

How to set the Coefficient Value in Regression; R

I'm looking for a way to specify the value of a predictor variable. When I run a glm with my current data, the coefficient for one of my variables is close to one. I'd like to set it at .8. I know this will give me a lower R^2 value, but I know a…
Burton Guster
  • 2,213
  • 8
  • 31
  • 29
6
votes
2 answers

Predicting/imputing the missing values of a Poisson GLM Regression in R?

I'm trying to explore ways of imputing missing values in a data set. My dataset contains the number of counts of an occurance (Unnatural, Natural and the sum Total) for Year(2001-2009), Month(1-12), Gender(M/F) and AgeGroup(4 groups). One of the…
OSlOlSO
  • 441
  • 7
  • 14
6
votes
0 answers

Regression output is different on different computers

We are fitting a generalized linear model to a set of data using R on Fedora 33. We are 3 people that have the exact same data set, exact same OS (Fedora 33) , exact same R version and package version. The sessionInfo() output also looks the same.…
compIssues
  • 61
  • 2
6
votes
1 answer

Is there a difference between gamma hurdle (two-part) models and zero-inflated gamma models?

I have semicontinuous data (many exact zeros and continuous positive outcomes) that I am trying to model. I have largely learned about modeling data with substantial zero mass from Zuur and Ieno's Beginner's Guide to Zero-Inflated Models in R, which…
Kellan Baker
  • 375
  • 3
  • 11
6
votes
2 answers

How to interpret the probabilities (p0, p1) of the result of h2o.predict()

I would like to understand the meaning of the value (result) of h2o.predict() function from H2o R-package. I realized that in some cases when the predict column is 1, the p1 column has a lower value than the column p0. My interpretation of p0 and p1…
David Leal
  • 6,373
  • 4
  • 29
  • 56
6
votes
2 answers

Gamma GLM: NaN production and divergence errors

Intro I'm trying to construct a GLM that models the quantity (mass) of eggs the specimens of a fish population lays depending on its size and age. Thus, the variables are: eggW: the total mass of layed eggs, a continuous and positive …
A. E.
  • 61
  • 5
6
votes
1 answer

Standard errors discrepancies between SAS and R for GLM gamma distribution

I am comparing GLM output from R and SAS of a model with a Gamma distribution. The point estimations are identical, but they have different estimation of the standard error and therefore different p-values. Does anyone know why? I am wondering if R…
YDao
  • 325
  • 2
  • 15
6
votes
1 answer

Why is `speedglm` slower than `glm`?

I am trying to use speedglm to achieve a faster GLM estimation than glm, but why it is even slower? set.seed(0) n=1e3 p=1e3 x=matrix(runif(n*p),nrow=n) y=sample(0:1,n,replace = T) ptm <- proc.time() fit=glm(y~x,family=binomial()) print(proc.time()…
hxd1011
  • 885
  • 2
  • 11
  • 23