0
$\begingroup$

I am a junior statistician and naïve in sample size estimations and I have to make a plot in which the power and sample size could be estimated according to different effects (OR or beta). My model will be a logistic regression mixed model, where y=Mortality (0, 1) and treatment has 4 levels (A, B, C, D) Model <- glmer(Mortality ~ Treatment + Var1 + Var2 + Var3 + (1|Subject), family = "binomial"(link = logit), data = Data)

I have seen this script that could work for a simple linear regression:

B <- function(beta, n, sd = 6) {
  sem <- sd / sqrt(n)
  1 - pnorm(1.64 - beta / sem)
}

n <- c(100,200,300,400,500,600,700,1000,2000,3000, 4000, 10000)
beta <- c(0.3,0.4, 0.5,0.6,0.7,0.8,0.9)

library(tidyverse)
outer(beta, n, B) %>%
  data.frame(row.names = beta) %>%
  setNames(n) %>%
  rownames_to_column("beta") %>%
  gather(n, power, -beta) %>%
  mutate(
    n = as.numeric(n),
    beta = factor(beta, unique(beta))) %>%
  ggplot(aes(n, power, colour = beta, group = beta)) +
  geom_line(aes(n, power, colour = beta, group = beta),size=1) + geom_point() + scale_y_continuous(labels = scales::percent, breaks =c(0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1)) + scale_x_log10(breaks=c(100,200,300,400,500,600,700,800,1000,3350,10000,35500,100000,10000)) + labs(x = "sample size (N)", y = "power (%)") + theme(panel.background = element_blank())

Plot

Any ideas?

$\endgroup$
  • 1
    $\begingroup$ Have you seen this ? $\endgroup$ – Robert Long Feb 27 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.