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
10
votes
2 answers

R glm standard error estimate differences to SAS PROC GENMOD

I am converting a SAS PROC GENMOD example into R, using glm in R. The SAS code was: proc genmod data=data0 namelen=30; model boxcoxy=boxcoxxy ~ AGEGRP4 + AGEGRP5 + AGEGRP6 + AGEGRP7 + AGEGRP8 + RACE1 + RACE3 + WEEKEND + SEQ/dist=normal; FREQ…
Michelle
  • 1,281
  • 2
  • 16
  • 31
10
votes
1 answer

GAM model error

My data frame looks like: head(bush_status) distance status count 0 endemic 844 1 exotic 8 5 native 3 10 endemic 5 15 endemic 4 20 endemic 3 The count data is non-normally distributed. I'm…
Fbj9506
  • 231
  • 3
  • 11
10
votes
1 answer

Using modelr::add_predictions for glm

I am trying to calculate the logistic regression prediction for a set of data using the tidyverse and modelr packages. Clearly I am doing something wrong in the add_predictions as I am not receiving the "response" of the logistic function as I would…
Farmer
  • 137
  • 1
  • 8
10
votes
2 answers

What do these R glm error messages mean: "Error: no valid set of coefficients has been found: please supply starting values"

Here are two related questions but they are not duplicates of mine as the first one has a solution specific to the data set and the second one involves a failure of glm when start is supplied alongside an…
Alex
  • 15,186
  • 15
  • 73
  • 127
10
votes
2 answers

update() a model inside a function with local covariate

I need to update a regression model from inside a function. Ideally, the function should work with any kind of models (lm, glm, multinom, clm). More precisely, I need to add one or several covariates that are defined inside the function. Here is an…
Matthias Studer
  • 1,722
  • 1
  • 10
  • 24
10
votes
6 answers

Deciding threshold for glm logistic regression model in R

I have some data with predictors and a binary target. Eg: df <- data.frame(a=sort(sample(1:100,30)), b= sort(sample(1:100,30)), target=c(rep(0,11),rep(1,4),rep(0,4),rep(1,11))) I trained a logistic regresion model using…
user2175594
  • 799
  • 3
  • 9
  • 17
10
votes
2 answers

modify glm function to adopt user-specified link function in R

In glm in R, the default link functions for the Gamma family are inverse,identity and log. Now for my particular question, I need to use gamma regression with response Y and a modified link function in the form of log(E(Y)-1)). Thus, I consider…
alittleboy
  • 10,616
  • 23
  • 67
  • 107
10
votes
3 answers

How to get values of Z - statistic from glm object?

How can I get values of Z - statistics as a vector from glm object? For example, I have fit <- glm(y ~ 0 + x,binomial) How can I access the column Pr(>|z|) the same way I get estimates of coefficients with fit$coef?
9
votes
2 answers

How to vectorize equations?

I'm trying to implement the Softmax regression algorithm to solve the K-classifier problem after watching Professor Andrew Ng's lectures on GLM. I thought I understood everything he was saying until it finally came to writing the code to implement…
oort
  • 1,840
  • 2
  • 20
  • 29
9
votes
1 answer

What standard errors are returned with predict.glm(..., type = "response", se.fit = TRUE)?

I am going to fit the model on the data provided in this excellent example on how to compute the 95% confidence interval for the response, after performing a logistic regression: foo <- mtcars[,c("mpg","vs")]; names(foo) <- c("x","y") mod <- glm(y ~…
Alex
  • 15,186
  • 15
  • 73
  • 127
8
votes
2 answers

Zero-Inflation NB - object 'model_count' not found

I am modeling a mediated zero-inflated negative binomial (ZINB) model. i am following the steps of O'Rourke & Vazquez (2019) --> https://www.sciencedirect.com/science/article/abs/pii/S0306460319301078 A few days ago i was running a different ZINB…
Principia
  • 125
  • 1
  • 7
8
votes
0 answers

lme4 glmer for r caret package train function

I am trying to adapt the glm method from caret::train to be used for a Generalized Linear Mixed Effects Model. I have used the following code to set-up the function: `GLMERmod <- list(type="Classification", library="lme4", loop=NULL) parameters <-…
daileyco
  • 743
  • 5
  • 13
8
votes
2 answers

MATLAB's glmfit vs fitglm

I'm trying to perform logistic regression to do classification using MATLAB. There seem to be two different methods in MATLAB's statistics toolbox to build a generalized linear model 'glmfit' and 'fitglm'. I can't figure out what the difference is…
8
votes
3 answers

Force certain parameters to have positive coefficients in lm()

I would like to know how to constrain certain parameters in lm() to have positive coefficients. There are a few packages or functions (e.g. display) that can make all coefficients, and the intercept, positive. For instance, in this example, I would…
Yu Deng
  • 1,051
  • 4
  • 18
  • 35
8
votes
1 answer

MCMCglmm multinomial model in R

I'm trying to create a model using the MCMCglmm package in R. The data are structured as follows, where dyad, focal, other are all random effects, predict1-2 are predictor variables, and response 1-5 are outcome variables that capture # of observed…
M.A.Kline
  • 1,697
  • 2
  • 19
  • 29