Learn R Programming

faux (version 1.2.1)

get_coefs: Get Coefficients from Data

Description

You need model coefficients to simulate multilevel data, and can get them from data simulated from parameters using sim_design() or rmulti().

Usage

get_coefs(data, formula = NULL, fun = stats::lm, ...)

Value

a list of the model coefficients

Arguments

data

A dataset in long format

formula

An lm formula (can be extracted from datasets created by sim_design)

fun

the model function

...

Further arguments to the model function

Examples

Run this code
# simulate some data
data <- sim_design(within = 2, between = 2, 
                   mu = c(1, 0, 1, 1), 
                   long = TRUE, empirical = TRUE)

# get coefs for the full factorial model
get_coefs(data)

# a reduced model
get_coefs(data, y ~ B1 + W1)

# specify a different model function
data$y <- norm2binom(data$y)
get_coefs(data, fun = glm, family = binomial)

Run the code above in your browser using DataLab