The “glm” Function in R

  • Package: Base R (no specific package required)

  • Purpose: Fits generalized linear models to data.

  • General Class: Statistical Modeling

  • Required Argument(s):

    • formula: A symbolic description of the model to be fitted. In the form response ~ terms.

    • family: A description of the error distribution and link function to be used in the model.

  • Notable Optional Arguments:

    • data: An optional data frame in which to interpret the variables.

    • weights: An optional vector of weights to be used in the fitting process.

    • subset: An optional vector specifying a subset of observations to be used in the fitting process.

    • na.action: A function that indicates what should happen when data contain missing values.

    • start: A starting point for the algorithm to optimize the parameters.

  • Example:

  • # Example data
    set.seed(123)
    x <- rnorm(100)
    y_binary <- rbinom(100, 1, plogis(2*x))

    # Fit a logistic regression model
    model <- glm(y_binary ~ x, family = binomial)

    # Display the summary of the model
    summary(model)

  • In this example, the glm function is used to fit a logistic regression model with a binary response variable y_binary and a predictor variable x. The summary of the model is then displayed, showing coefficients, standard errors, z-values, and other relevant information.

Previous
Previous

The “ks.test” Function in R

Next
Next

The “lm” Function in R