Pooling Two Sensors and Correlation in a Lattice Walk
Statistics & ExperimentsModel answerLast updated
Find the minimum-variance linear unbiased way to pool readings from two sensors, then compute the correlation of coordinates, and of their absolute values, for a walk on the square lattice.
Part 1: Pooling readings from two sensors
A room has a fixed but unknown true temperature $\theta$.
1a. One sensor. Sensor A gives $n$ i.i.d. readings $X_1,\dots,X_n$ with $\mathbb E[X_i]=\theta$ and $\mathrm{Var}(X_i)=\sigma_1^2$.
- Propose an estimator of $\theta$ and give its variance.
- Argue why it is a sensible, or optimal, choice.
1b. Two sensors. Sensor B gives $m$ i.i.d. readings $Y_1,\dots,Y_m$ with $\mathbb E[Y_j]=\theta$ and $\mathrm{Var}(Y_j)=\sigma_2^2$. Every $X_i$ is independent of every $Y_j$. You may assume $\sigma_1^2$ and $\sigma_2^2$ are known.
- Among all linear unbiased estimators built from all $n+m$ readings, find the one with the smallest variance.
- Give the optimal weights and the resulting variance.
- Say what you would do if the variances were unknown.
Part 2: A walk on the square lattice
A walker starts at the origin $(0,0)$. At every step it moves one unit up, down, left or right, each with probability $1/4$, independently of earlier steps. Let $(X_n, Y_n)$ be its position after $n$ steps.
2a. Compute $\mathrm{Corr}(X_n, Y_n)$.
2b. Study $\mathrm{Corr}(|X_n|, |Y_n|)$.
- Give a correct exact expression, even if it is not a neat closed form.
- Determine the sign of the correlation.
- Determine its behaviour as $n\to\infty$.
- Check your answer on small $n$.
Hints
Hint 1
For any linear estimator, write the coefficients as weights. Unbiasedness forces them to sum to 1. Then minimize the sum of weight^2 times variance under that constraint.
Hint 2
For two sensors, first reduce each sensor to its sample mean, with variances sigma1^2/n and sigma2^2/m. Then pick the mixing weight w to minimize w^2 v1 + (1-w)^2 v2.
Hint 3
For 2a, look at a single step: can the horizontal and vertical displacements both be nonzero at the same time? Then use independence of steps to add covariances.
Hint 4
For 2b, condition on H, the number of horizontal steps (Binomial(n, 1/2)). Given H, the two coordinates are independent 1D walks of lengths H and n-H. The covariance then comes only from how E|S_k| depends on k.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1: Pooling sensor readings
1a. One sensor
Use the sample mean $\hat\theta=\bar X=\frac1n\sum X_i$. It is unbiased and
$$\mathrm{Var}(\bar X)=\frac{\sigma_1^2}{n}.$$
Why it is optimal among linear estimators. Take $\hat\theta=\sum a_iX_i$.
- Unbiasedness requires $\sum a_i=1$.
- The variance is $\sigma_1^2\sum a_i^2$.
- By Cauchy–Schwarz, $1=(\sum a_i)^2\le n\sum a_i^2$, so $\sum a_i^2\ge 1/n$. Equality holds only for $a_i=1/n$.
So $\bar X$ is the best linear unbiased estimator (BLUE). Saying this explicitly shows you know why the mean is the right choice, not just that it is the default.
1b. Two sensors
Put weights $a_i$ on the $X_i$ and $b_j$ on the $Y_j$. Unbiasedness requires $\sum a_i+\sum b_j=1$. The variance is
$$\sigma_1^2\sum a_i^2+\sigma_2^2\sum b_j^2.$$
A Lagrange multiplier argument gives $a_i\propto 1/\sigma_1^2$ and $b_j\propto 1/\sigma_2^2$. Each reading gets a weight proportional to its precision (inverse variance). This is the same as combining the two sample means:
$$\hat\theta^=w^\bar X+(1-w^)\bar Y,\qquad w^=\frac{n/\sigma_1^2}{n/\sigma_1^2+m/\sigma_2^2}.$$
Quick derivation with the means. Let $v_1=\sigma_1^2/n$ and $v_2=\sigma_2^2/m$. Minimize $w^2v_1+(1-w)^2v_2$. Setting the derivative to zero gives $w v_1=(1-w)v_2$, so $w^*=v_2/(v_1+v_2)=\frac{1/v_1}{1/v_1+1/v_2}$.
The minimum variance is
$$\mathrm{Var}(\hat\theta^*)=\frac{1}{n/\sigma_1^2+m/\sigma_2^2}.$$
In words: precisions add.
Sanity checks.
- The result is never worse than the better sensor alone, $\min(v_1,v_2)$.
- If $\sigma_2\to\infty$, all weight goes to A and we recover 1a.
- If $\sigma_1=\sigma_2$, every reading gets weight $1/(n+m)$, the pooled mean.
Unknown variances. Plug in sample variances $s_1^2,s_2^2$ to get feasible weighted least squares. It is still essentially unbiased, because under normality the weights are independent of the means. Its variance is slightly larger than the oracle value, noticeably so for small $n$ or $m$.
Common mistakes.
- Weighting by sample size only.
- Weighting by $1/\sigma$ instead of $1/\sigma^2$.
- Forgetting that the weights must sum to 1.
Part 2: The lattice walk
Each step is $(\Delta X,\Delta Y)\in{(\pm1,0),(0,\pm1)}$ with probability $1/4$ each.
2a. $\mathrm{Corr}(X_n,Y_n)=0$
- $\mathbb E\Delta X=\mathbb E\Delta Y=0$.
- $\Delta X,\Delta Y=0$ always, since a step changes only one coordinate. So the per-step covariance is 0.
- Steps are i.i.d., so covariances add: $\mathrm{Cov}(X_n,Y_n)=0$.
- $\mathrm{Var}(X_n)=\mathrm{Var}(Y_n)=n/2$, so the correlation is well defined and equals 0.
Uncorrelated is not independent. For example, if $|X_n|=n$ then $Y_n=0$, and $X_n+Y_n\equiv n \pmod 2$. Part 2b exposes this dependence.
2b. $\mathrm{Corr}(|X_n|,|Y_n|)$ is negative and about $-0.438/n$
Conditioning. Let $H\sim\mathrm{Bin}(n,1/2)$ be the number of horizontal steps. Given $H$, $X_n$ and $Y_n$ are independent 1D simple random walks with $H$ and $n-H$ steps. Let $f(k)=\mathbb E|S_k|$ for a 1D walk. Then
$$\mathrm{Cov}(|X_n|,|Y_n|)=\mathrm{Cov}\big(f(H),f(n-H)\big),$$
because the conditional covariance is 0. In addition:
- $\mathbb E|X_n|=\mathbb E f(H)$.
- $\mathrm{Var}|X_n|=\frac n2-(\mathbb E f(H))^2$.
- $f(2j)=f(2j-1)=2j\binom{2j}{j}4^{-j}$.
This gives an exact finite-sum formula.
Sign. $f$ is nondecreasing, so $f(H)$ increases with $H$ and $f(n-H)$ decreases with $H$. By Chebyshev's association inequality the covariance is $\le 0$, and it is strictly negative for $n\ge1$. Intuitively, a step spent going sideways is not spent going vertically.
Small cases.
- $n=1$: $|X|+|Y|=1$, so the correlation is $-1$.
- $n=2$: $\mathbb E|X||Y|=1/2$ (one horizontal and one vertical step, probability 1/2, product 1). Also $\mathbb E|X|=3/4$ and $\mathrm{Var}|X|=1-9/16=7/16$. So $\mathrm{Cov}=1/2-9/16=-1/16$ and $\mathrm{Corr}=-1/7$.
Asymptotics. For large $k$, $f(k)\approx\sqrt{2k/\pi}$, so $f'(n/2)\approx 1/\sqrt{\pi n}$. Also $\mathrm{Var}(H)=n/4$. Linearizing around $n/2$:
$$\mathrm{Cov}\approx -f'(n/2)^2,\mathrm{Var}(H)=-\frac{1}{4\pi}.$$
For the variance, $(\mathbb E|X_n|)^2\approx n/\pi$, so
$$\mathrm{Var}|X_n|\approx\frac n2-\frac n\pi=\frac{n(\pi-2)}{2\pi}.$$
Dividing:
$$\mathrm{Corr}(|X_n|,|Y_n|)\approx-\frac{1}{2(\pi-2),n}\approx-\frac{0.438}{n}\to0.$$
This matches the CLT: $(X_n,Y_n)/\sqrt n$ converges to independent Gaussians, so any dependence must vanish in the limit. It decays only like $1/n$, though, and the sign stays negative.
Alternative route. Let $U=X+Y$ and $V=X-Y$. Each step changes both by $\pm1$, and $U$ and $V$ are independent 1D walks of $n$ steps. Then $|X||Y|=|U^2-V^2|/4$, which gives another way to get exact moments.
Exact computation
from math import comb, pi
def corr_abs_walk(n: int) -> float:
def f(k): # E|S_k| for a 1D simple walk
j = (k + 1) // 2
return 2 * j * comb(2 * j, j) / 4**j
p = [comb(n, h) / 2**n for h in range(n + 1)]
mean = sum(ph * f(h) for h, ph in enumerate(p))
cross = sum(ph * f(h) * f(n - h) for h, ph in enumerate(p))
var = n / 2 - mean**2
return (cross - mean**2) / var
# n=1 -> -1.0, n=2 -> -1/7, n*corr -> -1/(2*(pi-2)) ≈ -0.438
Complexity is $O(n)$ terms, using exact binomials.
Points a strong answer covers
- Weights summing to 1, derived inverse-variance weights, and "precisions add".
- A per-step covariance argument for 2a, plus the remark that uncorrelated does not imply independent.
- For 2b: conditioning on the horizontal step count, a monotonicity argument for the sign, small-$n$ checks, and the $-1/(2(\pi-2)n)$ rate.