inst/doc/linear-model.R

## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
x <- cbind(1, mtcars$wt)
y <- mtcars$mpg

head(x)

head(y)

dim(x)

length(y)

## -----------------------------------------------------------------------------
x <- model.matrix(mpg ~ wt, data = mtcars)
y <- model.response(model.frame(mpg ~ wt, data = mtcars))

## -----------------------------------------------------------------------------
solve(t(x) %*% x) %*% t(x) %*% y

## -----------------------------------------------------------------------------
lm(mpg ~ wt, data = mtcars)$coefficients

## -----------------------------------------------------------------------------
x <- model.matrix(mpg ~ wt, data = mtcars)
y <- log(mtcars$mpg)

## ----warning=FALSE------------------------------------------------------------
glm(mpg ~ wt, data = mtcars, family = poisson(link = "log"))$coefficients

Try the cpp11armadillo package in your browser

Any scripts or data that you put into this service are public.

cpp11armadillo documentation built on June 8, 2025, 9:40 p.m.