Post-hoc power analysis on logistic regression with varying sample size in R I have observations collected over a time period of 12 months. For each month, I recorded the total number of observations (n_per_month), the number of "success" events (n_success) and then computed the success rate as  n_success/n_per_month (success_rate). Here it is an example of the data:
data_df = data.frame(month = 5:11, 
     n_per_month = c(17, 21, 15, 8, 14, 14, 1), 
     n_success = c(13, 13, 6, 6, 10, 14, 1), 
     success_rate = c(0.7647059, 0.6190476, 0.4, 0.75, 0.7142857, 
                      1, 1))

Then I fitted a logistic regression using glm R function:
model_obs <- glm(success_rate ~ month, data = data_df, 
                 family = binomial(), weights=n_per_month)

And add the corresponding fitted values in the original dataframe:
data_df$fitted = as.numeric(predict.glm(model_obs, 
         type = "response"))

Following a past posted question: Simulation of logistic regression power analysis - designed experiments, I modified that R code to perform post-hoc power analysis. That is, I wanted to know how reliable is the success rate I computed from the observed data, given the sample size of each month. For this example code, I repeat the analysis 10 times (repetitions) and record the results of the power analysis in significant matrix. In this post-hoc power analysis I assume that the rates estimated from the observed data are true.
repetitions = 10

significant = matrix(nrow=repetitions, ncol=3)

for(i in 1:repetitions){
        final_rep = NULL    
for(j in 1:nrow(data_df)){        
  resp_val = rbinom(n=data_df$n_per_month[j], size=1, 
                    prob=data_df$fitted[j])
  tmp_df = data.frame(month=rep(data_df$month[j], 
              length(resp_val)), events=resp_val)
  final_rep = rbind(final_rep, tmp_df)
  }

n_success_df = aggregate(events ~ month, data = final_rep, sum)
n_month_df = aggregate(events ~ month, data = final_rep, length)
rep_df = data.frame(month=n_success_df$month, 
           n_per_month=n_month_df$events, 
           n_success=n_success_df$events)
rep_df$success_rate = rep_df$n_success/rep_df$n_per_month

model <- glm(success_rate ~ month, data = rep_df, 
            family = binomial(), weights=n_per_month)

significant[i, 1] = (summary(model)$coefficients[2, 4]<.05)
significant[i, 2]   = sum(significant[i, 1])
modelDev           = model$null.deviance-model$deviance
significant[i, 3]   = (1-pchisq(modelDev, 1))<.05
  
rm(temp_df, count_df, rep_df, model, modelDev)
}

sum(significant[, 2]==1)/repetitions

Would you agree with this procedure?


Would you agree with this procedure?

No, unless your intent is to inform design of a future study. And in that case, you should be doing your simulation in a different way.
"Post-hoc power analysis," in the way the term is typically used, is (a) inappropriate, as @AdamO explains in another answer, and (b) not the right way to evaluate "how reliable is the success rate I computed from the observed data, given the sample size of each month."
For the reliability of probability estimates month by month, outside of the modeling, this page shows the formula for the variance of the probability estimate from binomial sampling. Associated types of confidence intervals are described here. Those would be appropriate estimates of "how reliable is the success rate" month by month in a saturated model. For your last 2 months all observations are successes. Note that with only 1 observation in the last month, there is at least a 5% chance of a success when the true value of $p$ is as small as 0.05, so the confidence interval is very wide. For 14 successes out of 14, the 95% confidence limit for $p$ could be as low as about 0.8. See this Wikipedia page.
In terms of estimating the reliability of estimates from your model,* "given the sample size of each month," simulations like those you propose (with the number of observations per month fixed at those in your data sample) might make some sense. What you would want is an estimate of the variances of the coefficient estimates among simulations, or variances of month-by-month predictions from the models. That's different from your "post-hoc power calculation," which is based solely on whether coefficients from a model of a simulated data set happened to pass the arbitrary p < 0.05 criterion.
It's OK to use these data to inform design of a future study, but that's really an a priori power analysis for that future study. If you were to do so, you probably should also include an estimate of the sources of variability of the total number of observations per month.

*A warning on your model: you are modeling as if the log-odds of success is linearly related to the numeric month. Make sure that's really what you want. I find it hard to think of a scenario where that would be realistic.
