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)
# return analysis model
p_glm(y ~ G + C, test="Gtreatment = 0",
X=X, betas=c(10, .3, 1), sigma=1, return_analysis=TRUE)
# 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())
# \donttest{
# test whether two slopes differ given different samples.
# To do this setup data as an MLR where a binary variable S
# is used to reflect the second sample, and the interaction
# effect evaluates the magnitude of the slope difference
gen_twogroup <- function(n, dbeta, sdx1, sdx2, sigma, n2_n1 = 1, ...){
X1 <- rnorm(n, sd=sdx1)
X2 <- rnorm(n*n2_n1, sd=sdx2)
X <- c(X1, X2)
N <- length(X)
S <- c(rep(0, n), rep(1, N-n))
y <- dbeta * X*S + rnorm(N, sd=sigma)
dat <- data.frame(y, X, S)
dat
}
# prospective power using test that interaction effect is equal to 0
p_glm(formula=y~X*S, test="X:S = 0",
n=100, sdx1=1, sdx2=2, dbeta=0.2,
sigma=0.5, gen_fun=gen_twogroup) |> Spower(replications=1000)
# }
Run the code above in your browser using DataLab