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

Meaning of "trait" in MCMCglmm

Like in this post I'm struggling with the notation of MCMCglmm, especially what is meant by trait. My code ist the following library("MCMCglmm") set.seed(123) y <- sample(letters[1:3], size = 100, replace = TRUE) x <- rnorm(100) id <- rep(1:10,…
Qaswed
  • 3,649
  • 7
  • 27
  • 47
4
votes
1 answer

Calculating logLik by hand from a logistic regression

I ran a mixed model logistic regression adjusting my model with genetic relationship matrix using an R package known as GMMAT (function: glmmkin()). My output from the model includes (taken from the user manual): theta: the dispersion parameter…
mkv8
  • 43
  • 3
4
votes
1 answer

How to predict from ns spline parameters without model object

I have the coefficients from a glm fitted in R, and I want to predict expected values for a new set of data. If I had the model object this would be simple, using predict(). However, I am now offsite and for data confidentiality reasons I no longer…
SDH
  • 43
  • 4
4
votes
1 answer

glmer VS JAGS: different results in intercept-only hierarchical model

JAGS I have an intercept-only logistic model in JAGS, defined as follows: model{ for(i in 1:Ny){ y[i] ~ dbern(mu[s[i]]) } for(j in 1:Ns){ mu[j] <- ilogit(b0[j]) b0[j] ~ dnorm(0, sigma) } sigma ~ dunif(0, 100) } When I plot the…
Guilherme D. Garcia
  • 179
  • 1
  • 3
  • 11
4
votes
1 answer

logLik.lm(): Why does R use (p + 1) instead of p for degree of freedom?

I am trying to understand the results from AIC/BIC in R. For some reason R adds 1 to the number of parameters to be estimated. Hence R uses a different formula than 2 * p - 2 * logLik (in Gaussian case logLik is residual sum of squares). In fact it…
Vincent
  • 1,361
  • 2
  • 20
  • 33
4
votes
3 answers

Remove intercept from GLM with multiple factor predictors

I am running a binomial logistic regression with a logit link function in R. My response is factorial [0/1] and I have two multilevel factorial predictors - let's call them a and b where a has 4 factor levels (a1,a2,a3,a4) and b has 9 factor…
MiMi
  • 548
  • 1
  • 5
  • 8
4
votes
1 answer

Logistic regression returns error but runs okay on reduced dataset

I would appreciate your input on this a lot! I am working on a logistic regression, but it is not working for some reason: mod1<-glm(survive~reLDM2+yr+yr2+reLDM2:yr +reLDM2:yr2+NestAge0, family=binomial(link=logexp(NSSH1$exposure)), …
MSS
  • 345
  • 4
  • 12
4
votes
5 answers

How to get a data.frame with cases from a contingency table in r?

I would like to reproduce some calculations from a book (logit regression). The book gives a contingency table and the results. Here is the Table: . example <- matrix(c(21,22,6,51), nrow = 2, byrow = TRUE) #Labels: …
Martin
  • 307
  • 3
  • 10
4
votes
0 answers

Variable order in interaction terms

I'm trying to fit a number of linear models as shown below. It is important that all interaction terms are sorted lexicographically. Note that the second model is missing the main effect for x. x = rnorm(100) y = rnorm(100) z = x + y +…
rimorob
  • 624
  • 1
  • 5
  • 16
4
votes
1 answer

R caret: Tuning GLM boost prune parameter

I'm trying to tune the parameters for a GLM boost model. According to the Caret package documentation concerning this model there is 2 parameters that can be adjusted, mstop and prune. library(caret) library(mlbench) data(Sonar) …
Mesmer
  • 319
  • 1
  • 4
  • 17
4
votes
1 answer

Binomial GLM in Julia - how to specify hits and misses

In Julia, I'd like to calculate a GLM with family Binomial() and LogitLink(). My data are three linear arays: xvalues, number of hits, and number of misses. I would like to explain the binomially distributed hits and misses by their positions on the…
Hannes Becher
  • 149
  • 1
  • 6
4
votes
1 answer

R: function to apply Anova over different subsets of one's dataset and collect output

A common task is to have to carry out a certain statistical analysis (like an anova, glm or mixed model) on different subsets of a dataset and combine the output tables with summary coefficients and p values in a single dataframe. I am looking…
user2999576
  • 41
  • 1
  • 6
4
votes
1 answer

how to use glmnet without regularization

I have read that glmnet can be used without regularization, i.e. it can be used as a regular glm. I am writing a thesis and trying to avoid using to many different packages, so it would be convenient to use glmnet to do a regular glm logistic…
Camilla
  • 113
  • 2
  • 12
4
votes
2 answers

How do you perform a goodness of link test for a generalized linear model in R?

I'm working on fitting a generalized linear model in R (using glm()) for some data that has two predictors in full factorial. I'm confident that the gamma family is the right error distribution to use but not sure about which link function to use…
DirtStats
  • 559
  • 9
  • 29
4
votes
0 answers

Is there a step function or method for cv.glmnet?

One can perform glm model fit with logistic link function for response from binomial family and then can apply step function to extract the best subset of explanatory features in terms of information criterion such as AIC or BIC. Have anyone…
Marcin
  • 7,834
  • 8
  • 52
  • 99