Skip to content

Commit 8e4c519

Browse files
mmckyclaude
andauthored
[action-translation] resync: rand_resp.md (#149)
* 🔄 resync rand_resp.md * Restore trailing newline (engine issue tracked in QuantEcon/action-translation#116) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 65b6347 commit 8e4c519

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

.translate/state/rand_resp.md.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source-sha: d39b85fc089f59575047b7fc4a04a7561785c9ce
2+
synced-at: "2026-07-18"
3+
model: claude-sonnet-5
4+
mode: RESYNC
5+
section-count: 4
6+
tool-version: 0.17.0

lectures/rand_resp.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ kernelspec:
77
display_name: Python 3
88
language: python
99
name: python3
10+
translation:
11+
title: 随机化回应调查
12+
headings:
13+
Overview: 概述
14+
Warner's Strategy: Warner的策略
15+
Comparing Two Survey Designs: 比较两种调查设计
16+
Concluding Remarks: 结束语
1017
---
1118

1219
# 随机化回应调查
@@ -50,6 +57,7 @@ import pandas as pd
5057

5158
Warner {cite}`warner1965randomized` 提出并分析了以下程序:
5259

60+
- 从人群中有放回地抽取 $n$ 个随机样本,并对每个人进行访谈。
5361
- 从人群中有放回地抽取 $n$ 个随机样本,并对每个人进行访谈。
5462
- 准备一个**随机转盘**,该转盘指向字母 A 的概率为 $p$,指向字母 B 的概率为 $(1-p)$。
5563
- 每个受试者转动随机转盘,看到一个访谈者**看不到**的结果(A 或 B)。
@@ -88,7 +96,6 @@ $$
8896
8997
9098
$$
91-
9299
\pi p + (1-\pi)(1-p)=\frac{n_1}{n}
93100
$$ (eq:3)
94101
@@ -175,12 +182,11 @@ $$ (eq:ten)
175182
176183
$$
177184
\begin{aligned}
178-
179185
Var(\hat{\pi})&=\frac{ \left[ \pi T_a + (1-\pi)(1-T_b)\right] \left[1- \pi T_a -(1-\pi)(1-T_b)\right] }{n}
180186
\end{aligned}
181187
$$ (eq:eleven)
182188
183-
定义一个
189+
定义如下量是有用的:
184190
185191
$$
186192
\text{MSE 比率}=\frac{\text{随机化的均方误差}}{\text{常规的均方误差}}
@@ -221,9 +227,9 @@ class Comparison:
221227
A = self.A
222228
n = self.n
223229
df = self.template.copy()
224-
np.random.seed(seed)
225-
sample = np.random.rand(size, self.n) <= A
226-
random_device = np.random.rand(size, n)
230+
rng = np.random.default_rng(seed)
231+
sample = rng.random((size, self.n)) <= A
232+
random_device = rng.random((size, n))
227233
mse_rd = {}
228234
for p in self.p_arr:
229235
spinner = random_device <= p
@@ -232,8 +238,8 @@ class Comparison:
232238
pi_hat = (p - 1) / (2 * p - 1) + n1 / n / (2 * p - 1)
233239
mse_rd[p] = np.sum((pi_hat - A)**2)
234240
for inum, irow in df.iterrows():
235-
truth_a = np.random.rand(size, self.n) <= irow.T_a
236-
truth_b = np.random.rand(size, self.n) <= irow.T_b
241+
truth_a = rng.random((size, self.n)) <= irow.T_a
242+
truth_b = rng.random((size, self.n)) <= irow.T_b
237243
trad_answer = sample * truth_a + (1 - sample) * (1 - truth_b)
238244
pi_trad = trad_answer.sum(axis=1) / n
239245
df.loc[inum, 'Bias'] = pi_trad.mean() - A
@@ -315,4 +321,3 @@ df3_mc
315321
{doc}`这个QuantEcon讲座<util_rand_resp>`描述了一些其他的随机化回应调查方法。
316322
317323
该讲座介绍了Lars Ljungqvist {cite}`ljungqvist1993unified`对这些替代方案进行的功利主义分析。
318-

0 commit comments

Comments
 (0)