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?

Building on the part (a) of the Second point in @EdM's answer.
As the recently defamed RA Fisher said nearly 100 years ago to the First Indian Statistical Conference,

To consult the statistician after an experiment is finished is often merely to ask him to conduct a post mortem examination. He can perhaps say what the experiment died of.

He continues:

To utilise this kind of experience he [the statistician, who may in fact be a she or other still] must be induced to use his imagination, and to foresee in advance the difficulties and uncertainties with which, if they are not foreseen, his investigations are beset.

So the point of this is that any analysis requires forethought quantitatively. Typically, this is in the form of a "power analysis". That is, bearing no data at all upon which to base your opinion, what is the expected effect, rate of recruitment, missingness, distribution of blocking or strata variables, etc. etc. (ad infinitum or ad nauseum)... Often, the final result amounts to drawing a line in the sand and saying, "We expect the OR to be 1.5, and with 1:1 randomization, we'll have 90% power with N=XX". I have used lines such as these verbatim on protocols or grant applications.
And yet, in the preponderance of literature, there is rarely a mention of the apriori power calculation. This is disappointing for several reasons. Because of this, you often find the readership at a loss of how to interpret a non-significant result - or a significant one, although blindly many "trust" significant results and ask fewer questions of them.
In either case, I strongly argue that the statistician must revisit their assumptions upon reporting the final analysis. "We thought the death rate would be X but it was Y, we thought the distribution of age would be this but it was that," etc. etc. This is in the spirit of working in the service of science. Some assumptions are sensitive and require further analysis to make sure the result isn't spurious due to completely unforeseen phenomena, like effect modification, informative missingness, etc.
Despite all the insight above, a post-hoc power calculation does not fit into this line of inquiry. It doesn't shed any light at all on these issues because you replicate many issues in your analysis that may be flukes without identifying precisely what they were. I find reviewers or readers may ask for "post-hoc power calculations" because they are subconsciously aware of these "post mortem" issues, but they don't know how to ask meaningful questions of a statistician.
Many are the papers supporting this idea.
https://scholar.google.com/scholar?hl=en&as_sdt=0%2C48&q=do+not+perform+post-hoc+power+calculations&btnG=
