Solution (source code)

= Solution

Let $D_k=\sum_{j:g_j=k}v_j$ be the observed event count and $T_k=\sum_{j:g_j=k}x_j$ the total <person-time> in group $k$. Both groups are present; suppose each has $T_k>0$. The grouped <log-likelihood> is
$$
\ell(\beta^{(0)},\beta^{(1)})=\sum_{k=0}^1\{D_k\log\beta^{(k)}-T_k\beta^{(k)}\}+\text{constant}.
$$
When $D_k>0$, its derivative is $D_k/\beta^{(k)}-T_k$ and its second derivative is $-D_k/(\beta^{(k)})^2<0$. Therefore the <maximum-likelihood estimates> are
$$
\boxed{\widehat\beta^{(k)}=D_k/T_k,\qquad k=0,1.}
$$
Both events and censored observations contribute to $T_k$. If $D_k=0$, the likelihood decreases with the positive rate: its supremum is at the boundary $\beta^{(k)}\downarrow0$, rather than at a finite strictly positive estimate. Writing $D_k/T_k=0$ then describes the closure estimate.

Under the <null hypothesis> of a common rate, the same maximization gives
$$
\boxed{\widetilde\beta=\frac{D_0+D_1}{T_0+T_1}.}
$$
Let $D=D_0+D_1$ and $T=T_0+T_1$. The maximized linear terms cancel, since $T_k\widehat\beta^{(k)}=D_k$ and $T\widetilde\beta=D$. Thus the <likelihood-ratio test> uses
$$
\boxed{W=-2\log\Lambda
=2\left[\sum_{k=0}^1D_k\log\frac{D_k}{T_k}-D\log\frac DT\right]
=2\sum_{k=0}^1D_k\log\frac{D_kT}{DT_k}.}
$$
Interpret a zero-event summand by continuity as zero. If $D=0$, both likelihood suprema are equal and $W=0$: no rate comparison is informed by observed events.

Under positive common hazard, <independent censoring> and the usual increasing-information conditions in both groups, <Wilks theorem> gives $W\Rightarrow\chi_1^2$, because the unrestricted model has two rate parameters and the null has one. Reject for large $W$; at 5%, the usual cutoff is approximately $3.84$. The chi-squared calibration is asymptotic and can be poor with sparse event counts or boundary estimates.