Power calculations Uniform(0,$\theta$) I am working on this problem and got about halfway through it, before getting stuck. Could anyone take a look at it?
Here's my problem...

$x_1,...,x_4$ are distributed $U(0,\theta), \theta>0$
We want to test $H_0: \theta = 1$ vs $H_1:\theta \neq 1$ with the rejection region $R=[X \in R^{+4}:X_{4:4}<1/2$ or $X_{4:4} > 1]$
evaluate the level $\alpha$ and the power function

I figured out the level.
$$\alpha = P_{\theta=1}(X_{4:4}>1)+P_{\theta=1}(X_{4:4}<1/2)=0 + \int_0^{1/2}nx^{n-1}dx=1/{2^n} $$
but am having trouble calculating power as it is a two-sided test.
First, I tried to calculate the power for all theta, then subtract when theta = 1
$$power = \int_0^{\infty}\int_1^{\infty}nx^{n-1}dxd\theta - \int_1^\infty nx^{n-1} $$ but that did not work. Could anyone offer an idea as for how to proceed?

Edit: someone said I didn't need the double integral, so I set $\theta=\theta$ and added two integrals.
$$(n/\theta^n)\int_1^{\theta}x^{n-1}=1-1/\theta^n$$
$$(n/\theta^n)\int_0^{1/2}x^{n-1}=1/(2\theta)^n$$
then setting n = 4
$$1-1/\theta^4+1/16\theta^4 =1-(15/16)(1/\theta^4)$$
Is this correct?
 A: Since this is self-study, I will show a derivation for the related case of a one-sided test.
So let $X_1,\ldots,X_n$ be a random sample from a Uniform distribution on $[0,\theta]$, $U[0,\theta]$. Consider testing $H_0:\theta\leq\theta_0$ vs. $H_1:\theta>\theta_0$.
A level-$\alpha$ test of $H_0$ rejects if the maximum $X_{(n)}$ exceeds $\theta_0(1-\alpha)^{1/n}$. The density of the maximum is given by
\begin{eqnarray*}
 f_{X_{(n)}}(x)&=&n\left(\int_{0}^x\frac{1}{\theta}dy\right)^{n-1}\frac{1}{\theta}\\
        &=&\frac{n}{\theta^n}x^{n-1}
\end{eqnarray*}
when $x\in[0,\theta]$ and zero else.
If the null is true, $\theta=\theta_0$ (strictly speaking you need to evaluate a sup here, but intuitively it is clear that the probability that the maximum exceeds some $c$ is largest for $\theta_0$ among all $\theta\leqslant\theta_0$). Hence, the probability that the maximum exceeds some $c$ so that the test is level-$\alpha$ is
\begin{eqnarray*}
 P(X_{(n)}>c|H_0)&=&P(\text{Reject $H_0$}|H_0)\\
              &=&\int_{c}^{\theta_0}\frac{n}{\theta_0^n}y^{n-1}dy\\
              &=&\frac{y^n}{\theta_0^n}|_{c}^{\theta_0}\\
              &=&1-\frac{c^n}{\theta_0^n}=\alpha
 \end{eqnarray*}
Hence, reject if the maximum $X_{(n)}$ exceeds $\theta_0(1-\alpha)^{1/n}$.
The power function $\gamma(\theta):=P(X_{(n)}\in \text{rejection region})$ of the test is given by
\begin{eqnarray*}
\gamma(\theta)&=&1-P(\text{Not reject $H_0$})\\
&=&1-\int_0^{\theta_0(1-\alpha)^{1/n}\wedge \theta}\frac{n}{\theta^n}y^{n-1}dy\\
&=&1-\frac{y^n}{\theta^n}|_0^{\theta_0(1-\alpha)^{1/n}\wedge \theta}\\
&=&1-\frac{\theta_0^n(1-\alpha)\wedge \theta^n}{\theta^n},
\end{eqnarray*}
where the minimum operator $\wedge$ accounts for the support $[0,\theta]$ of distribution of the maximum - there zero probability that $X_{(n)}$ exceeds $\theta$.
Graphical illustration:

Code:
theta <- seq(0.5, 0.8, 0.001)
theta_0 <- 0.6
n <- 10
alpha <- 0.05

power <- 1-pmin(theta^n,theta_0^n*(1-alpha))/theta^n

plot(theta, power, type="l", lwd=2, col="darkgreen")
abline(h=alpha, lty=2)
abline(v=theta_0, lty=2)
abline(v=theta[which.max(pmin(theta^n,theta_0^n*(1-alpha)))], lty=2)

A: Sometimes it helps to re-order your work.  Since $\alpha$ is fully determined by the power function, let's focus on getting the latter first.  Your test depends entirely on the maximum oberved value $\tilde{X}_n \equiv X_{(n,n)}$, which has a well-known distribution (see this information on order statistics).  To facilitate our analysis, suppose we denote the cumulative distribution function for this quantity by $G_\theta$.  Since we have the support $0 < \tilde{X}_n \leqslant \theta$, the power function can be written as:
$$\begin{align}
\pi(\theta) 
&\equiv \mathbb{P}(\text{Reject } H_0 | \theta) \\[6pt]
&= \mathbb{P}(\tilde{X}_n < \tfrac{1}{2} | \theta) + \mathbb{P}(\tilde{X}_n > 1 | \theta) \\[6pt]
&= \begin{cases}
1 & & & \text{for } 0 < \theta < \tfrac{1}{2}, \\[6pt]
\mathbb{P}(\tilde{X}_n < \tfrac{1}{2} | \theta) & & & \text{for } \tfrac{1}{2} \leqslant \theta \leqslant 1, \\[6pt]
\mathbb{P}(\tilde{X}_n < \tfrac{1}{2} | \theta) + \mathbb{P}(\tilde{X}_n > 1 | \theta) & & & \text{for } \theta > 1, \\[6pt]
\end{cases} \\[12pt]
&= \begin{cases}
1 & & & \text{for } 0 < \theta < \tfrac{1}{2}, \\[12pt]
G_\theta(\tfrac{1}{2}) & & & \text{for } \tfrac{1}{2} \leqslant \theta \leqslant 1, \\[12pt]
G_\theta(\tfrac{1}{2}) + (1-G_\theta(1)) & & & \text{for } \theta > 1. \\[12pt]
\end{cases} \\[6pt]
\end{align}$$
The size of the test then follows as:
$$\alpha = \pi(1) = G_1(\tfrac{1}{2}).$$
Now, if you can figure out the distribution of the maximum observed value, you should be able to obtain the cumulative distribution function $G_\theta$ for this quantity and then get the form of the power function.  This will then give you the size of the test.
As you can see from the above working, when deriving the properties of a classical hypothesis test with known rejection rule, it is usually best to start by deriving the full power function.  This is an important function and it gives a lot of information.  Once you have this, may other aspects of the test (e.g., its size and asymptotic properties) follow trivially.
