Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 888839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:28:03+00:00 2026-05-15T13:28:03+00:00

I have been reading the code used by R to fit a generalized linear

  • 0

I have been reading the code used by R to fit a generalized linear model (GLM), since the source-code of R is freely available. The algorithm used is called iteratively reweighted least squares (IRLS), which is a fairly documented algorithm. For each iteration, there is a call to a Fortran function to solve the weighted least squares problem.

From the end-user’s viewpoint, for a logistic regression for instance, a call in R looks just like this:

y <- rbinom(100, 1, 0.5)
x <- rnorm(100)
glm(y~x, family=binomial)$coefficients

And if you do not want to use a intercept, either of these calls is okay:

glm(y~x-1, family=binomial)$coefficients
glm(y~x+0, family=binomial)$coefficients

However, I cannot manage to understand how the formula, i.e. y~x or y~x-1, is making sense in the code and being understood as for whether to use an intercept or not. I was looking for a part of the code where a column of ones would be bound to x, but it seems there is none.

As far as I have read, the boolean intercept which appears in the function called glm.fit is not the same as the intercept which I am referring to. And it is the same for the offset.

The documentation about glm and glm.fit is here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:28:04+00:00Added an answer on May 15, 2026 at 1:28 pm

    You are probably looking in the wrong place. Usually, model.matrix() is called first in the fitting functions:

    > D <- data.frame(x1=1:4, x2=4:1)
    > model.matrix(~ x1 + x2, D)
      (Intercept) x1 x2
    1           1  1  4
    2           1  2  3
    3           1  3  2
    4           1  4  1
    attr(,"assign")
    [1] 0 1 2
    > model.matrix(~ x1 + x2 -1 , D)
      x1 x2
    1  1  4
    2  2  3
    3  3  2
    4  4  1
    attr(,"assign")
    [1] 1 2
    > 
    

    and it is the output of model.matrix() which is passed down to Fortran. That is the case for lm() and other model fitters.

    For glm(), it is different and only model.frame() is called which does not add an intercept column. Why that is so has to do with the difference between generalized linear models and standard linear models and beyond the scope of this posting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.