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

Fit and compare multiple sigmoid curves in R

I would like to fit multiple curves at once, and compare them statistically, in terms of their 3 estimated parameters – asymptote, slope and x0. Here is an idealized image of the data to be modeled: Most searchable pages turn up methods to fit a…
Matt74
  • 729
  • 4
  • 8
6
votes
1 answer

Compute cross-validation for GLMs with negative binomial response

I am interested in using cross validation (leave-one-out or K-folds) to test several different negative binomial GLMs that I have created. I am using the glm.nb() function from MASS to run negative binomial regression. My question is whether I can…
Kodiakflds
  • 603
  • 1
  • 4
  • 15
6
votes
1 answer

glmer from R package lme4 asking to scale variables even though variables already scaled

I have a dataset with 27 variables and ~30,000 observations. The first 17 variables are continuous and the remainder are binary. When running glmer with the model specified as all the fixed effects + random effect intercept based on a subject ID, I…
notaclue1980
  • 61
  • 1
  • 2
6
votes
2 answers

Saving a single object within a function in R: RData file size is very large

I am trying to save trimmed-down GLM objects in R (i.e. with all the "non-essential" characteristics set to NULL e.g. residuals, prior.weights, qr$qr). As an example, looking at the smallest object that I need to do this…
6
votes
1 answer

R: could not find function "function (object, ...) \nobject" in glm() and bestglm()

I was running a bestglm analysis from the package bestglm: res.bestglm <- bestglm(Xy = offermodel, family = binomial, IC = "BIC", method = "exhaustive") summary(res.bestglm$BestModel) Morgan-Tatar search since…
Hack-R
  • 22,422
  • 14
  • 75
  • 131
6
votes
1 answer

Binomial GLM using caret train

I would like to fit a Binomial GLM on a certain dataset. Using glm(...,family=binomial) everything works fine however I would like to do it with the caret train() function. Unfortunately I get an unexpected error which I cannot get rid…
Dean
  • 73
  • 1
  • 4
6
votes
2 answers

R - using glm inside a data.table

I'm trying to do some glm's inside a data.table to produce modelled results split by key factors. I've been doing this sucessfully for: High level glm glm(modellingDF,formula=Outcome~IntCol + DecCol,family=binomial(link=logit)) Scoped glm with…
Steph Locke
  • 5,951
  • 4
  • 39
  • 77
6
votes
1 answer

Missing object error when using step() within a user-defined function

5 days and still no answer As can be seen by Simon's comment, this is a reproducible and very strange issue. It seems that the issue only arises when a stepwise regression with very high predictive power is wrapped in a function. I have been…
zap2008
  • 684
  • 1
  • 9
  • 24
6
votes
1 answer

How obtain the true residual deviance and degrees of freedom in R of a glm model when a set of parameters gets pasted() as a vector

I'm writing a script (in python, with the R parts in pypeR) such that I need to use a function in R that compares two models with an F-ratio test. The models are like this: Model 1: Response ~ Predictor A + Predictor B + Predictor C.... + Predictor…
Atticus29
  • 4,190
  • 18
  • 47
  • 84
6
votes
1 answer

glm and relative risk -replicate Stata code in R

Could anyone help me replicate these relative risk calculations (and its confidence interval) in R? A similar procedure used in Stata is described here. Could anyone show me how to do this in R (my data has clusters and strata but I've taken a…
Marco M
  • 623
  • 1
  • 8
  • 15
6
votes
1 answer

Interpreting coefficient names in glmnet in R

I am using glmnet to predict probabilities based on a set of 5 features using the following code. I need the actual formula because I need to use it in a different (non R) program. deg = 3 glmnet.fit <-…
dougp
  • 61
  • 1
  • 3
5
votes
3 answers

Plot the Profile Deviance for a GLM fit in R

I would like to be able to plot the profile deviance for a parameter estimate fitted using the function glm() in R. The profile Deviance is the deviance function for different values of the parameter estimate in question, after estimating all other…
MatW
  • 305
  • 3
  • 7
5
votes
2 answers

Exporting multiple glm plots as PNGs?

SO, I'm trying to export plots of my linear model. When I do it as a PDF, the PDF has four pages and four different charts. When I export as a PNG, I only get the first chart. How do I export so that I get all four graphs as separate PNG…
user1017124
  • 123
  • 1
  • 6
5
votes
1 answer

Linear Regression in R with variable number of explanatory variables

Possible Duplicate: Specifying formula in R with glm without explicit declaration of each covariate how to succinctly write a formula with many variables from a data frame? I have a vector of Y values and a matrix of X values that I want to…
Michael
  • 7,087
  • 21
  • 52
  • 81
5
votes
1 answer

Error when using random effect with h2o.glm in R

I would like to use h2o in R for glm regression but with random effects (HGLM, seems possible from this page ). I do not manage to make it work yet, and get errors I do not understand. Is here my working example: I define a dataset with Simpson…
denis
  • 5,580
  • 1
  • 13
  • 40