% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit_glm.R
\name{fastglmPure}
\alias{fastglmPure}
\title{Fast generalized linear model fitting}
\usage{
fastglmPure(
  x,
  y,
  family = gaussian(),
  weights = rep(1, NROW(y)),
  offset = rep(0, NROW(y)),
  start = NULL,
  etastart = NULL,
  mustart = NULL,
  method = 0L,
  tol = 1e-07,
  maxit = 100L,
  firth = FALSE
)
}
\arguments{
\item{x}{input model matrix. Must be a matrix object}

\item{y}{numeric response vector of length nobs.}

\item{family}{a description of the error distribution and link function to be used in the model.
For \code{fastglmPure} this can only be the result of a call to a family function.
(See \code{\link[stats]{family}} for details of family functions.)}

\item{weights}{an optional vector of 'prior weights' to be used in the fitting process. Should be a numeric vector.}

\item{offset}{this can be used to specify an a priori known component to be included in the linear predictor during fitting. 
This should be a numeric vector of length equal to the number of cases}

\item{start}{starting values for the parameters in the linear predictor.}

\item{etastart}{starting values for the linear predictor.}

\item{mustart}{values for the vector of means.}

\item{method}{an integer scalar with value 0 for the column-pivoted QR decomposition, 1 for the unpivoted QR decomposition,
2 for the LLT Cholesky, 3 for the LDLT Cholesky, 4 for the full pivoted QR decomposition, 5 for the Bidiagonal Divide and 
Conquer SVD}

\item{tol}{threshold tolerance for convergence. Should be a positive real number}

\item{maxit}{maximum number of IRLS iterations. Should be an integer}

\item{firth}{logical; if `TRUE` apply Firth's (1993) bias-reducing penalty
to the score function. Currently supported only for
`family = binomial(link = "logit")` on dense `x`. The penalty modifies
the working response by `h_i (0.5 - mu_i) / (mu_i (1 - mu_i))` where
`h_i` is the leverage; convergence is checked on the sup-norm of the
coefficient update. See `logistf::logistf()` for the canonical
reference implementation.}
}
\value{
A list with the elements
\item{coefficients}{a vector of coefficients}
\item{se}{a vector of the standard errors of the coefficient estimates}
\item{rank}{a scalar denoting the computed rank of the model matrix}
\item{df.residual}{a scalar denoting the degrees of freedom in the model}
\item{residuals}{the vector of residuals}
\item{s}{a numeric scalar - the root mean square for residuals}
\item{fitted.values}{the vector of fitted values}
}
\description{
Fast generalized linear model fitting
}
\examples{

set.seed(1)
x <- matrix(rnorm(1000 * 25), ncol = 25)
eta <- 0.1 + 0.25 * x[,1] - 0.25 * x[,3] + 0.75 * x[,5] -0.35 * x[,6] #0.25 * x[,1] - 0.25 * x[,3]
y <- 1 * (eta > rnorm(1000))

yp <- rpois(1000, eta ^ 2)
yg <- rgamma(1000, exp(eta) * 1.75, 1.75)

# binomial
system.time(gl1 <- glm.fit(x, y, family = binomial()))

system.time(gf1 <- fastglmPure(x, y, family = binomial(), tol = 1e-8))

system.time(gf2 <- fastglmPure(x, y, family = binomial(), method = 1, tol = 1e-8))

system.time(gf3 <- fastglmPure(x, y, family = binomial(), method = 2, tol = 1e-8))

system.time(gf4 <- fastglmPure(x, y, family = binomial(), method = 3, tol = 1e-8))

max(abs(coef(gl1) - gf1$coef))
max(abs(coef(gl1) - gf2$coef))
max(abs(coef(gl1) - gf3$coef))
max(abs(coef(gl1) - gf4$coef))

# poisson
system.time(gl1 <- glm.fit(x, yp, family = poisson(link = "log")))

system.time(gf1 <- fastglmPure(x, yp, family = poisson(link = "log"), tol = 1e-8))

system.time(gf2 <- fastglmPure(x, yp, family = poisson(link = "log"), method = 1, tol = 1e-8))

system.time(gf3 <- fastglmPure(x, yp, family = poisson(link = "log"), method = 2, tol = 1e-8))

system.time(gf4 <- fastglmPure(x, yp, family = poisson(link = "log"), method = 3, tol = 1e-8))

max(abs(coef(gl1) - gf1$coef))
max(abs(coef(gl1) - gf2$coef))
max(abs(coef(gl1) - gf3$coef))
max(abs(coef(gl1) - gf4$coef))

# gamma
system.time(gl1 <- glm.fit(x, yg, family = Gamma(link = "log")))

system.time(gf1 <- fastglmPure(x, yg, family = Gamma(link = "log"), tol = 1e-8))

system.time(gf2 <- fastglmPure(x, yg, family = Gamma(link = "log"), method = 1, tol = 1e-8))

system.time(gf3 <- fastglmPure(x, yg, family = Gamma(link = "log"), method = 2, tol = 1e-8))

system.time(gf4 <- fastglmPure(x, yg, family = Gamma(link = "log"), method = 3, tol = 1e-8))

max(abs(coef(gl1) - gf1$coef))
max(abs(coef(gl1) - gf2$coef))
max(abs(coef(gl1) - gf3$coef))
max(abs(coef(gl1) - gf4$coef))

}
\seealso{
[fastglm_fit()]
}
