rStats.js v1.3.0
    Preparing search index...

    Function glm

    • Fit a generalized linear model by iteratively reweighted least squares. Equivalent to R's glm(y ~ x, family = ...). Or y ~ x - 1 without intercept; the predictors are given as a matrix instead of a formula. Rows with a missing value (NaN) in x, y, the weights or the offset are dropped. Every family and link of R's stats is available; R's warnings are returned in warnings. See glmSummary, glmResiduals, glmPredict, glmConfint and glmAnova for the methods.

      Parameters

      • x: Sample | MatrixInput

        Predictors: a matrix (array of rows, one column per predictor; rows of length 0 for a model with the intercept only) or a vector (one predictor).

      • y: Sample | MatrixInput

        Response: a vector, or for the binomial families rows of (successes, failures).

      • options: GlmOptions = {}

      Returns GlmResult

      const fit = glm([1, 2, 3, 4, 5, 6], [0, 0, 1, 0, 1, 1], { family: "binomial" });
      fit.coefficients; // [-4.2491, 1.214]
      glmSummary(fit).pValue; // [0.20976, 0.18341]