Skip to contents

Calculates residuals from observed outcome and predicted values (Gaussian family) or predicted probabilities (binomial family). Called by `.exp.multiple` and `.iso.multiple`.

Usage

.residuals(y, y_hat, family)

Arguments

y

response: vector of length \(n\) (see family)

y_hat

predicted values or probabilities (see family): vector of length \(n\), or matrix with \(n\) rows (samples) and \(k\) columns (methods)

family

character "gaussian" (\(y\): real numbers, \(y\_hat\): real numbers) or "binomial" (\(y\): 0s and 1s, \(y\_hat\): unit interval)

Examples

n <- 100
p <- 5
X <- matrix(stats::rnorm(n*p),nrow=n,ncol=p)
#y <- stats::rbinom(n,size=1,prob=0.5)
y <- stats::rnorm(n)
glm <- glm(y~X,family="gaussian")
res <- residuals.glm(glm)
y_hat <- predict(glm,type="response")
all.equal(res,y-y_hat)
#> [1] TRUE