###########################################
# predictor X follows normal distribution #
###########################################
## probability specification
power.z.logistic(base.prob = 0.15, prob = 0.20,
alpha = 0.05, power = 0.80,
dist = "normal")
## odds ratio specification
power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667,
alpha = 0.05, power = 0.80,
dist = "normal")
## regression coefficient specification
power.z.logistic(beta0 = -1.734601, beta1 = 0.3483067,
alpha = 0.05, power = 0.80,
dist = "normal")
## change parameters associated with predictor X
pred.dist <- list(dist = "normal", mean = 10, sd = 2)
power.z.logistic(base.prob = 0.15, beta1 = 0.3483067,
alpha = 0.05, power = 0.80,
dist = pred.dist)
##############################################
# predictor X follows Bernoulli distribution #
# (such as treatment/control groups) #
##############################################
## odds ratio specification
power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667,
alpha = 0.05, power = 0.80,
dist = "bernoulli")
## change parameters associated with predictor X
pred.dist <- list(dist = "bernoulli", prob = 0.30)
power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667,
alpha = 0.05, power = 0.80,
dist = pred.dist)
####################################
# predictor X is an ordinal factor #
####################################
## generating an ordinal predictor
x.ord <- sample(
x = c(1, 2, 3, 4), # levels
size = 1e5, # sample size large enough to get stable estimates
prob = c(0.25, 0.25, 0.25, 0.25), # category probabilities
replace = TRUE
)
## dummy coding the ordinal predictor
x.ord <- factor(x.ord, ordered = TRUE)
contrasts(x.ord) <- contr.treatment(4, base = 4)
x.dummy <- model.matrix( ~ x.ord)[,-1]
x.data <- as.data.frame(x.dummy)
## fit linear regression to get multiple r-squared
x.fit <- lm(x.ord1 ~ x.ord2 + x.ord3, data = x.data)
## extract parameters
bern.prob <- mean(x.data$x.ord1)
r.squared.pred <- summary(x.fit)$adj.r.squared
## change parameters associated with predictor X
pred.dist <- list(dist = "bernoulli", prob = bern.prob)
power.z.logistic(base.prob = 0.15, odds.ratio = 1.416667,
alpha = 0.05, power = 0.80,
r.squared.pred = r.squared.pred,
dist = pred.dist)
Run the code above in your browser using DataLab