get_weights: Get the values from model weights

View source: R/get_weights.R

get_weightsR Documentation

Get the values from model weights

Description

Returns weighting variable of a model.

Usage

get_weights(x, ...)

## Default S3 method:
get_weights(x, remove_na = FALSE, null_as_ones = FALSE, na_rm = remove_na, ...)

Arguments

x

A fitted model.

...

Currently not used.

remove_na

Logical, if TRUE, removes possible missing values.

null_as_ones

Logical, if TRUE, will return a vector of 1 if no weights were specified in the model (as if the weights were all set to 1).

na_rm

Deprecated, use remove_na instead.

Value

The weighting variable, or NULL if no weights were specified. If the weighting variable should also be returned (instead of NULL) when all weights are set to 1 (i.e. no weighting), set null_as_ones = TRUE.

Examples

data(mtcars)
set.seed(123)
mtcars$weight <- rnorm(nrow(mtcars), 1, .3)

# LMs
m <- lm(mpg ~ wt + cyl + vs, data = mtcars, weights = weight)
get_weights(m)

get_weights(lm(mpg ~ wt, data = mtcars), null_as_ones = TRUE)

# GLMs
m <- glm(vs ~ disp + mpg, data = mtcars, weights = weight, family = quasibinomial)
get_weights(m)
m <- glm(cbind(cyl, gear) ~ mpg, data = mtcars, weights = weight, family = binomial)
get_weights(m)

easystats/insight documentation built on Oct. 2, 2024, 8:19 a.m.