热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

加州大学伯克利分校Stat2.3xInference统计推断学习笔记:Section4DependentSamples

Stat2.3xInference(统计推断)课程由加州大学伯克利分校(UniversityofCalifornia,Berkeley)于2014年在edX平台讲授。PDF笔记下载

Stat2.3x Inference(统计推断)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授。

PDF笔记下载(Academia.edu)

Summary

Dependent Variables (paired samples)

  • SD of the difference is $$\sqrt{\sigma_x^2+\sigma_y^2-2\cdot r\cdot\sigma_x\cdot\sigma_y}$$ where $r$ is the correlation between the two variables X and Y.
  • Correlation $$r=\frac{1}{n}\cdot\sum_{i=1}^{n}(\frac{x_i-\bar{x}}{\sigma_x}\cdot\frac{y_i-\bar{y}}{\sigma_y})$$ where $$\sigma_x=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(x_i-\bar{x})^2}$$ $$\sigma_y=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_i-\bar{y})^2}$$ R function:
    cor(x, y)

ADDITIONAL PRACTICE PROBLEMS FOR EXERCISE SET 4

PROBLEM 1

To see whether caffeine affects the speed at which mice can run to a "reward", a simple random sample of 50 mice was taken from a large population of mice. Each mouse ran twice; once before the caffeine, and once after. The "before" run times had a mean of 32 seconds and an SD of 3 seconds. The "after" run times had a mean of 30 seconds and an SD of 3.5 seconds. The correlation between the "before" and "after" run times was 0.7. For 32 of the 50 mice, the "after" run time was shorter than the "before". Which of the following is a correct $z$ statistic to test whether mice in this population run faster after caffeine? More than one answer might be correct.

a) $(2 - 0) / \sqrt{0.424^2 + 0.495^2}$

b) $(2 - 0) / 0.362$

c) $(31.5 - 25) / 3.535$

Solution

Dependent paired variables, so (a) is incorrect. Based on the sample mean, we have $$H_0: \mu_1 = \mu_2$$ $$H_A: \mu_1 > \mu_2$$ and $$n=50, \mu_1=32, \mu_2=30, \sigma_1=3, \sigma_2=3.5$$ Therefore $$\sigma=\sqrt{\sigma_1^2+\sigma_2^2-2\cdot r\cdot\sigma_1\cdot\sigma_2}=\sqrt{3^2+{3.5}^2-2\times0.7\times3\times3.5}$$ $$ SE=\frac{\sigma}{\sqrt{n}}\Rightarrow z=\frac{\mu_1-\mu_2}{SE}=\frac{2-0}{0.362}$$ Thus, (b) is correct. We can conclude that the P-value is too small and reject $H_0$, that is, $\mu_1 > \mu _2$. R code:

sd = sqrt(3^2 + 3.5^2 - 2 * 0.7 * 3 * 3.5)
se = sd / sqrt(50); z = 2 / se
se
[1] 0.3619392
1 - pnorm(z)
[1] 1.640035e-08

(c) is correct, too. This is like a coin toss. $$H_0: p=0.5$$ $$H_A: p > 0.5 $$ where $p$ is the percent of "faster" mice of the population. The observed number of heads is 32. If the null were true, we would expect it to be 25 give or take: $$SE=\sqrt{\frac{p\cdot(1-p)}{n}}\cdot n=3.535$$ Thus $$z=\frac{31.5-25}{3.535}$$ Since the P-value is small so reject $H_0$, that is, $p > 0.5$. R code:

p = 0.5; n = 50
se = sqrt(p * (1 - p) / n)
z = (32 / 50 - p) / se
1 - pnorm(z)
[1] 0.02385744
se * 50
[1] 3.535534

PROBLEM 2

In a study on weight loss, a simple random sample of 500 of the 750 participants was placed in the "Diet 1" group and the remaining 250 in the "Diet 2" group. After the treatment, the average weight loss in the "Diet 1" group was 4.3 pounds with an SD of 1.2 pounds; the average weight lost in the "Diet 2" group was 3.9 pounds with an SD of 1.7 pounds. In the "Diet 1" group, 57% of the participants lost weight, compared to 54% in the "Diet 2" group.

a) To test whether the diet affected the mean amount of weight lost, the $z$ statistic is (fill in the blank): $(0.4 - 0)/( )$

b) To test whether the diet affects the percent of people who lose weight, the $z$ statistic is $(3 - 0)/( )$

Solution

Independent variables.

a. $$H_0: \mu_1=\mu_2$$ $$H_A: \mu_1\neq\mu_2$$ And $$n_1=500, n_2=250, \mu_1=4.3, \mu_2=3.9, \sigma_1=1.2, \sigma_2=1.7$$ $$\Rightarrow SE=\sqrt{SE_1^2+SE_2^2}=\sqrt{(\frac{\sigma_1}{\sqrt{n_1}})^2+(\frac{\sigma_2}{\sqrt{n_2}})^2}=0.1201666$$ Therefore, the P-value is 0.0008724816 which is smaller than 0.05. We reject $H_0$, that is, $\mu_1\neq\mu_2$. R code:

mu1 = 4.3; mu2 = 3.9; sd1 = 1.2; sd2 = 1.7; n1 = 500; n2 = 250
se1 = sd1 / sqrt(n1); se2 = sd2 / sqrt(n2); se = sqrt(se1^2 + se2^2)
se
[1] 0.1201666
z = (mu1 - mu2) / se
(1 - pnorm(z)) * 2
[1] 0.0008724816

b. $$H_0: p_1=p_2$$ $$H_A: p_1\neq p_2$$ And $$p_1=0.57, p_2=0.54, n_1=500, n_2=250, \hat{p}=\frac{n_1\cdot p_1+n_2\cdot p_2}{n_1+n_2}$$ $$\Rightarrow SE=\sqrt{SE_1^2+SE_2^2}=\sqrt{\frac{\hat{p}\cdot(1-\hat{p})}{n_1}+\frac{\hat{p}\cdot(1-\hat{p})}{n_2}}=0.03844997$$ R code:

p1 = 0.57; p2 = 0.54; n1 = 500; n2 = 250
p = (n1 * p1 + n2 * p2) / (n1 + n2)
se1 = sqrt(p * (1 - p) / n1); se2 = sqrt(p * (1 - p) / n2)
se = sqrt(se1^2 + se2^2)
se
[1] 0.03844997
z = (p1 - p2) / se
(1 - pnorm(z)) * 2
[1] 0.4352527

Because the P-value is larger than 0.05 so we reject $H_A$, that is, $p_1=p_2$.

EXERCISE SET 4

If a problem asks for an approximation, please use the methods described in the video lecture segments. Unless the problem says otherwise, please give answers correct to one decimal place according to those methods. Some of the problems below are about simple random samples. If the population size is not given, you can assume that the correction factor for standard errors is close enough to 1 that it does not need to be computed. Please use the 5% cutoff for P-values unless otherwise instructed in the problem.

PROBLEM 1

In a study of the effect of a medical treatment, a simple random sample of 300 of the 500 participating patients was assigned to the treatment group; the remaining patients formed the control group. When the patients were assessed at the end of the study, favorable outcomes were observed in 162 patients in the treatment group and 97 patients in the control group. Did the treatment have an effect, or is this just chance variation? Perform a statistical test, following the steps in Problems 1A-1D.

1A The null hypothesis is (pick the best among the options):

a. The treatment has an effect which could be good or bad.

b. The treatment has a good effect.

c. The treatment has no effect.

d. The treatment has a bad effect.

1B Under the null hypothesis, the SE of the difference between the percents of favorable outcomes in the two groups is about( )%.

1C The $z$ statistic is closest to?

1D The conclusion of the test is (pick the better of the two options): The observed difference is due to chance. The treatment has an effect.

Solution

1A) $$H_0: p_1=p_2$$ $$H_A: p_1 > p_2$$ where $p_1=\frac{162}{300}, p_2=\frac{97}{200}$.

1B) The samples are from the same population, so we don‘t use pooled estimate. $$SE=\sqrt{SE_1^2+SE_2^2}=\sqrt{\frac{p_1\cdot(1-p_1)}{n_1}+\frac{p_2\cdot(1-p_2)}{n_2}}=0.04557274$$

1C) $$z=\frac{p_1-p_2}{SE}=1.205771$$

1D) P-value is $0.1137427 > 0.05$, which concludes rejecting $H_A$. Therefore, the conclusion is $p_1=p_2$. R code:

p1 = 162 / 300; p2 = 97 / 200; n1 = 300; n2 = 200
se = sqrt(p1 * (1 - p1) / n1 + p2 * (1 - p2) / n2)
z = (p1 - p2) / se; z
[1] 1.206862
1 - pnorm(z)
[1] 0.1137427

PROBLEM 2

In a simple random sample of 250 father-son pairs taken from a large population of such pairs, the mean height of the fathers is 68.5 inches and the SD is 2.5 inches; the mean height of the sons is 69 inches and the SD is 3 inches; the correlation between the heights of the fathers and sons is 0.5. In the population, are the sons taller than their fathers, on average? Or is this just chance variation? Follow the steps in Problems 2A-2B.

2A The SE of the mean difference between heights of fathers and sons in the sample is closest to?

2B Which of the following most closely represents the result of the test?

a. The result is not statistically significant, so we conclude that it is due to chance variation.

b. The result is not statistically significant, so we conclude that the sons are taller than their fathers, on average.

c. The result is highly statistically significant, so we conclude that the sons are taller than their fathers, on average.

d. The result is highly statistically significant, so we conclude that it is due to chance variation.

Solution

2A) Dependent variables. $$H_0: \mu_1=\mu_2$$ $$H_A: \mu_1 <\mu_2$$ where $\mu_1, \mu_2$ represents the height of fathers and sons on average, respectively. We have $$n=250, \sigma_1=2.5, \sigma_2=3, \mu_1=68.5, \mu_2=69, r=0.5$$ and $$SE_1=\frac{\sigma_1}{\sqrt{n}}, SE_2=\frac{\sigma_2}{\sqrt{n}}$$ Thus $$SE=\sqrt{SE_1^2+SE_2^2-2\cdot r\cdot SE_1\cdot SE_2}=0.1760682$$

2B) $$z = \frac{\mu_1-\mu_2}{SE}=-2.839809$$ And the P-value is $0.002257026 <0.05$ which is statistically significant. Therefore, we reject $H_0$ and the conclusion is $\mu_1 <\mu_2$. R code:

n = 250; mu1 = 68.5; mu2 = 69; sigma1 = 2.5; sigma2=3; r = 0.5
se1 = sigma1 / sqrt(n); se2 = sigma2 / sqrt(n)
se = sqrt(se1^2 + se2^2 - 2 * r * se1 * se2)
se
[1] 0.1760682
z = (mu1 - mu2) / se; z
[1] -2.839809
pnorm(z)
[1] 0.002257026

PROBLEM 3

A group of scientists is studying whether a new medical treatment has an adverse (bad) effect on lung function. Here are data on a simple random sample of 10 patients taken from a large population of patients in the study. Both variables are measurements, in liters, of the amount of air that the patient can blow out (this is a very rough description of a well-defined measure). The bigger a measurement is, the better the lung function. The "baseline" measurement was taken before the treatment, and the "final" measurement was taken after the treatment.

Baseline        Final

4.19             4.17

4.52             4.20

4.50             4.53

3.90             3.95

4.33             4.15

4.30             4.19

3.94             3.96

4.35             4.26

4.21             4.07

4.17             3.93

In case you need summary statistics, here are some that are commonly used; the SDs have $n-1 = 9$ in the denominator. Baseline: mean 4.241, SD 0.2065 Final: mean 4.141, SD 0.1798 Correlation between baseline and final: 0.8055 Perform a one-sided test at the 5% level, following the steps in Problems 3A-3C.

3A Based on the information given, which test should you perform?

a. binomial test for the fairness of a coin

b. one-sample $z$ test for a population mean (quantitative variable; not proportions of zeros and ones)

c. one-sample $t$ test for a population mean

d. two-sample $z$ test for the difference between population means, based on independent samples

e. two-sample $z$ test for the effect of a treatment, applied to the results of a randomized controlled experiment

3B The P-value of the test is:

less than 1%

between 1% and 5%

between 5% and 10%

between 10% and 15%

between 15% and 20%

3C The conclusion of the test is: The treatment had a bad effect. The results are due to chance variation.

Solution

3A) (a) is correct. The data are paired, so this will be a one-sample test; this rules out (d) and (e). There are only 10 observations, so the probabilities for sample means need not be normal; this rules out (b). It cannot be $t$ test since there‘s no assumption about the underlying normality of the variables; this rules out (c). ($t$ test: population roughly normal, unknown mean and SD). The only thing left is to compare the results to tosses of a coin. Define a "head" to be a patient whose score goes down after treatment. Then we will test whether the number of heads is like the result of tossing a coin 10 times, or whether there are too many heads for "coin tossing" to be a reasonable conclusion. $$H_0: p=0.5$$ $$H_A: p>0.5$$ where $p=0.7$ is this sample. For the given mean, SD and $r$ in the problem, its calculation in R could be:

base = c(4.19, 4.52, 4.5, 3.9, 4.33, 4.3, 3.94, 4.35, 4.21, 4.17)
final = c(4.17, 4.2, 4.53, 3.95, 4.15, 4.19, 3.96, 4.26, 4.07, 3.93)
mean(base); sd(base); mean(final); sd(final); cor(base, final)
[1] 4.241
[1] 0.2064757
[1] 4.141
[1] 0.1798425
[1] 0.8054805

3B) In 7 of the 10 pairs, the patient‘s score went down. So we want the chance of 7 or more heads in 10 tosses of a coin. Binomial distribution, under the null $n=10, k=7:10, p=0.5$, so $$\sum_{k=7}^{10}C_{10}^{k}\cdot0.5^k\cdot0.5^{10-k}=0.171875$$ R code:

sum(dbinom(7:10, 10, 0.5))
[1] 0.171875

3C) P-value is 0.171875 which is larger than 0.05, so we reject $H_A$. That is, the conclusion is the result is due to chance variation ($p=0.5$).

加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 4 Dependent Samples


推荐阅读
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 本文介绍了指针的概念以及在函数调用时使用指针作为参数的情况。指针存放的是变量的地址,通过指针可以修改指针所指的变量的值。然而,如果想要修改指针的指向,就需要使用指针的引用。文章还通过一个简单的示例代码解释了指针的引用的使用方法,并思考了在修改指针的指向后,取指针的输出结果。 ... [详细]
author-avatar
fseiei
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有