p_glm: p-value from (generalized) linear regression model...

View source: R/p_glm.R

p_glmR Documentation

p-value from (generalized) linear regression model simulations with fixed predictors

Description

p-values associated with (generalized) linear regression model. Requires a prespecified design matrix (X).

Usage

p_glm(
  formula,
  X,
  betas,
  test,
  sigma = NULL,
  family = gaussian(),
  gen_fun = gen_glm,
  ...
)

gen_glm(formula, X, betas, sigma = NULL, family = gaussian(), ...)

Arguments

formula

formula passed to either lm or glm

X

a data.frame containing the covariates

betas

vector of slope coefficients that match the model.matrix version of X

test

character vector specifying the test to pass to lht. Can also be a list of character vectors to evaluate multiple tests

sigma

residual standard deviation for linear model. Only used when family = 'gaussian'

family

family of distributions to use (see family)

gen_fun

function used to generate the required discrete data. Object returned must be a data.frame. Default uses gen_glm. User defined version of this function must include the argument ...

...

additional arguments to be passed to gen_fun. Not used unless a customized gen_fun is defined

Value

a single p-value

Author(s)

Phil Chalmers rphilip.chalmers@gmail.com

See Also

p_lm.R2

Examples


X <- data.frame(G = factor(rep(c('control', 'treatment'), each=50)),
                C = sample(50:100, 100, replace=TRUE))
head(X)

# ANCOVA setup
p_glm(y ~ G + C, test="Gtreatment = 0",
  X=X, betas=c(10, .3, 1), sigma=1)

# ANCOVA setup with logistic regression
p_glm(y ~ G + C, test="Gtreatment = 0",
  X=X, betas=c(-2, .5, .01), family=binomial())

# ANCOVA setup with poisson regression
p_glm(y ~ G + C, test="Gtreatment = 0",
  X=X, betas=c(-2, .5, .01), family=poisson())



Spower documentation built on April 4, 2025, 5:11 a.m.