Search code examples
r

Question about glm family in R


When using glm() in R, is family = "binomial" the same as family = binomial? Are they interchangeable and producing the same results? I am looking at a binary classification problem.


Solution

  • The two commands glm(..., family="binomial") (1) and glm(... , family=binomial) (2) are the same (they will always give the same results).

    You can see this from the R code of glm on lines 7-8:

      7:  if (is.character(family)) 
      8:    family <- get(family, mode = "function", envir = parent.frame())
      9:  if (is.function(family)) 
      10:   family <- family()
    

    Version (1) specifies the family as a character string, which gets converted to a function using get(). This is now in the same form as version (2).

    is.function(binomial)
    [1] TRUE
    
    is.function(get("binomial", mode = "function", envir = parent.frame()))
    [1] TRUE