How is SPSS calculating 'observed power'? I see quite a few discussions on here about the validity of calculating observed power. I can see that the general consensus is that it isn't very useful, but that isn't my question. 
How is SPSS calculating observed power? If I wanted to replicate this in R or python using my own code, how would I get the same value as SPSS?
Does anyone know or can point me to some documentation?
 A: Short Answer
There is a formula which predicts the distribution of your test statistic given specifics of your experiment (e.g. sample size) and a given effect (e.g. difference in means). SPSS estimates the effect using your data, and then plugs-in this information into the formula to get the distribution of your test-statistic. 
The power is then the estimated probability that your test statistic falls within the rejection region (e.g. exceeds a criterion value), where the probability is calculated using the estimated distribution. 
Long Answer
The Power of a statistical test is the probability of rejecting the null hypothesis, given that the null hypothesis is false (alternate hypothesis is true). Informally, it is the probability of detecting a statistical effect assuming that the effect exists. 
How Power might be calculated depends on the hypothesis test in question. Most likely, if you are using SPSS, you are talking about an ANOVA procedure (ANOVA,MANOVA,ANCOVA,etc.). I'll take as an example the overall F-test in a regular ANOVA, with balanced treatments, but the principles apply generally.  
In ANOVA, the overall F-test test is, written in terms of the effects model, (writing the treatment means as $ \mu_{i} = \mu + \beta_{i}$),
$$
H_{0}: \beta_{1} = \beta_{2} = \ ... \  =\beta_{g} = 0 
$$
The alternative hypothesis is that at least two of the treatment means differ. 
To test $H_{0}$, the test statistic is:
$$
F = \frac{MS_{trts}}{MS_{Error}} 
$$ 
which under the null hypothesis follows an $F_{g-1,N-g}$ distribution, where N is the total sample size. Thus we compare the observed F-statistic to the $1-\alpha$ quantile of an $F_{g-1,N-g}$ distribution (call $F^{*}$) to determine whether to reject the null hypothesis. Put another way,
$$
\text{if} \ \ F \geq F^{*} \Longrightarrow \ \text{Reject} \ H_{0}
$$
$$
\text{if} \ \ F < F^{*} \Longrightarrow \ \text{Retain} \ H_{0}
$$
Under the alternate hypothesis, the F-statistic no longer follows an $F_{g-1,N-g}$ distribution, but instead follows a noncentral F-distribution $F_{g-1,N-g,\gamma}$, where $\gamma$ is the noncentrality parameter
$$
\gamma = \frac{n \sum_{i=1}^{n} \beta_{i}^{2}}{\sigma^{2}}
$$
where $n$ is the number of observations in each treatment group, and $\sigma^{2}$ is the variance of the errors. 
Suppose one knew all of the information needed to calculate the distribution of the test statistic F using the above formulas (specifics of experiment, and effect sizes). The power could then be calculated:
$$
\text{Power} \ = \ P(F \geq F^{*})
$$
Now onto observed power (you have read up, so you should know generally about its definition and possible interpretations). 
It will generally be known before an experiment or data collection process is conducted what the sample size, number of treatments, and alpha level will be. However, it will not generally be known what the variance of the error terms or the effects $\beta_{i}$ will be. 
But if data is collected, it is possible to estimate the variance of the error terms and the $\beta_{i}$ directly from your data. In that case, one can plug-in these values directly into the above formula for the non-central F-distribution to estimate the distribution that your F-statistic follows. Once can then compare this noncentral F-distribution to your critical value in order to get the "observed power." So in order,


*

*Plug in values of $N$, $g$, as well as estimated values $\hat{\sigma}^{2}$, $\hat{\beta}_{i}$ in formula to get estimated distribution of $F$. 

*Calculate critical value $F^{*}$ using 1 - $\alpha$ quantile of $F_{g-1,N-g}$. 

*Observed power is probability that $F$ exceeds $F^{*}$. 


Again, while the formulas and rejection region will differ based on your statistical test, the idea of how to calculate observed power are universal. 
