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
17
votes
4 answers

Selecting the statistically significant variables in an R glm model

I have an outcome variable, say Y and a list of 100 dimensions that could affect Y (say X1...X100). After running my glm and viewing a summary of my model, I see those variables that are statistically significant. I would like to be able to select…
Pritish Kakodkar
  • 307
  • 1
  • 4
  • 12
16
votes
2 answers

Difference between glmnet() and cv.glmnet() in R?

I'm working on a project that would show the potential influence a group of events have on an outcome. I'm using the glmnet() package, specifically using the Poisson feature. Here's my code: # de <- data imported from sql connection x <-…
Sean Branchaw
  • 597
  • 1
  • 5
  • 21
16
votes
6 answers

R error which says "Models were not all fitted to the same size of dataset"

I have created two generalised linear models as follows: glm1 <-glm(Y ~ X1 + X2 + X3, family=binomial(link=logit)) glm2 <-glm(Y ~ X1 + X2, family=binomial(link=logit)) I then use the anova function: anova(glm2,glm1) but get an error…
REnthusiast
  • 1,591
  • 3
  • 16
  • 18
15
votes
1 answer

How to plot interaction effects from extremely large data sets (esp. from rxGlm output)

I am currenlty computing glm models off a huge data data set. Both glm and even speedglm take days to compute. I currently have around 3M observations and altogether 400 variables, only some of which are used for the regression. In my regression I…
deca
  • 730
  • 1
  • 8
  • 24
15
votes
1 answer

Getting predicted values at response scale using broom::augment function

I'm fitting glm model in R and can get predicted values at response scale using predict.glm(object=fm1, type="response") where fm1 is the fitted model. I wonder how to get predicted values at response scale using augment function from broom package.…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
15
votes
3 answers

How to fit autoregressive poisson mixed model (count time series) in R?

My task is to assess how various environmental variables affect annual population fluctuations. For this, I need to fit poisson autoregressive model for time-series counts: Where Ni,j is the count of observed individuals at site i in year j,…
Tomas
  • 57,621
  • 49
  • 238
  • 373
14
votes
2 answers

Cross validation for glm() models

I'm trying to do a 10-fold cross validation for some glm models that I have built earlier in R. I'm a little confused about the cv.glm() function in the boot package, although I've read a lot of help files. When I provide the following…
Error404
  • 6,959
  • 16
  • 45
  • 58
13
votes
2 answers

Understanding glm$residuals and resid(glm)

Can you tell me what is returned by glm$residuals and resid(glm) where glm is a quasipoisson object. e.g. How would I create them using glm$y and glm$linear.predictors. glm$residuals n missing unique Mean .05 .10 .25 .50 …
Michael Bishop
  • 1,875
  • 4
  • 17
  • 23
12
votes
1 answer

Default starting values fitting logistic regression with glm

I'm wondering how are default starting values specified in glm. This post suggests that default values are set as zeros. This one says that there is an algorithm behind it, however relevant link is broken. I tried to fit simple logistic regression…
Adela
  • 1,757
  • 19
  • 37
12
votes
2 answers

What does predict.glm(, type="terms") actually do?

I am confused with the way predict.glm function in R works. According to the help, The "terms" option returns a matrix giving the fitted values of each term in the model formula on the linear predictor scale. Thus, if my model has form f(y) =…
David Dale
  • 10,958
  • 44
  • 73
12
votes
2 answers

Fractional Response Regression in R

I am trying to model my data in which the response variable is between 0 and 1, so I have decided to use fractional response model in R. From my current understanding, the fractional response model is similar to logistic regression, but it uses…
newbie
  • 917
  • 8
  • 21
12
votes
1 answer

R: Incompatible Dimensions Error vglm function in VGAM

TL;DR I am running Tobit regressions with the VGAM package in R -- Here is a toy dataset that is consistently giving me an error that I have not been able to diagnose: library(data.table) library(VGAM) > sessionInfo()$otherPkgs $VGAM Package:…
mlegge
  • 6,763
  • 3
  • 40
  • 67
12
votes
4 answers

How to save glm result without data or only with coeffients for prediction?

When I use the following R code, model_glm=glm(V1~. , data=xx,family="binomial"); save(file="modelfile",model_glm); The size of modelfile will be as much as the data, which will be 1gig in my case. How can I remove the data part in the result of…
Indicator
  • 361
  • 2
  • 13
11
votes
2 answers

glm starting values not accepted log-link

I want to run a Gaussian GLM with a log link and an offset. The following problems arise: y <- c(1,1,0,0) t <- c(5,3,2,4) No problem: exp(coef(glm(y~1 + offset(log(t)), family=poisson))) with family=gaussian, starting values need to be specified,…
Andi
  • 111
  • 1
  • 1
  • 4
11
votes
1 answer

Is there a way to obtain coefficients for each step of the optimization algorithm in glm function?

When one performs a logit regression in R, it is possible to obtain coefficients after the optimization algorithm has converged (or not) with coefficients() function: library(MASS) data(menarche) glm.out = glm(cbind(Menarche, Total-Menarche) ~ Age, …
Marcin
  • 7,834
  • 8
  • 52
  • 99