提交 0f91dee4 编写于 作者: W wizardforcel

2022-07-08 12:37:00

上级 3cce08be
......@@ -43,7 +43,7 @@
最后,我们可以看看实际的科学研究。让我们先来看看一项名为PURE study的大型研究,该研究调查了来自18个不同国家的13.5万多人的饮食和健康结果(包括死亡)。在对这个数据集的分析之一中(发表于2017年*The Lancet*; Dehghan等人( [2017](ch020.xhtml#ref-dehg:ment:zhan:2017) ) ),纯粹的调查者报告了一项分析,分析了在人们被跟踪的时间内,各种类型的宏量营养素(包括饱和脂肪和碳水化合物)的摄入与死亡可能性之间的关系。人们被随访的中位时间为7.4年,这意味着研究中一半的人被随访的时间更短,另一半被随访超过7.4年。图 [1.1](#fig:PureDeathSatFat) 绘制了该研究的一些数据(摘自论文),显示了饱和脂肪和碳水化合物的摄入与任何原因导致的死亡风险之间的关系。
![A plot of data from the PURE study, showing the relationship between death from any cause and the relative intake of saturated fats and carbohydrates.](../media/file0.png)
![A plot of data from the PURE study, showing the relationship between death from any cause and the relative intake of saturated fats and carbohydrates.](img/file0.png)
图1.1:PURE研究的数据图,显示了任何原因导致的死亡与饱和脂肪和碳水化合物的相对摄入量之间的关系。
......
......@@ -84,7 +84,7 @@
如果我们想要将一个测量值与另一个测量值进行比较,可靠性是很重要的,因为两个不同变量之间的关系不会比任何一个变量与其自身之间的关系(即其可靠性)更强。这意味着一个不可靠的度量永远不会与任何其他度量有很强的统计关系。出于这个原因,研究人员在开发一种新的测量方法(比如一项新的调查)时,通常会不遗余力地建立和提高其可靠性。
![A figure demonstrating the distinction between reliability and validity, using shots at a bullseye. Reliability refers to the consistency of location of shots, and validity refers to the accuracy of the shots with respect to the center of the bullseye. ](../media/file1.png)
![A figure demonstrating the distinction between reliability and validity, using shots at a bullseye. Reliability refers to the consistency of location of shots, and validity refers to the accuracy of the shots with respect to the center of the bullseye. ](img/file1.png)
图2.1:一个展示信度和效度区别的图,使用靶心射击。可靠性指的是射击位置的一致性,而有效性指的是射击相对于靶心中心的准确性。
......
......@@ -22,7 +22,7 @@
汇总数据的一个简单方法是生成一个表,表示各种类型的观察值的计数。这种类型的桌子已经使用了几千年(见图 [3.1](#fig:salesContract) )。
![A Sumerian tablet from the Louvre, showing a sales contract for a house and field. Public domain, via Wikimedia Commons.](../media/file2.jpg)
![A Sumerian tablet from the Louvre, showing a sales contract for a house and field. Public domain, via Wikimedia Commons.](img/file2.jpg)
图3.1:一块来自卢浮宫的苏美尔石碑,显示了一份房屋和田地的销售合同。公共领域,通过维基共享。
......@@ -80,7 +80,7 @@
| Eleven | Fifteen | Zero | Zero point three |
| Twelve | Seventeen | Zero | Zero point three four |
![Left: Histogram showing the number (left) and proportion (right) of people reporting each possible value of the SleepHrsNight variable.](../media/file3.png)
![Left: Histogram showing the number (left) and proportion (right) of people reporting each possible value of the SleepHrsNight variable.](img/file3.png)
图3.2:左:显示报告SleepHrsNight变量的每个可能值的人数(左)和比例(右)的直方图。
......@@ -105,7 +105,7 @@
让我们为我们的睡眠变量这样做,计算绝对和累积频率。在图 [3.3](#fig:sleepAbsCumulRelFreq) 的左图中,我们绘制了数据,看看这些表示是什么样子;绝对频率值用实线绘制,累积频率用虚线绘制。我们看到,累积频率是*单调增加的*——也就是说,它只能上升或保持不变,但永远不会下降。同样,我们通常发现相对频率比绝对频率更有用;这些绘制在图 [3.3](#fig:sleepAbsCumulRelFreq) 的右侧面板中。重要的是,相对频率图的形状与绝对频率图完全相同,只是数值的大小发生了变化。
![A plot of the relative (solid) and cumulative relative (dashed) values for frequency (left) and proportion (right) for the possible values of SleepHrsNight.](../media/file4.png)
![A plot of the relative (solid) and cumulative relative (dashed) values for frequency (left) and proportion (right) for the possible values of SleepHrsNight.](img/file4.png)
图3.3:sleep hrs night可能值的频率(左)和比例(右)的相对值(实线)和累积相对值(虚线)图。
......@@ -115,7 +115,7 @@
### 3.2.3 绘制直方图
![A histogram of the Age (left) and Height (right) variables in NHANES.](../media/file5.png)
![A histogram of the Age (left) and Height (right) variables in NHANES.](img/file5.png)
图3.4:NHANES中年龄(左)和身高(右)变量的直方图。
......@@ -127,7 +127,7 @@
您可能凭直觉认为小的高度来自数据集中的孩子。检验这一点的一种方法是用儿童和成人的不同颜色绘制直方图(图 [3.5](#fig:heightHistSep) 的左图)。这表明所有非常矮的身高确实来自样本中的儿童。让我们创建一个新版本的NHANES,它只包含成年人,然后为他们绘制直方图(图 [3.5](#fig:heightHistSep) 的右面板)。在那张图中,分布看起来更加对称。正如我们将在后面看到的,这是一个很好的*正态*(或*高斯*)分布的例子。
![Histogram of heights for NHANES. A: values plotted separately for children (gray) and adults (black). B: values for adults only. C: Same as B, but with bin width = 0.1](../media/file6.png)
![Histogram of heights for NHANES. A: values plotted separately for children (gray) and adults (black). B: values for adults only. C: Same as B, but with bin width = 0.1](img/file6.png)
图3.5:NHANES的高度直方图。答:分别为儿童(灰色)和成人(黑色)绘制的值。b:仅供成人使用。c:与B相同,但箱宽度= 0.1
......@@ -169,7 +169,7 @@
数据集就像雪花一样,每一个都是不同的,但尽管如此,在不同类型的数据中还是有一些常见的模式。这允许我们使用数据的理想化表示来进一步总结它们。让我们将成人身高数据绘制在 [3.5](#fig:heightHistSep) 中,并将它们与一个非常不同的变量一起绘制:脉率(每分钟心跳数),也是用NHANES测量的(见图 [3.6](#fig:NormalDistPlotsWithDist) )。
![Histograms for height (left) and pulse (right) in the NHANES dataset, with the normal distribution overlaid for each dataset.](../media/file7.png)
![Histograms for height (left) and pulse (right) in the NHANES dataset, with the normal distribution overlaid for each dataset.](img/file7.png)
图3.6:NHANES数据集中高度(左)和脉搏(右)的直方图,每个数据集都覆盖了正态分布。
......@@ -185,7 +185,7 @@
[3.7](#fig:SFOWaitTimes) 的左图显示了旧金山国际机场安检线的平均等待时间,这是一个相对轻微偏斜的例子。您可以看到,虽然大多数等待时间不到20分钟,但也有很多情况下等待时间要长得多,超过60分钟!这是一个“右偏”分布的例子,右尾比左尾长;当查看计数或测量时间时,这些是常见的,它们不能小于零。“左偏”分布不太常见,但可能会发生,例如在查看值不能大于1的小数值时。
![Examples of right-skewed and long-tailed distributions. Left: Average wait times for security at SFO Terminal A (Jan-Oct 2017), obtained from https://awt.cbp.gov/ . Right: A histogram of the number of Facebook friends amongst 3,663 individuals, obtained from the Stanford Large Network Database. The person with the maximum number of friends is indicated by the diamond.](../media/file8.png)
![Examples of right-skewed and long-tailed distributions. Left: Average wait times for security at SFO Terminal A (Jan-Oct 2017), obtained from https://awt.cbp.gov/ . Right: A histogram of the number of Facebook friends amongst 3,663 individuals, obtained from the Stanford Large Network Database. The person with the maximum number of friends is indicated by the diamond.](img/file8.png)
图3.7:右偏和长尾分布的例子。左图:SFO终端A的平均安检等待时间(2017年1月至10月),从[https://awt.cbp.gov/](https://awt.cbp.gov/)获得。右图:从斯坦福大学大型网络数据库获得的3663个人中脸书朋友数量的直方图。菱形表示拥有最多朋友的人。
......
......@@ -4,7 +4,7 @@
1986年1月28日,挑战者号航天飞机在起飞后73秒爆炸,机上7名宇航员全部遇难。正如任何此类灾难发生时一样,官方对事故原因进行了调查,发现连接固体火箭助推器两段的O形环泄漏,导致接头失效和大型液体燃料箱爆炸(见图 [4.1](#fig:srbLeak) )。
![An image of the solid rocket booster leaking fuel, seconds before the explosion. The small flame visible on the side of the rocket is the site of the O-ring failure. By NASA (Great Images in NASA Description) [Public domain], via Wikimedia Commons](../media/file9.jpg)
![An image of the solid rocket booster leaking fuel, seconds before the explosion. The small flame visible on the side of the rocket is the site of the O-ring failure. By NASA (Great Images in NASA Description) [Public domain], via Wikimedia Commons](img/file9.jpg)
图4.1:爆炸前几秒钟,固体火箭助推器泄漏燃料的图像。火箭侧面可见的小火焰就是O型圈失效的地方。由NASA(NASA描述中的伟大图像)[公共领域],通过维基共享
......@@ -12,7 +12,7 @@
可视化专家爱德华·塔夫特认为,如果恰当地展示所有数据,工程师们会更有说服力。特别是,他们可以展示类似于图 [4.2](#fig:challengerTemps) 中的图,这突出了两个重要的事实。首先,它表明O形环的损坏程度(由在以前的飞行中从海洋中回收固体火箭助推器后在环外发现的腐蚀和烟灰的数量来定义)与起飞时的温度密切相关。第二,它显示了1月28日早晨的预测温度范围(显示在阴影区域)远远超出了所有先前发射的范围。虽然我们不能确定,但至少看起来这可能更有说服力。
![A replotting of Tufte's damage index data. The line shows the trend in the data, and the shaded patch shows the projected temperatures for the morning of the launch.](../media/file10.png)
![A replotting of Tufte's damage index data. The line shows the trend in the data, and the shaded patch shows the projected temperatures for the morning of the launch.](img/file10.png)
图4.2:Tufte损坏指数数据的重新绘制。这条线显示了数据的趋势,阴影部分显示了发射当天早上的预计温度。
......@@ -34,7 +34,7 @@
4. 另一个选项是面板D中显示的*盒图*,它显示了中位数(中心线)、可变性的度量(盒的宽度,基于称为四分位距的度量)和任何异常值(由线末端的点标注)。这些都是显示数据的有效方法,为数据的分布提供了良好的感觉。
![Four different ways of plotting the difference in height between men and women in the NHANES dataset. Panel A plots the means of the two groups, which gives no way to assess the relative overlap of the two distributions. Panel B shows the same bars, but also overlays the data points, jittering them so that we can see their overall distribution. Panel C shows a violin plot, which shows the distribution of the datasets for each group. Panel D shows a box plot, which highlights the spread of the distribution along with any outliers (which are shown as individual points).](../media/file11.png)
![Four different ways of plotting the difference in height between men and women in the NHANES dataset. Panel A plots the means of the two groups, which gives no way to assess the relative overlap of the two distributions. Panel B shows the same bars, but also overlays the data points, jittering them so that we can see their overall distribution. Panel C shows a violin plot, which shows the distribution of the datasets for each group. Panel D shows a box plot, which highlights the spread of the distribution along with any outliers (which are shown as individual points).](img/file11.png)
图4.3:绘制NHANES数据集中男女身高差异的四种不同方法。图A绘出了两组的平均值,这没有给出评估两个分布的相对重叠的方法。图B显示了相同的条形,但也覆盖了数据点,使它们抖动,以便我们可以看到它们的总体分布。面板C显示了小提琴图,其显示了每个组的数据集的分布。图D显示了一个箱形图,该图突出显示了分布范围以及任何异常值(显示为单个点)。
......@@ -62,7 +62,7 @@
4. 面板D中的数据向我们展示了这两个变量之间的明显关系完全是由一个个体引起的,我们称这个个体为*异常值*,因为他们远远落在群体中其他人的模式之外。应该清楚的是,我们可能不想从一个数据点驱动的效应中得出太多结论。这个数字强调了为什么*总是*在过于相信任何数据摘要之前查看原始数据是重要的。
![Four different possible presentations of data for the dental health example. Each point in the scatter plot represents one data point in the dataset, and the line in each plot represents the linear trend in the data.](../media/file12.png)
![Four different possible presentations of data for the dental health example. Each point in the scatter plot represents one data point in the dataset, and the line in each plot represents the linear trend in the data.](img/file12.png)
图4.4:牙齿健康示例的四种不同的可能数据表示。散点图中的每个点代表数据集中的一个数据点,每个图中的线条代表数据中的线性趋势。
......@@ -76,7 +76,7 @@
<math xmlns:epub="http://www.idpf.org/2007/ops" display="block"><semantics><mrow>T3】dT5】a<mi>t</mi><mi>a</mi><mi>/</mi> <mi>I</mi><mi>n<mi>k</mi><mspace width="0.222em"><mi>r</mi><mi>a</mi><mi>t</mi><mi>I</mi><mi>o</mi><mo>=</mo><mfrac><mrow><mi>a</mi><mi>m</mi><mi>o<mi><mi>n</mi> <mi>o</mi><mi>n</mi><mspace width="0.167em"><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi></mspace></mi></mi></mrow><mrow><mi>t</mi><mi>o</mi><mi>t</mi><mi>a</mi><mi>l</mi><mspace width="0.167em"><mi>a</mi> <mi>used\,on\,data}{total\,amount\,of\,ink}</mi></mspace></mrow></mfrac></mspace></mi></mrow></semantics></math> 这样做的目的是尽量减少视觉上的杂乱,让数据透显出来。 例如,以图 [4.5](#fig:dataInkExample) 中牙齿健康数据的两个展示为例。两个面板显示相同的数据,但面板A更容易理解,因为它的数据/油墨比率相对较高。
![An example of the same data plotted with two different data/ink ratios.](../media/file13.png)
![An example of the same data plotted with two different data/ink ratios.](img/file13.png)
图4.5:用两种不同的数据/油墨比例绘制的相同数据的示例。
......@@ -94,7 +94,7 @@
* 它有一个令人分心的背景纹理
* 它使用三维条形图,这会扭曲数据
![An example of chart junk.](../media/file14.png)
![An example of chart junk.](img/file14.png)
图4.6:图表垃圾的一个例子。
......@@ -106,7 +106,7 @@
通常可以使用可视化来扭曲数据集的信息。一个非常常见的方法是使用不同的轴缩放来放大或隐藏数据模式。例如,我们想知道美国的暴力犯罪率是否发生了变化。在图 [4.7](#fig:crimePlotAxes) 中,我们可以看到这些数据的绘制方式要么让犯罪率看起来保持不变,要么让犯罪率直线下降。同样的数据,却能说出截然不同的两个故事!
![Crime data from 1990 to 2014 plotted over time. Panels A and B show the same data, but with different ranges of values along the Y axis. Data obtained from https://www.ucrdatatool.gov/Search/Crime/State/RunCrimeStatebyState.cfm](../media/file15.png)
![Crime data from 1990 to 2014 plotted over time. Panels A and B show the same data, but with different ranges of values along the Y axis. Data obtained from https://www.ucrdatatool.gov/Search/Crime/State/RunCrimeStatebyState.cfm](img/file15.png)
图4.7:1990年至2014年的犯罪数据随时间的变化。图A和B显示了相同的数据,但是沿Y轴的数值范围不同。数据来源于[https://www . ucrdatool . gov/Search/Crime/State/runcrimestatebystate . cfm](https://www.ucrdatatool.gov/Search/Crime/State/RunCrimeStatebyState.cfm)
......@@ -116,7 +116,7 @@
肯定有使用零点毫无意义的情况。假设我们对绘制一段时间内个体的体温感兴趣。在图 [4.8](#fig:bodyTempAxis) 中,我们绘制了Y轴上有零或没有零的相同(模拟)数据。显而易见的是,通过将这些数据标绘为Y轴上的零点(图A ),我们在图中浪费了大量的空间,因为一个活人的体温不可能达到零点!通过将零度包括在内,我们也使第21-30天的温度明显上升变得不那么明显。一般来说,我倾向于使用线图和散点图中的所有空间,除非零点真的非常重要。
![Body temperature over time, plotted with or without the zero point in the Y axis.](../media/file16.png)
![Body temperature over time, plotted with or without the zero point in the Y axis.](img/file16.png)
图4.8:体温随时间的变化,在Y轴上有或没有零点的情况下绘制。
......@@ -124,7 +124,7 @@
在许多情况下,谎言因素支持应该在条形图中包含零点的论点。在图 [4.9](#fig:barCharLieFactor) 中,我们绘制了Y轴上有无零点的相同数据。在图A中,两个条形之间的面积比例差与数值之间的面积比例差完全相同(即lie因子= 1),而在图B中(其中不包括零),两个条形之间的面积比例差大约是数值比例差的2.8倍,因此在视觉上夸大了差异的大小。
![Two bar charts with associated lie factors.](../media/file17.png)
![Two bar charts with associated lie factors.](img/file17.png)
图4.9:两个带有相关寿命因子的条形图。
......@@ -144,13 +144,13 @@
许多人(包括我自己)都有一个重要的感知限制,那就是色盲。这使得在元素之间只有颜色对比而没有亮度对比的图形(如图 [4.10](#fig:badColors) 中的图形)中很难感知信息。除了颜色之外,使用亮度和/或纹理差异很大的图形元素总是很有帮助的。还有[“色盲友好”调色板](http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/#a-colorblind-friendly-palette)可用于许多可视化工具。
![Example of a bad figure that relies solely on color contrast.](../media/file18.png)
![Example of a bad figure that relies solely on color contrast.](img/file18.png)
图4.10:仅仅依靠颜色对比的坏图的例子。
即使是色觉完美的人,也有感知上的局限,可以让一些情节失效。这就是为什么统计学家从不使用饼状图的原因之一:人类很难准确感知形状体积的差异。图 [4.11](#fig:pieChart) 中的饼状图(展示了我们上面展示的相同的宗教信仰数据)显示了这有多棘手。
![An example of a pie chart, highlighting the difficulty in apprehending the relative volume of the different pie slices.](../media/file19.png)
![An example of a pie chart, highlighting the difficulty in apprehending the relative volume of the different pie slices.](img/file19.png)
图4.11:一个饼图的例子,突出了理解不同饼图切片的相对体积的困难。
......@@ -158,7 +158,7 @@
使用更合理的方法绘制数据(图 [4.12](#fig:religionBars) ),我们可以更清楚地看到模式。该图可能看起来不像使用Excel生成的饼图那样华丽,但它是更有效、更准确的数据表示。
![A clearer presentation of the religious affiliation data (obtained from http://www.pewforum.org/religious-landscape-study/).](../media/file20.png)
![A clearer presentation of the religious affiliation data (obtained from http://www.pewforum.org/religious-landscape-study/).](img/file20.png)
图4.12:宗教归属数据的更清晰展示(从[http://www.pewforum.org/religious-landscape-study/](http://www.pewforum.org/religious-landscape-study/)获得)。
......@@ -174,7 +174,7 @@
通常我们感兴趣的是绘制数据,其中感兴趣的变量受我们感兴趣的因素之外的其他因素影响。例如,假设我们想了解汽油价格是如何随着时间的推移而变化的。图 [4.13](#fig:gasPrices) 显示了历史天然气价格数据,绘制时考虑或不考虑通货膨胀调整。虽然未经调整的数据显示了巨大的增长,但调整后的数据显示这主要只是通货膨胀的反映。需要根据其他因素调整数据的其他例子包括人口规模和不同季节收集的数据。
![The price of gasoline in the US from 1930 to 2013 (obtained from http://www.thepeoplehistory.com/70yearsofpricechange.html) with or without correction for inflation (based on Consumer Price Index).](../media/file21.png)
![The price of gasoline in the US from 1930 to 2013 (obtained from http://www.thepeoplehistory.com/70yearsofpricechange.html) with or without correction for inflation (based on Consumer Price Index).](img/file21.png)
图4.13:1930年至2013年美国汽油价格(从[http://www.thepeoplehistory.com/70yearsofpricechange.html](http://www.thepeoplehistory.com/70yearsofpricechange.html)获得),有无通货膨胀修正(基于消费者价格指数)。
......
......@@ -32,7 +32,7 @@
让我们来看一个使用NHANES中的数据构建数据模型的例子。特别是,我们将尝试在NHANES样本中建立一个儿童身高模型。首先,让我们加载数据并绘制它们(见图 [5.1](#fig:childHeight) )。
![Histogram of height of children in NHANES.](../media/file22.png)
![Histogram of height of children in NHANES.](img/file22.png)
图5.1:NHANES儿童身高直方图。
......@@ -58,7 +58,7 @@
事实证明,如果我们使用算术平均值作为我们的估计量,那么平均误差将确实为零(如果您感兴趣,请参见本章末尾的简单证明)。即使平均值的平均误差为零,我们也可以从图 [5.2](#fig:meanError) 的直方图中看到,每个个体仍有一定程度的误差;有些是正的,有些是负的,它们相互抵消,平均误差为零。
![Distribution of errors from the mean.](../media/file23.png)
![Distribution of errors from the mean.](img/file23.png)
图5.2:平均值的误差分布。
......@@ -74,7 +74,7 @@
我们能想象出更好的模式吗?请记住,这些数据来自NHANES样本中的所有儿童,年龄从2岁到17岁不等。考虑到这一广泛的年龄范围,我们可能期望我们的身高模型也应该包括年龄。让我们把身高和年龄的数据画出来,看看这种关系是否真的存在。
![Height of children in NHANES, plotted without a model (A), with a linear model including only age (B) or age and a constant (C), and with a linear model that fits separate effects of age for males and females (D).](../media/file24.png)
![Height of children in NHANES, plotted without a model (A), with a linear model including only age (B) or age and a constant (C), and with a linear model that fits separate effects of age for males and females (D).](img/file24.png)
图5.3:NHANES儿童的身高,绘制时未使用模型(A),线性模型仅包含年龄(B)或年龄和常数(C),线性模型适用于男性和女性的不同年龄效应(D)。
......@@ -96,7 +96,7 @@
使用这个模型,我们的误差要小得多——平均只有8.36厘米。你能想到其他可能与身高有关的变量吗?性别呢?在图 [5.3](#fig:childHeightLine) 的D图中,我们用分别适合男性和女性的线绘制数据。从剧情上看,似乎是有雌雄之分的,但比较小,只在青春期年龄后才出现。在图 [5.4](#fig:msePlot) 中,我们绘制了不同模型的均方根误差值,包括一个带有模拟性别影响的附加参数的模型。从这里我们可以看到,从众数到平均数,模型变得更好了一点,从平均数到平均数+年龄,模型变得更好了一点,并且通过包括性别也变得稍微好了一点。
![Mean squared error plotted for each of the models tested above.](../media/file25.png)
![Mean squared error plotted for each of the models tested above.](img/file25.png)
图5.4:上面测试的每个模型的均方误差图。
......@@ -114,7 +114,7 @@
让我们用一个例子来说明这一点。我们将使用计算机模拟来生成一些数据,而不是使用真实的数据(关于这一点,我们将在几章中详细介绍)。假设我们想要了解一个人的血液酒精含量(BAC)与他们在模拟驾驶测试中的反应时间之间的关系。我们可以生成一些模拟数据并绘制关系图(见图 [5.5](#fig:BACrt) 的A图)。
![Simulated relationship between blood alcohol content and reaction time on a driving test, with best-fitting linear model represented by the line. A: linear relationship with low measurement error. B: linear relationship with higher measurement error. C: Nonlinear relationship with low measurement error and (incorrect) linear model](../media/file26.png)
![Simulated relationship between blood alcohol content and reaction time on a driving test, with best-fitting linear model represented by the line. A: linear relationship with low measurement error. B: linear relationship with higher measurement error. C: Nonlinear relationship with low measurement error and (incorrect) linear model](img/file26.png)
图5.5:驾驶测试中血液酒精含量和反应时间之间的模拟关系,最佳拟合线性模型用直线表示。答:线性关系,测量误差小。b:线性关系,测量误差较高。c:具有低测量误差和(不正确的)线性模型的非线性关系
......@@ -134,7 +134,7 @@
为了看到这一点,让我们再次生成一些数据,以便我们知道变量之间的真实关系。我们将创建两个模拟数据集,它们以完全相同的方式生成,只是添加了不同的随机噪声。也就是他们两个人的方程是<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><mi>y</mi><mo>=</mo><mi>β<mo>*</mo><mi>x</mi><mo>+</mo><mi>ϵ</mi></mi></mrow><annotation encoding="application/x-tex">y = \ beta * x+</annotation></semantics></math>;唯一的区别是不同的随机噪声被用于<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mi>ϵ</mi><annotation encoding="application/x-tex"></annotation></semantics></math>在每种情况下。
![An example of overfitting. Both datasets were generated using the same model, with different random noise added to generate each set. The left panel shows the data used to fit the model, with a simple linear fit in blue and a complex (8th order polynomial) fit in red. The root mean square error (RMSE) values for each model are shown in the figure; in this case, the complex model has a lower RMSE than the simple model. The right panel shows the second dataset, with the same model overlaid on it and the RMSE values computed using the model obtained from the first dataset. Here we see that the simpler model actually fits the new dataset better than the more complex model, which was overfitted to the first dataset.](../media/file27.png)
![An example of overfitting. Both datasets were generated using the same model, with different random noise added to generate each set. The left panel shows the data used to fit the model, with a simple linear fit in blue and a complex (8th order polynomial) fit in red. The root mean square error (RMSE) values for each model are shown in the figure; in this case, the complex model has a lower RMSE than the simple model. The right panel shows the second dataset, with the same model overlaid on it and the RMSE values computed using the model obtained from the first dataset. Here we see that the simpler model actually fits the new dataset better than the more complex model, which was overfitted to the first dataset.](img/file27.png)
图5.6:过度拟合的例子。两个数据集都是使用相同的模型生成的,每个数据集都添加了不同的随机噪声。左图显示了用于拟合模型的数据,简单的线性拟合用蓝色表示,复杂的(8阶多项式)拟合用红色表示。每个模型的均方根误差(RMSE)值如图所示;在这种情况下,复杂模型的RMSE低于简单模型。右侧面板显示了第二个数据集,其上覆盖了相同的模型,并且使用从第一个数据集获得的模型计算了RMSE值。在这里,我们看到更简单的模型实际上比更复杂的模型更适合新的数据集,更复杂的模型过度适合第一个数据集。
......@@ -158,7 +158,7 @@
我们已经看到,均值是保证给我们零平均误差的估计量,但我们也知道平均误差不是最好的标准;相反,我们需要一个能给出最低误差平方和(SSE)的估计量,均值也是如此。我们可以用微积分来证明这一点,但我们将在图 [5.7](#fig:MinSSE) 中用图形来演示。
![A demonstration of the mean as the statistic that minimizes the sum of squared errors. Using the NHANES child height data, we compute the mean (denoted by the blue bar). Then, we test a range of possible parameter estimates, and for each one we compute the sum of squared errors for each data point from that value, which are denoted by the black curve. We see that the mean falls at the minimum of the squared error plot.](../media/file28.png)
![A demonstration of the mean as the statistic that minimizes the sum of squared errors. Using the NHANES child height data, we compute the mean (denoted by the blue bar). Then, we test a range of possible parameter estimates, and for each one we compute the sum of squared errors for each data point from that value, which are denoted by the black curve. We see that the mean falls at the minimum of the squared error plot.](img/file28.png)
图5.7:显示了最小化误差平方和的统计平均值。使用NHANES儿童身高数据,我们计算平均值(用蓝色条表示)。然后,我们测试一系列可能的参数估计值,对于每一个估计值,我们根据该值计算每个数据点的误差平方和,用黑色曲线表示。我们看到平均值落在平方误差图的最小值处。
......@@ -270,13 +270,13 @@ SSE的最小化是一个很好的特性,这也是为什么平均值是最常
根据集中趋势和可变性描述了分布的特征后,根据各个分数相对于总体分布的位置来表示它们通常是有用的。假设我们感兴趣的是描述不同州之间犯罪的相对水平,以确定加州是否是一个特别危险的地方。我们可以使用来自联邦调查局统一犯罪报告网站的2014年数据来问这个问题。图 [5.8](#fig:crimeHist) 的左面显示了各州暴力犯罪数量的直方图,突出显示了加利福尼亚州的数值。看着这些数据,加州似乎非常危险,那一年有153709起犯罪。我们可以通过生成一个显示变量在各州分布的图来可视化这些数据,该图显示在图 [5.8](#fig:crimeHist) 的右侧面板中。
![Left: Histogram of the number of violent crimes. The value for CA is plotted in blue. Right: A map of the same data, with number of crimes (in thousands) plotted for each state in color.](../media/file29.png)
![Left: Histogram of the number of violent crimes. The value for CA is plotted in blue. Right: A map of the same data, with number of crimes (in thousands) plotted for each state in color.](img/file29.png)
图5.8:左图:暴力犯罪数量直方图。CA的值用蓝色标出。右图:相同数据的地图,用彩色标出了每个州的犯罪数量(以千计)。
然而,你可能已经想到,加州也是美国人口最多的州,所以它也有更多的犯罪是合理的。如果我们针对每个州的一个人口绘制犯罪数量图(见图 [5.9](#fig:popVsCrime) 的左图),我们会看到两个变量之间存在直接关系。
![Left: A plot of number of violent crimes versus population by state. Right: A histogram of per capita violent crime rates, expressed as crimes per 100,000 people.](../media/file30.png)
![Left: A plot of number of violent crimes versus population by state. Right: A histogram of per capita violent crime rates, expressed as crimes per 100,000 people.](img/file30.png)
图5.9:左图:各州暴力犯罪数量与人口的关系图。右图:人均暴力犯罪率直方图,以每10万人的犯罪率表示。
......@@ -288,13 +288,13 @@ Z值允许我们以一种方式表达数据,这种方式提供了对每个数
直观地说,您可以将Z分数视为告诉您任何数据点离平均值有多远,以标准差为单位。我们可以对犯罪率数据进行计算,如图 [5.10](#fig:crimeZplot) 所示,该图绘制了Z分数与原始分数的关系。
![Scatterplot of original crime rate data against Z-scored data.](../media/file31.png)
![Scatterplot of original crime rate data against Z-scored data.](img/file31.png)
图5.10:原始犯罪率数据与Z得分数据的散点图。
散点图向我们展示了Z计分的过程并没有改变数据点的相对分布(从原始数据和Z计分的数据在相互标绘时落在一条直线上的事实中可以看出),它只是将它们移动到平均值为0,标准偏差为1。图 [5.11](#fig:crimeZmap) 显示了使用地理视图的Z得分犯罪数据。
![Crime data rendered onto a US map, presented as Z-scores.](../media/file32.png)
![Crime data rendered onto a US map, presented as Z-scores.](img/file32.png)
图5.11:呈现在美国地图上的犯罪数据,以Z分数表示。
......@@ -306,13 +306,13 @@ Z值允许我们以一种方式表达数据,这种方式提供了对每个数
“Z-score”中的“Z”来自于标准正态分布(即均值为零、标准差为1的正态分布)通常被称为“Z”分布。我们可以使用标准正态分布来帮助我们理解特定的Z分数告诉我们关于数据点相对于分布的其余部分的位置。
![Density (top) and cumulative distribution (bottom) of a standard normal distribution, with cutoffs at one standard deviation above/below the mean.](../media/file33.png)
![Density (top) and cumulative distribution (bottom) of a standard normal distribution, with cutoffs at one standard deviation above/below the mean.](img/file33.png)
图5.12:标准正态分布的密度(上图)和累积分布(下图),截止值在平均值之上/之下的一个标准差处。
[5.12](#fig:zDensityCDF) 中的上图显示,我们预计约有16%的值落在<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><mi>Z</mi><mo></mo><mn>1</mn></mrow><annotation encoding="application/x-tex">Z \ ge 1</annotation></semantics></math>中,同样比例的值落在<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><mi>Z</mi><mo></mo><mn>1</mn></mrow></semantics></math>
![Density (top) and cumulative distribution (bottom) of a standard normal distribution, with cutoffs at two standard deviations above/below the mean](../media/file34.png)
![Density (top) and cumulative distribution (bottom) of a standard normal distribution, with cutoffs at two standard deviations above/below the mean](img/file34.png)
图5.13:标准正态分布的密度(上图)和累积分布(下图),在高于/低于平均值的两个标准差处有截止值
......@@ -326,7 +326,7 @@ Z值允许我们以一种方式表达数据,这种方式提供了对每个数
假设我们想要生成平均值为100、标准差为10的标准化犯罪分数,而不是Z分数。这类似于用智力测验的分数来产生智商(IQ)的标准化。我们可以通过简单地将Z分数乘以10,然后加上100来实现。
![Crime data presented as standardized scores with mean of 100 and standard deviation of 10.](../media/file35.png)
![Crime data presented as standardized scores with mean of 100 and standard deviation of 10.](img/file35.png)
图5.14:犯罪数据显示为标准化分数,平均值为100,标准差为10。
......@@ -336,13 +336,13 @@ Z值允许我们以一种方式表达数据,这种方式提供了对每个数
Z分数的一个有用的应用是比较不同变量的分布。假设我们想比较暴力犯罪和财产犯罪在各州的分布情况。在图 [5.15](#fig:crimeTypePlot) 的左图中,我们用蓝色标出CA。如你所见,财产犯罪的原始比率远远高于暴力犯罪的原始比率,所以我们不能直接比较数字。然而,我们可以绘制这些数据彼此之间的Z分数(图 [5.15](#fig:crimeTypePlot) 的右图)——我们再次看到数据的分布没有变化。将数据放入每个变量的Z分数中,使它们具有可比性,并让我们看到,就暴力犯罪和财产犯罪而言,加州实际上位于分布的中间。
![Plot of violent vs. property crime rates (left) and Z-scored rates (right).](../media/file36.png)
![Plot of violent vs. property crime rates (left) and Z-scored rates (right).](img/file36.png)
图5.15:暴力与财产犯罪率(左)和Z得分率(右)。
我们再给剧情加一个因素:人口。在图 [5.16](#fig:crimeTypePopPlot) 的左侧面板中,我们使用绘图符号的大小显示了这一点,这通常是向绘图添加信息的有用方式。
![Left: Plot of violent vs. property crime rates, with population size presented through the size of the plotting symbol; California is presented in blue. Right: Difference scores for violent vs. property crime, plotted against population. ](../media/file37.png)
![Left: Plot of violent vs. property crime rates, with population size presented through the size of the plotting symbol; California is presented in blue. Right: Difference scores for violent vs. property crime, plotted against population. ](img/file37.png)
图5.16:左图:暴力犯罪率与财产犯罪率的对比图,人口数量通过绘图符号的大小表示;加州以蓝色呈现。右图:暴力犯罪与财产犯罪的得分差异,与人口相对照。
......
......@@ -49,7 +49,7 @@
[6.1](#fig:ElectionResults) 的左图显示,随着样本数量(即抛硬币试验)的增加,估计的正面概率收敛到真实值0.5。但是,请注意,当样本量很小时,估计值可能与真实值相差很远。这方面的一个真实例子是2017年阿拉巴马州美国参议院特别选举,共和党人罗伊·摩尔与民主党人道格·琼斯进行了对决。图 [6.1](#fig:ElectionResults) 的右侧面板显示了随着计票数量的增加,当晚每位候选人的相对票数。晚上早些时候的计票尤其不稳定,从琼斯最初的大幅领先到摩尔长期领先,直到最后琼斯领先赢得比赛。
![Left: A demonstration of the law of large numbers. A coin was flipped 30,000 times, and after each flip the probability of heads was computed based on the number of heads and tail collected up to that point. It takes about 15,000 flips for the probability to settle at the true probability of 0.5\. Right: Relative proportion of the vote in the Dec 12, 2017 special election for the US Senate seat in Alabama, as a function of the percentage of precincts reporting. These data were transcribed from https://www.ajc.com/news/national/alabama-senate-race-live-updates-roy-moore-doug-jones/KPRfkdaweoiXICW3FHjXqI/](../media/file38.png)
![Left: A demonstration of the law of large numbers. A coin was flipped 30,000 times, and after each flip the probability of heads was computed based on the number of heads and tail collected up to that point. It takes about 15,000 flips for the probability to settle at the true probability of 0.5\. Right: Relative proportion of the vote in the Dec 12, 2017 special election for the US Senate seat in Alabama, as a function of the percentage of precincts reporting. These data were transcribed from https://www.ajc.com/news/national/alabama-senate-race-live-updates-roy-moore-doug-jones/KPRfkdaweoiXICW3FHjXqI/](img/file38.png)
图6.1:左图:大数定律的演示。一枚硬币被抛了30,000次,每次抛完之后,正面的概率是根据当时收集到的正面和反面的数量来计算的。大约需要15,000次翻转,概率才会稳定在0.5的真实概率。右图:2017年12月12日阿拉巴马州美国参议院席位特别选举中投票的相对比例,作为选区报告百分比的函数。这些数据转录自[https://www . AJC . com/news/national/Alabama-Senate-race-live-updates-Roy-Moore-Doug-Jones/kprfkdaweixizw3fhjxqi/](https://www.ajc.com/news/national/alabama-senate-race-live-updates-roy-moore-doug-jones/KPRfkdaweoiXICW3FHjXqI/)
......@@ -97,7 +97,7 @@ de Méré基于这个错误的假设进行推理,即四次掷骰中至少有
<semantics><mrow><mi>【p】</mi><mrow><mo stretchy="true" form="prefix">【r】<mi><mn>【2】</mn></mi></mo></mrow><mo stretchy="true" form="postfix">)</mo></mrow><mo>=</mo><mi><mrow><mo stretchy="true" form="prefix">(</mo></mrow> <mo>+</mo><mi>【p104】<mrow><mo stretchy="true" form="prefix"><mi>【r】<mi>【T1112】【l】</mi></mi></mo></mrow> 【T1137】-【T1138】<mi><mrow>【T1142】<mi><mi><mi><mi>【l148】 <mi>w</mi><mn>【2】</mn></mi></mi></mi></mi></mrow><mo stretchy="true" form="postfix">)</mo><annotation encoding="application/x-tex">p(卷6 _ {扔1} \ cup 6 _ {扔2}) = P(卷6 _ {扔1 }))</annotation></mi></mi></mi></semantics>
![Each cell in this matrix represents one outcome of two throws of a die, with the columns representing the first throw and the rows representing the second throw. Cells shown in red represent the cells with a six in either the first or second throw; the rest are shown in blue.](../media/file39.png)
![Each cell in this matrix represents one outcome of two throws of a die, with the columns representing the first throw and the rows representing the second throw. Cells shown in red represent the cells with a six in either the first or second throw; the rest are shown in blue.](img/file39.png)
图6.2:这个矩阵中的每个单元格代表一个骰子两次投掷的结果,列代表第一次投掷,行代表第二次投掷。显示为红色的单元格表示第一次或第二次投掷中有6的单元格;其余的用蓝色显示。
......@@ -188,7 +188,7 @@ de Méré赌他会在四次掷骰子中至少掷出一个6,这个概率大于0
也就是说,我们想知道两个事物都为真的概率,假定被作为条件的一个是真的。
![A graphical depiction of conditional probability, showing how the conditional probability limits our analysis to a subset of the data.](../media/file40.png)
![A graphical depiction of conditional probability, showing how the conditional probability limits our analysis to a subset of the data.](img/file40.png)
图6.3:条件概率的图形描述,显示了条件概率如何将我们的分析限制在数据的一个子集。
......
......@@ -41,7 +41,7 @@
样本均值和标准差相似,但不完全等于总体值。现在,让我们从50个个体中抽取大量样本,计算每个样本的平均值,并查看平均值的抽样分布。为了很好地估计抽样分布,我们必须决定取多少样本——在这种情况下,我们将取5000个样本,这样我们对答案非常有信心。请注意,像这样的模拟有时需要几分钟才能运行,可能会让您的计算机气鼓鼓的。图 [7.1](#fig:samplePlot) 中的直方图显示,50个个体的每个样本的估计均值略有不同,但总体而言,它们以总体均值为中心。5000个样本平均值(168.3463)非常接近真实总体平均值(168.3497)。
![The blue histogram shows the sampling distribution of the mean over 5000 random samples from the NHANES dataset. The histogram for the full dataset is shown in gray for reference.](../media/file41.png)
![The blue histogram shows the sampling distribution of the mean over 5000 random samples from the NHANES dataset. The histogram for the full dataset is shown in gray for reference.](img/file41.png)
图7.1:蓝色直方图显示了NHANES数据集中超过5000个随机样本的平均抽样分布。完整数据集的直方图以灰色显示,以供参考。
......@@ -73,7 +73,7 @@
为了查看中心极限定理的作用,让我们使用NHANES数据集中的变量AlcoholYear,它是高度偏斜的,如图 [7.2](#fig:alcDist50) 的左图所示。由于没有更好的词来形容,这种分布是时髦的——而且肯定不是正态分布。现在让我们看看这个变量的均值的抽样分布。图 [7.2](#fig:alcDist50) 显示了该变量的抽样分布,通过从NHANES数据集中重复抽取50个样本并取平均值获得。尽管原始数据显然是非正态的,但抽样分布非常接近正态。
![Left: Distribution of the variable AlcoholYear in the NHANES dataset, which reflects the number of days that the individual drank in a year. Right: The sampling distribution of the mean for AlcoholYear in the NHANES dataset, obtained by drawing repeated samples of size 50, in blue. The normal distribution with the same mean and standard deviation is shown in red.](../media/file42.png)
![Left: Distribution of the variable AlcoholYear in the NHANES dataset, which reflects the number of days that the individual drank in a year. Right: The sampling distribution of the mean for AlcoholYear in the NHANES dataset, obtained by drawing repeated samples of size 50, in blue. The normal distribution with the same mean and standard deviation is shown in red.](img/file42.png)
图7.2:左:NHANES数据集中变量AlcoholYear的分布,它反映了个人一年中饮酒的天数。右图:NHANES数据集中酒精年份平均值的抽样分布,通过绘制50个蓝色重复样本获得。具有相同平均值和标准偏差的正态分布显示为红色。
......
......@@ -45,7 +45,7 @@
大多数统计软件都包括为每个主要概率分布生成随机数的功能,例如均匀分布(0到1之间的所有值相等)、正态分布和二项式分布(例如掷骰子、掷硬币)。图 [8.1](#fig:rngExamples) 显示了从均匀分布函数和正态分布函数生成的数字示例。
![Examples of random numbers generated from a uniform (left) or normal (right) distribution.](../media/file43.png)
![Examples of random numbers generated from a uniform (left) or normal (right) distribution.](img/file43.png)
图8.1:从均匀分布(左)或正态分布(右)生成的随机数示例。
......@@ -61,13 +61,13 @@
让我们回到考试结束时间的例子。假设我管理三次测验,并记录每个学生每次考试的完成时间,这可能看起来像图 [8.2](#fig:finishingTimes) 中呈现的分布。
![Simulated finishing time distributions.](../media/file44.png)
![Simulated finishing time distributions.](img/file44.png)
图8.2:模拟的结束时间分布。
要回答我们的问题,我们真正想知道的不是完成时间的分布是什么样的,而是每次测验的最长完成时间的分布是什么样的。为了做到这一点,我们可以模拟一个测验的结束时间,假设结束时间是正态分布的,如上所述;对于每个模拟测验,我们会记录最长的完成时间。我们大量重复这种模拟(5000次应该足够了)并记录完成次数的分布,如图 [8.3](#fig:finishTimeSim) 所示。
![Distribution of maximum finishing times across simulations.](../media/file45.png)
![Distribution of maximum finishing times across simulations.](img/file45.png)
图8.3:模拟中最大完成时间的分布。
......@@ -91,7 +91,7 @@ bootstrap背后的想法是我们从实际的数据集中重复采样;重要
让我们从使用bootstrap估计NHANES数据集中成人身高平均值的抽样分布开始,这样我们就可以将结果与我们之前讨论的平均值的标准误差(SEM)进行比较。
![An example of bootstrapping to compute the standard error of the mean adult height in the NHANES dataset. The histogram shows the distribution of means across bootstrap samples, while the red line shows the normal distribution based on the sample mean and standard deviation.](../media/file46.png)
![An example of bootstrapping to compute the standard error of the mean adult height in the NHANES dataset. The histogram shows the distribution of means across bootstrap samples, while the red line shows the normal distribution based on the sample mean and standard deviation.](img/file46.png)
图8.4:计算NHANES数据集中成人平均身高标准误差的自举示例。直方图显示了bootstrap样本的均值分布,而红线显示了基于样本均值和标准差的正态分布。
......
......@@ -102,7 +102,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
| 不 | One hundred and thirty-one | Thirty | Nine |
| 是 | One hundred and nineteen | Twenty-seven | Five point two |
![Box plot of BMI data from a sample of adults from the NHANES dataset, split by whether they reported engaging in regular physical activity.](../media/file47.png)
![Box plot of BMI data from a sample of adults from the NHANES dataset, split by whether they reported engaging in regular physical activity.](img/file47.png)
图9.1:来自NHANES数据集的成年人样本的身体质量指数数据的箱线图,根据他们是否报告参加定期身体活动来划分。
......@@ -124,7 +124,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
<math xmlns:epub="http://www.idpf.org/2007/ops" display="block"><semantics><mrow><mstyle mathvariant="normal"><mi>d</mi> <mi></mi> <mi>f</mi> <mi></mi></mstyle><mo>=</mo><mfrac><msup><mrow><mo stretchy="true" form="prefix">(</mo><mfrac><msubsup><mi>S</mi><mn>1</mn><mn>2</mn></msubsup><msub>T30】n<mn>1</mn></msub></mfrac><mo>+</mo><mfrac><msubsup><mi>S</mi><mn>2</mn><mn>2</mn></msubsup></mfrac></mrow> <mn>2</mn></msup><mrow><mfrac><msup><mrow><mo stretchy="true" form="prefix">(</mo><msubsup><mi>S</mi><mn>1</mn><mn>2</mn></msubsup><mi>/</mi><msub><mi>n</mi><mn>1</mn></msub><mo stretchy="true" form="postfix">)</mo></mrow> <mn>2</mn></msup><mrow><msub><mi>n</mi><mn>1</mn></msub><mo>—T97】1</mo></mrow></mfrac><mo>+</mo><mfrac><msup><mrow><mo stretchy="true" form="prefix">(</mo><msubsup><mi>S</mi><mn>2</mn></msubsup></mrow><mn>2</mn></msup><mrow><msub><mi>n</mi><mn>2</mn></msub><mo></mo><mn>1</mn></mrow></mfrac></mrow></mfrac></mrow><annotation encoding="application/x-tex">【mathrm { d . f . } = \frac{\left(\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}\right)^2}{\frac{\left(s_1^2/n_1\right)^2}{n_1-1}+\frac{\left(s_2^2/n_2\right)^2}{n_2-1}}</annotation></semantics></math> 这将等于<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><msub><mi>n</mi><mn>1</mn></msub><mo>+</mo><msub><mi>n</mi><mn>2</mn></msub><mo>-<mn>2</mn></mo></mrow><annotation encoding="application/x-tex">n _ 1 对于本例,得出的值为241.12,略低于从样本量中减去2得到的值248。</annotation></semantics></math>
![Each panel shows the t distribution (in blue dashed line) overlaid on the normal distribution (in solid red line). The left panel shows a t distribution with 4 degrees of freedom, in which case the distribution is similar but has slightly wider tails. The right panel shows a t distribution with 1000 degrees of freedom, in which case it is virtually identical to the normal.](../media/file48.png)
![Each panel shows the t distribution (in blue dashed line) overlaid on the normal distribution (in solid red line). The left panel shows a t distribution with 4 degrees of freedom, in which case the distribution is similar but has slightly wider tails. The right panel shows a t distribution with 1000 degrees of freedom, in which case it is virtually identical to the normal.](img/file48.png)
图9.2:每个面板显示了叠加在正态分布(红色实线)上的t分布(蓝色虚线)。左图显示了具有4个自由度的t分布,在这种情况下,分布是相似的,但尾部略宽。右图显示了具有1000个自由度的t分布,在这种情况下,它实际上与正态分布相同。
......@@ -148,7 +148,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
<semantics><mrow><mi>【p】</mi><mrow><mo stretchy="true" form="prefix">(</mo><mi>【x】</mi>【k】</mrow></mrow></semantics>
![Distribution of numbers of heads (out of 100 flips) across 100,000 simulated runs with the observed value of 70 flips represented by the vertical line.](../media/file49.png)
![Distribution of numbers of heads (out of 100 flips) across 100,000 simulated runs with the observed value of 70 flips represented by the vertical line.](img/file49.png)
图9.3:100,000次模拟运行中的头数分布(100次翻转中),观察到的70次翻转值用垂直线表示。
......@@ -200,7 +200,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
| 容抗 | One hundred and twenty-five | Two hundred and sixty-five |
| 容抗 | One hundred and fifteen | Three hundred and ten |
![Left: Box plots of simulated squatting ability for football players and cross-country runners.Right: Box plots for subjects assigned to each group after scrambling group labels.](../media/file50.png)
![Left: Box plots of simulated squatting ability for football players and cross-country runners.Right: Box plots for subjects assigned to each group after scrambling group labels.](img/file50.png)
图9.4:左图:足球运动员和越野跑运动员模拟蹲姿能力的方框图。右图:打乱组标签后分配到每个组的受试者的方框图。
......@@ -224,7 +224,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
现在让我们看看如何用随机化回答同样的问题。基本思想是,如果组间无差异的零假设为真,那么哪一组来自哪一组(足球运动员对越野跑运动员)并不重要——因此,为了创建与我们的实际数据相似但又符合零假设的数据,我们可以随机对数据集中的个体数据进行重新排序,然后重新计算组间的差异。这种混洗的结果显示在表 [9.2](#tab:squatPlot) 中标有“shuffleSquat”的列中,所得数据的箱线图显示在图 [9.4](#fig:squatPlot) 的右侧面板中。
![Histogram of t-values for the difference in means between the football and cross-country groups after randomly shuffling group membership. The vertical line denotes the actual difference observed between the two groups, and the dotted line shows the theoretical t distribution for this analysis.](../media/file51.png)
![Histogram of t-values for the difference in means between the football and cross-country groups after randomly shuffling group membership. The vertical line denotes the actual difference observed between the two groups, and the dotted line shows the theoretical t distribution for this analysis.](img/file51.png)
图9.5:随机调整组成员后,足球组和越野组之间均值差异的t值直方图。垂直线表示在两组之间观察到的实际差异,虚线表示该分析的理论t分布。
......@@ -236,7 +236,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
现在,让我们使用随机化来计算身体质量指数/活动示例的p值。在这种情况下,我们将随机打乱`PhysActive`变量,并在每次打乱后计算各组之间的差异,然后将我们观察到的 *t* 统计数据与打乱数据集的 *t* 统计数据的分布进行比较。图 [9.6](#fig:simDiff) 显示了混洗样本中 *t* 值的分布,我们还可以计算出找到与观察值一样大或比观察值更大的值的概率。从随机化获得的p值(0.000000)非常类似于使用 *t* 分布获得的值(0.000075)。随机化检验的优点是,它不要求我们假设每个组的数据都是正态分布的,尽管t检验通常对违反该假设的情况非常稳健。此外,当我们没有像t检验那样的理论分布时,随机化检验可以允许我们计算统计的p值。
![Histogram of t statistics after shuffling of group labels, with the observed value of the t statistic shown in the vertical line, and values at least as extreme as the observed value shown in lighter gray](../media/file52.png)
![Histogram of t statistics after shuffling of group labels, with the observed value of the t statistic shown in the vertical line, and values at least as extreme as the observed value shown in lighter gray](img/file52.png)
图9.6:组标签重排后的t统计直方图,观察到的t统计值显示在垂直线中,值至少与观察到的值一样极端,以浅灰色显示
......@@ -335,7 +335,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
[9.7](#fig:sigResults) 显示了显著结果的比例如何随着样本量的增加而增加,因此,对于非常大的样本量(总共约262,000名受试者),当两种饮食之间的体重减轻量相差1盎司时,我们将在超过90%的研究中发现显著结果。虽然这些在统计学上是显著的,但大多数医生不会认为体重减轻一盎司在实践上或临床上是显著的。当我们回到第 [10.3节](#statistical-power)中的*统计功效*的概念时,我们将更详细地探讨这种关系,但是从这个例子中应该已经清楚,统计显著性不一定表示实际显著性。
![The proportion of signifcant results for a very small change (1 ounce, which is about .001 standard deviations) as a function of sample size.](../media/file53.png)
![The proportion of signifcant results for a very small change (1 ounce, which is about .001 standard deviations) as a function of sample size.](img/file53.png)
图9.7:非常小的变化(1盎司,大约0.001标准偏差)的显著结果的比例与样本大小的函数关系。
......@@ -355,7 +355,7 @@ NHST也被广泛误解,主要是因为它违背了我们关于统计假设检
让我们想象一下,如果研究人员只是简单地问测试在来自零分布的p <.05 at="" each="" location="" when="" in="" fact="" there="" is="" no="" true="" effect="" any="" of="" the="" locations.="" to="" do="" this="" we="" generate="" a="" large="" number="" simulated="" xmlns:epub="http://www.idpf.org/2007/ops"> t 值处是否显著,并问其中有多少在p<0.05处显著,会发生什么。让我们这样做很多次,每次都计算出有多少测试结果是显著的(见图 [9.8](#fig:nullSim) )。
![Left: A histogram of the number of significant results in each set of one million statistical tests, when there is in fact no true effect. Right: A histogram of the number of significant results across all simulation runs after applying the Bonferroni correction for multiple tests.](../media/file54.png)
![Left: A histogram of the number of significant results in each set of one million statistical tests, when there is in fact no true effect. Right: A histogram of the number of significant results across all simulation runs after applying the Bonferroni correction for multiple tests.](img/file54.png)
图9.8:左图:当实际上没有真实效果时,每组一百万个统计测试中显著结果数量的直方图。右图:对多个测试应用Bonferroni校正后,所有模拟运行的重要结果数量的直方图。
......
......@@ -56,7 +56,7 @@
我们用NHANES的数据作为我们的人口可以看到这一点;在这种情况下,我们知道总体参数的真实值,因此我们可以看到置信区间在许多不同样本中捕获该值的频率。图 [10.1](#fig:CIcoverage) 显示了NHANES数据集中100个样本的估计平均重量的置信区间。其中,95个获得了真实的人口平均体重,表明置信区间程序的表现,因为它应该。
![Samples were repeatedly taken from the NHANES dataset, and the 95% confidence interval of the mean was computed for each sample. Intervals shown in red did not capture the true population mean (shown as the dotted line).](../media/file55.png)
![Samples were repeatedly taken from the NHANES dataset, and the 95% confidence interval of the mean was computed for each sample. Intervals shown in red did not capture the true population mean (shown as the dotted line).](img/file55.png)
图10.1:从NHANES数据集中重复提取样本,并计算每个样本平均值的95%置信区间。以红色显示的区间没有捕捉到真实的总体平均值(如虚线所示)。
......@@ -68,7 +68,7 @@
因为标准误差随着样本量的增加而减小,所以置信区间应该随着样本量的增加而变窄,从而为我们的估计提供越来越紧的界限。图 [10.2](#fig:CISampSize) 显示了置信区间如何作为权重示例的样本大小的函数而变化的示例。从图中可以明显看出,随着样本量的增加,置信区间变得越来越窄,但样本量的增加会带来收益递减,这与置信区间项的分母与样本量的平方根成比例的事实相一致。
![An example of the effect of sample size on the width of the confidence interval for the mean.](../media/file56.png)
![An example of the effect of sample size on the width of the confidence interval for the mean.](img/file56.png)
图10.2:样本大小对均值置信区间宽度影响的例子。
......@@ -141,7 +141,7 @@
根据Cohen's d,有一个解释效果大小的常用尺度,如表 [10.1](#tab:dInterp) 所示。查看一些普遍理解的效应有助于理解这些解释。例如,参照我们上面的表格,成人身高性别差异的影响大小(d = 2.05)非常大。我们也可以通过观察NHANES数据集样本中男性和女性身高的分布来了解这一点。图 [10.3](#fig:genderHist) 显示这两种分布很好地分开,尽管仍然重叠,这突出了一个事实,即使两组之间的差异有很大的影响大小,每个组中也会有更像另一组的个体。
![Smoothed histogram plots for male and female heights in the NHANES dataset, showing clearly distinct but also clearly overlapping distributions.](../media/file57.png)
![Smoothed histogram plots for male and female heights in the NHANES dataset, showing clearly distinct but also clearly overlapping distributions.](img/file57.png)
图10.3:NHANES数据集中男性和女性身高的平滑直方图,显示了明显不同但也明显重叠的分布。
......@@ -157,7 +157,7 @@
*r* 是一个从-1到1变化的测度,其中值1代表变量之间完全正相关,0代表没有关系,-1代表完全负相关。图 [10.4](#fig:corrFig) 显示了使用随机生成数据的各种相关水平的示例。
![Examples of various levels of Pearson's r.](../media/file58.png)
![Examples of various levels of Pearson's r.](img/file58.png)
图10.4:不同等级皮尔逊风险比的例子。
......@@ -207,7 +207,7 @@
我们可以通过模拟看到这一点。首先让我们模拟一个实验,在这个实验中,我们使用标准的t检验来比较两组的平均值。我们将改变影响的大小(根据Cohen's d指定)、I型错误率和样本大小,对于其中的每一项,我们将检查显著结果(即功效)的比例是如何受到影响的。图 [10.5](#fig:plotPowerSim) 显示了功率作为这些因素的函数如何变化的示例。
![Results from power simulation, showing power as a function of sample size, with effect sizes shown as different colors, and alpha shown as line type. The standard criterion of 80 percent power is shown by the dotted black line.](../media/file59.png)
![Results from power simulation, showing power as a function of sample size, with effect sizes shown as different colors, and alpha shown as line type. The standard criterion of 80 percent power is shown by the dotted black line.](img/file59.png)
图10.5:功率模拟的结果,显示功率作为样本大小的函数,效果大小显示为不同的颜色,alpha显示为线型。80%功率的标准标准由黑色虚线表示。
......
......@@ -12,7 +12,7 @@
生成模型背后的想法是,一个*潜在的*(看不见的)过程生成我们观察到的数据,通常在这个过程中有一定的随机性。当我们从总体中抽取一个数据样本,并从样本中估计一个参数时,我们所做的事情实质上是试图学习一个潜在变量(总体均值)的值,该变量通过对观察数据(样本均值)的抽样而产生。图 [11.1](#fig:GenerativeModel) 显示了这个想法的示意图。
![A schematic of the idea of a generative model.](../media/file60.png)
![A schematic of the idea of a generative model.](img/file60.png)
图11.1:生成模型的概念示意图。
......@@ -62,7 +62,7 @@
### 11.3.1 指定在先
要使用贝叶斯定理,我们首先需要指定假设的先验概率。在这种情况下,我们不知道真实的数字,但我们可以假设它很小。根据 [FAA](https://www.faa.gov/air_traffic/by_the_numbers/media/Air_Traffic_by_the_Numbers_2018.pdf) 的数据,2017年美国共有971,595,898名航空乘客。假设这些旅行者中有一个在包里携带了爆炸物——这将给出9.71亿分之一的先验概率,这非常小!在9/11袭击后的几个月里,安全人员可能合理地持有更强的先验,所以让我们说他们的主观信念是每一百万个飞行员中有一个携带爆炸物。
要使用贝叶斯定理,我们首先需要指定假设的先验概率。在这种情况下,我们不知道真实的数字,但我们可以假设它很小。根据 [FAA](https://www.faa.gov/air_traffic/by_the_numbeimg/Air_Traffic_by_the_Numbers_2018.pdf) 的数据,2017年美国共有971,595,898名航空乘客。假设这些旅行者中有一个在包里携带了爆炸物——这将给出9.71亿分之一的先验概率,这非常小!在9/11袭击后的几个月里,安全人员可能合理地持有更强的先验,所以让我们说他们的主观信念是每一百万个飞行员中有一个携带爆炸物。
......@@ -137,7 +137,7 @@
我们可以使用二项式密度函数计算任何特定有效性参数值下观察数据的似然性。在图 [11.2](#fig:like2) 中可以看到<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><msub><mi>P</mi><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>P</mi><mi>o</mi><mi>n</mi><mi>d</mi></mrow></msub><annotation encoding="application/x-tex">P _ { respond }</annotation></semantics></math>。看这个,似乎我们观测到的数据在<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><msub><mi>P</mi><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>P</mi><mi>o</mi><mi>n</mi><mi>d</mi></mrow></msub><mo>=</mo><mn>0.7</mn></mrow><math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><msub><mi>P</mi><mi>r</mi><mi>e<mi>s<mi>P</mi><mi>o</mi><mi>n</mi><mi>d</mi></mi></mi></msub></mrow><mo>=</mo><mn>0。 而且在<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mrow><msub><mi>P</mi><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>P</mi><mi>o</mi><mi>d</mi></mrow></msub><mo>=</mo><mn>0.3 <mi>贝叶斯推理的一个基本思想是,我们应该提高我们对感兴趣的参数值的信念,与数据在这些值之下的可能性成比例,与我们在看到数据之前对参数值的信念(我们的先验知识)相平衡。</mi></mn></mrow></semantics></math></mn></semantics></math></semantics></math>
![Likelihood of each possible number of responders under several different hypotheses (p(respond)=0.5 (solid), 0.7 (dotted), 0.3 (dashed). Observed value shown in the vertical line](../media/file61.png)
![Likelihood of each possible number of responders under several different hypotheses (p(respond)=0.5 (solid), 0.7 (dotted), 0.3 (dashed). Observed value shown in the vertical line](img/file61.png)
图11.2:在几种不同的假设下,每个可能的响应者数量的可能性(p(响应)=0.5(实线),0.7(虚线),0.3(虚线)。观察值显示在垂直线中
......@@ -157,7 +157,7 @@
我们现在已经得到了计算所有可能值的后验概率分布所需的所有部分,这些值为<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><msub><mi>p</mi><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>p</mi><mi>o</mi><mi>n</mi><mi>d</mi></mrow></msub><annotation encoding="application/x-tex">p _ { respond }</annotation></semantics></math>,如图 [11.3所示](#fig:posteriorDist)
![Posterior probability distribution for the observed data plotted in solid line against uniform prior distribution (dotted line). The maximum a posteriori (MAP) value is signified by the diamond symbol.](../media/file62.png)
![Posterior probability distribution for the observed data plotted in solid line against uniform prior distribution (dotted line). The maximum a posteriori (MAP) value is signified by the diamond symbol.](img/file62.png)
图11.3:观察数据的后验概率分布,实线表示均匀先验分布(虚线)。最大后验概率(MAP)值由菱形符号表示。
......@@ -197,7 +197,7 @@
最后,重要的是要认识到,如果先验足够强,它们可以完全压倒数据。假设您有一个绝对的先验,即<math display="inline"><semantics><msub><mi>p</mi><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mi>p</mi><mi>o</mi><mi>n</mi><mi>d</mi></mrow></msub><annotation encoding="application/x-tex">p _ { respond }</annotation></semantics></math>为0.8或更大,这样您就将所有其他值的先验概率设置为零。如果我们计算后验概率会发生什么?
![A: Effects of priors on the posterior distribution. The original posterior distribution based on a flat prior is plotted in blue. The prior based on the observation of 10 responders out of 20 people is plotted in the dotted black line, and the posterior using this prior is plotted in red. B: Effects of the strength of the prior on the posterior distribution. The blue line shows the posterior obtained using the prior based on 50 heads out of 100 people. The dotted black line shows the prior based on 250 heads out of 500 flips, and the red line shows the posterior based on that prior. C: Effects of the strength of the prior on the posterior distribution. The blue line shows the posterior obtained using an absolute prior which states that p(respond) is 0.8 or greater. The prior is shown in the dotted black line.](../media/file63.png)
![A: Effects of priors on the posterior distribution. The original posterior distribution based on a flat prior is plotted in blue. The prior based on the observation of 10 responders out of 20 people is plotted in the dotted black line, and the posterior using this prior is plotted in red. B: Effects of the strength of the prior on the posterior distribution. The blue line shows the posterior obtained using the prior based on 50 heads out of 100 people. The dotted black line shows the prior based on 250 heads out of 500 flips, and the red line shows the posterior based on that prior. C: Effects of the strength of the prior on the posterior distribution. The blue line shows the posterior obtained using an absolute prior which states that p(respond) is 0.8 or greater. The prior is shown in the dotted black line.](img/file63.png)
图11.4: A:先验对后验分布的影响。基于平坦先验的原始后验分布以蓝色绘制。基于20个人中10个应答者的观察的先验以黑色虚线绘制,使用该先验的后验以红色绘制。b:先验强度对后验分布的影响。蓝线表示基于100个人中的50个人使用先验获得的后验概率。黑色虚线表示基于500次翻转中250次翻转的先验,红线表示基于该先验的后验。c:先验强度对后验分布的影响。蓝线显示使用绝对先验获得的后验概率,表明p(响应)为0.8或更大。先验以黑色虚线显示。
......@@ -243,7 +243,7 @@
首先,让我们生成一些数据,并使用零假设检验对它们进行分析(见图 [11.5](#fig:bayesTesting) )。然后,让我们进行独立样本t检验,结果显示两组之间存在显著差异:
![Box plots showing data for drug and placebo groups.](../media/file64.png)
![Box plots showing data for drug and placebo groups.](img/file64.png)
图11.5:显示药物组和安慰剂组数据的箱线图。
......@@ -364,7 +364,7 @@
| 2.5% | Zero point five four |
| 97.5% | Zero point seven three |
![Rejection sampling example.The black line shows the density of all possible values of p(respond); the blue lines show the 2.5th and 97.5th percentiles of the distribution, which represent the 95 percent credible interval for the estimate of p(respond).](../media/file65.png)
![Rejection sampling example.The black line shows the density of all possible values of p(respond); the blue lines show the 2.5th and 97.5th percentiles of the distribution, which represent the 95 percent credible interval for the estimate of p(respond).](img/file65.png)
图11.6:剔除抽样示例。黑线表示p(响应)所有可能值的密度;蓝线显示分布的2.5和97.5个百分点,代表p(响应)估计值的95%可信区间。
......
......@@ -31,7 +31,7 @@ Pearson卡方检验为我们提供了一种方法来检验一组观察计数是
此分析的卡方统计结果为0.74,这本身是不可解释的,因为它取决于不同值相加的数量。但是,我们可以利用卡方统计量是根据零假设下的特定分布分布的这一事实,这种分布称为*卡方*分布。这个分布被定义为一组标准正态随机变量的平方和;它的自由度数量等于变量相加的数量。分布的形状取决于自由度的数量。图 [12.1](#fig:chisqDist) 的左图显示了几个不同自由度的分布示例。
![Left: Examples of the chi-squared distribution for various degrees of freedom. Right: Simulation of sum of squared random normal variables. The histogram is based on the sum of squares of 50,000 sets of 8 random normal variables; the dotted line shows the values of the theoretical chi-squared distribution with 8 degrees of freedom.](../media/file66.png)
![Left: Examples of the chi-squared distribution for various degrees of freedom. Right: Simulation of sum of squared random normal variables. The histogram is based on the sum of squares of 50,000 sets of 8 random normal variables; the dotted line shows the values of the theoretical chi-squared distribution with 8 degrees of freedom.](img/file66.png)
图12.1:左图:不同自由度的卡方分布示例。右图:随机正态变量平方和的模拟。直方图基于5万组8个随机正态变量的平方和;虚线显示了具有8个自由度的理论卡方分布的值。
......
......@@ -20,7 +20,7 @@
## 13.2 收入不平等与仇恨犯罪有关吗?
![Plot of rates of hate crimes vs. Gini index.](../media/file67.png)
![Plot of rates of hate crimes vs. Gini index.](img/file67.png)
图13.1:仇恨犯罪率与基尼指数的关系图。
......@@ -83,7 +83,7 @@
我们也可以通过随机化来测试这一点,在随机化中,我们反复打乱其中一个变量的值并计算相关性,然后将我们观察到的相关值与该零分布进行比较,以确定我们观察到的值在零假设下的可能性有多大。结果如图 [13.2](#fig:shuffleCorr) 所示。使用随机化计算的p值相当类似于t检验给出的答案。
![Histogram of correlation values under the null hypothesis, obtained by shuffling values. Observed value is denoted by blue line.](../media/file68.png)
![Histogram of correlation values under the null hypothesis, obtained by shuffling values. Observed value is denoted by blue line.](img/file68.png)
图13.2:零假设下相关值的直方图,通过混排值获得。观察值用蓝线表示。
......@@ -97,7 +97,7 @@
您可能已经注意到图 [13.1](#fig:hateCrimeGini) 中有些奇怪的地方——其中一个数据点(哥伦比亚特区的数据点)似乎与其他数据点完全不同。我们称之为*异常值*,标准相关系数对异常值非常敏感。例如,在图 [13.3](#fig:outlierCorr) 中,我们可以看到一个孤立的数据点如何导致非常高的正相关值,即使其他数据点之间的实际关系完全是负的。
![An simulated example of the effects of outliers on correlation. Without the outlier the remainder of the datapoints have a perfect negative correlation, but the single outlier changes the correlation value to highly positive.](../media/file69.png)
![An simulated example of the effects of outliers on correlation. Without the outlier the remainder of the datapoints have a perfect negative correlation, but the single outlier changes the correlation value to highly positive.](img/file69.png)
图13.3:异常值对相关性影响的模拟示例。在没有异常值的情况下,其余的数据点具有完美的负相关,但是单个异常值将相关值变为高度正相关。
......@@ -143,11 +143,11 @@
然而,实际上,对完成时间和成绩的影响并不直接归因于花在学习上的时间,而是学生通过学习获得的知识量。我们通常会说知识是一个*潜在的*变量——也就是说,我们不能直接测量它,但我们可以看到它反映在我们可以测量的变量中(如分数和完成时间)。图 [13.5](#fig:latentCausalGraph) 显示了这一点。
![A graph showing causal relationships between three variables: study time, exam grades, and exam finishing time. A green arrow represents a positive relationship (i.e. more study time causes exam grades to increase), and a red arrow represents a negative relationship (i.e. more study time causes faster completion of the exam).](../media/file70.png)
![A graph showing causal relationships between three variables: study time, exam grades, and exam finishing time. A green arrow represents a positive relationship (i.e. more study time causes exam grades to increase), and a red arrow represents a negative relationship (i.e. more study time causes faster completion of the exam).](img/file70.png)
图13.4:显示三个变量之间因果关系的图表:学习时间、考试成绩和考试结束时间。绿色箭头表示正相关关系(即更多的学习时间导致考试成绩提高),红色箭头表示负相关关系(即更多的学习时间导致更快完成考试)。
![A graph showing the same causal relationships as above, but now also showing the latent variable (knowledge) using a square box.](../media/file71.png)
![A graph showing the same causal relationships as above, but now also showing the latent variable (knowledge) using a square box.](img/file71.png)
图13.5:一个图表显示了与上面相同的因果关系,但是现在也用一个方框显示了潜在变量(知识)。
......@@ -194,7 +194,7 @@
<semantics><mrow><mi>【g】</mi><mo>=</mo><mrow><munderover><mi></mi></munderover></mrow></mrow> <mrow><mi><munderover><mo><mrow><mi>【I】</mi>【t】</mrow></mo></munderover></mi></mrow></semantics>
![Lorenz curves for A) perfect equality, B) normally distributed income, and C) high inequality (equal income except for one very wealthy individual).](../media/file72.png)
![Lorenz curves for A) perfect equality, B) normally distributed income, and C) high inequality (equal income except for one very wealthy individual).](img/file72.png)
图13.6:洛伦茨曲线表示A)完全平等,B)正常分配的收入,以及C)高度不平等(除了一个非常富有的人之外,收入相等)。
......
......@@ -15,7 +15,7 @@
一般线性模型是这样一种模型,其中因变量的模型由独立变量的*线性组合*组成,每个独立变量都乘以一个权重(通常称为希腊字母β-<math display="inline"><semantics><mi>β</mi><annotation encoding="application/x-tex"></annotation></semantics></math>),该权重确定独立变量对模型预测的相对贡献。
![Relation between study time and grades](../media/file73.png)
![Relation between study time and grades](img/file73.png)
图14.1:学习时间和成绩之间的关系
......@@ -57,7 +57,7 @@
<math xmlns:epub="http://www.idpf.org/2007/ops" display="block"><semantics><mrow><mover><mi>y</mi><mo accent="true">̂</mo></mover><mo>=</mo><mi>x</mi><mo>*</mo><mover><msub><mi>β</mi><mi>x</mi></msub><mo accent="true">̂</mo></mover><mo>+</mo><mover><msub><mi>β</mi></msub><mo accent="true">̂</mo> 其中<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mover><msub><mi>β</mi><mi>x</mi></msub><mo accent="true">̂</mo></mover><annotation encoding="application/x-tex">\ hat【beta _ x】</annotation></semantics></math>是我们对斜率的估计而<math xmlns:epub="http://www.idpf.org/2007/ops" display="inline"><semantics><mover><mn><mo accent="true">̂</mo></mn></mover>【T77】 图 <a xmlns:epub="http://www.idpf.org/2007/ops" href="#fig:LinearRegression">14.2</a> 显示了该模型应用于研究时间数据的示例。</semantics></math></mover></mrow></semantics></math>
![The linear regression solution for the study time data is shown in the solid line The value of the intercept is equivalent to the predicted value of the y variable when the x variable is equal to zero; this is shown with a dotted line. The value of beta is equal to the slope of the line -- that is, how much y changes for a unit change in x. This is shown schematically in the dashed lines, which show the degree of increase in grade for a single unit increase in study time.](../media/file74.png)
![The linear regression solution for the study time data is shown in the solid line The value of the intercept is equivalent to the predicted value of the y variable when the x variable is equal to zero; this is shown with a dotted line. The value of beta is equal to the slope of the line -- that is, how much y changes for a unit change in x. This is shown schematically in the dashed lines, which show the degree of increase in grade for a single unit increase in study time.](img/file74.png)
图14.2:研究时间数据的线性回归解以实线表示。当x变量等于零时,截距值相当于y变量的预测值;这用虚线表示。β的值等于直线的斜率,即x的单位变化对应y的变化量。虚线示意性地显示了这一点,它显示了学习时间每增加一个单位,成绩增加的程度。
......@@ -204,7 +204,7 @@
## F-statistic: 10.2 on 2 and 5 DF, p-value: 0.0173
```
![The relation between study time and grade including prior experience as an additional component in the model. The solid line relates study time to grades for students who have not had prior experience, and the dashed line relates grades to study time for students with prior experience. The dotted line corresponds to the difference in means between the two groups.](../media/file75.png)
![The relation between study time and grade including prior experience as an additional component in the model. The solid line relates study time to grades for students who have not had prior experience, and the dashed line relates grades to study time for students with prior experience. The dotted line corresponds to the difference in means between the two groups.](img/file75.png)
图14.3:学习时间和年级之间的关系,包括以前的经验作为模型中的一个附加部分。实线表示没有工作经验的学生的学习时间与成绩的关系,虚线表示有工作经验的学生的成绩与学习时间的关系。虚线对应于两组之间平均值的差异。
......@@ -289,7 +289,7 @@
从这些结果中,我们看到咖啡因和焦虑都有显著的影响(我们称之为*主要影响*)以及咖啡因和焦虑之间的相互作用。图 [14.4](#fig:CaffeineAnxietyInteraction) 中的面板C显示了每组的独立回归线。
![A: The relationship between caffeine and public speaking. B: The relationship between caffeine and public speaking, with anxiety represented by the shape of the data points. C: The relationship between public speaking and caffeine, including an interaction with anxiety. This results in two lines that separately model the slope for each group (dashed for anxious, dotted for non-anxious).](../media/file76.png)
![A: The relationship between caffeine and public speaking. B: The relationship between caffeine and public speaking, with anxiety represented by the shape of the data points. C: The relationship between public speaking and caffeine, including an interaction with anxiety. This results in two lines that separately model the slope for each group (dashed for anxious, dotted for non-anxious).](img/file76.png)
图14.4: A:咖啡因和公众演讲的关系。b:咖啡因和公开演讲之间的关系,数据点的形状代表焦虑。c:公众演讲和咖啡因之间的关系,包括与焦虑的相互作用。这导致两条线分别模拟每组的斜率(虚线代表焦虑,虚线代表非焦虑)。
......@@ -350,7 +350,7 @@ p2 <- ggplot(qq_df,aes(sample=unif)) +
plot_grid(p1,p2)
```
![Q-Q plotsof normal (left) and non-normal (right) data. The line shows the point at which the x and y axes are equal.](../media/file77.png)
![Q-Q plotsof normal (left) and non-normal (right) data. The line shows the point at which the x and y axes are equal.](img/file77.png)
图14.5:正常(左)和非正常(右)数据的Q-Q图。这条线表示x轴和y轴相等的点。
......@@ -382,7 +382,7 @@ plot_grid(p1,p2)
一种被开发出来帮助解决过度拟合问题的方法被称为*交叉验证*。这种技术通常用于机器学习领域,它专注于构建能够很好地推广到新数据的模型,即使我们没有新的数据集来测试模型。交叉验证背后的想法是,我们反复拟合我们的模型,每次都留下一个数据子集,然后测试模型预测每个保留子集中的值的能力。
![A schematic of the cross-validation procedure.](../media/file78.png)
![A schematic of the cross-validation procedure.](img/file78.png)
图14.6:交叉验证程序的示意图。
......@@ -464,7 +464,7 @@ df_matrix <-
我们知道成绩数据进入了Y矩阵,但是什么进入了<math display="inline"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>矩阵呢?请记住,在我们对线性回归的最初讨论中,除了我们感兴趣的自变量之外,我们还需要添加一个常数,因此我们的<math display="inline"><semantics><mi>X</mi><annotation encoding="application/x-tex">X</annotation></semantics></math>矩阵(我们称之为*设计矩阵*)需要包括两列:一列代表研究时间变量,一列代表每个个体的相同值(我们通常用全1填充)。我们可以图形方式查看最终的设计矩阵(见图 [14.7](#fig:GLMmatrix) )。
![A depiction of the linear model for the study time data in terms of matrix algebra.](../media/file79.png)
![A depiction of the linear model for the study time data in terms of matrix algebra.](img/file79.png)
图14.7:用矩阵代数描述研究时间数据的线性模型。
......
......@@ -82,7 +82,7 @@ ttestBF(NHANES_sample$BPDiaAve, mu=80, nullInterval=c(-Inf, 80))
统计学中经常出现的一个更常见的问题是,两个不同组的均值之间是否存在差异。假设我们想知道经常吸食大麻的人是否看更多的电视,我们也可以使用NHANES数据集来询问这个问题。我们从数据集中抽取了200个样本,测试每天看电视的小时数是否与经常使用大麻有关。图 [15.1](#fig:PotTVViolin) 的左图使用小提琴图显示了这些数据。
![Left: Violin plot showing distributions of TV watching separated by regular marijuana use. Right: Violin plots showing data for each group, with a dotted line connecting the predicted values for each group, computed on the basis of the results of the linear model.. ](../media/file80.png)
![Left: Violin plot showing distributions of TV watching separated by regular marijuana use. Right: Violin plots showing data for each group, with a dotted line connecting the predicted values for each group, computed on the basis of the results of the linear model.. ](img/file80.png)
图15.1:左图:小提琴图显示了定期吸食大麻对看电视的影响。右图:显示各组数据的Violin图,虚线连接各组的预测值,根据线性模型的结果进行计算..
......@@ -185,7 +185,7 @@ t检验通常作为比较均值的专门工具,但它也可以被视为一般
在实验研究中,我们经常使用*受试者内*设计,在这种设计中,我们在多个测量值上比较同一个人。来自这种设计的测量通常被称为*重复测量*。例如,在NHANES数据集中,血压被测量三次。假设我们有兴趣测试样本中个体间第一次和第二次测量的平均收缩压是否存在差异(图 [15.2](#fig:BPfig) )。
![Left: Violin plot of systolic blood pressure on first and second recording, from NHANES. Right: Same violin plot with lines connecting the two data points for each individual.](../media/file81.png)
![Left: Violin plot of systolic blood pressure on first and second recording, from NHANES. Right: Same violin plot with lines connecting the two data points for each individual.](img/file81.png)
图15.2:左图:NHANES第一次和第二次记录的收缩压小提琴图。右图:同样的小提琴图,用线条连接每个人的两个数据点。
......@@ -209,7 +209,7 @@ t检验通常作为比较均值的专门工具,但它也可以被视为一般
在这种分析中,我们真正关心的是每个人的血压在两次测量之间是否以系统的方式发生了变化,因此另一种表示数据的方法是计算每个人在两个时间点之间的差异,然后分析这些差异分数,而不是分析个体测量。在图 [15.3](#fig:BPDiffHist) 中,我们展示了这些差异分数的直方图,蓝色线条表示平均差异。
![Histogram of difference scores between first and second BP measurement. The vertical line represents the mean difference in the sample.](../media/file82.png)
![Histogram of difference scores between first and second BP measurement. The vertical line represents the mean difference in the sample.](img/file82.png)
图15.3:第一次和第二次血压测量的差值直方图。垂直线代表样本中的平均差异。
......@@ -284,7 +284,7 @@ t检验通常作为比较均值的专门工具,但它也可以被视为一般
我们经常想要比较两个以上的平均数,以确定它们之间是否有任何不同。假设我们正在分析一项高血压治疗临床试验的数据。在这项研究中,志愿者被随机分配到三种情况中的一种:药物1、药物2或安慰剂。让我们生成一些数据并绘制它们(见图 [15.4](#fig:DrugTrial)
![Box plots showing blood pressure for three different groups in our clinical trial.](../media/file83.png)
![Box plots showing blood pressure for three different groups in our clinical trial.](img/file83.png)
图15.4:箱线图显示了我们临床试验中三个不同组的血压。
......@@ -302,7 +302,7 @@ t检验通常作为比较均值的专门工具,但它也可以被视为一般
使用ANOVA,我们希望在均值间无差异的零假设下,测试模型解释的方差是否大于我们随机预期的方差。而对于t分布,在零假设下期望值为零,但这里不是这样,因为平方和总是正数。幸运的是,有另一种理论分布描述了在零假设下平方和的比率是如何分布的:分布 *F* (见图 [15.5](#fig:FDist) )。这种分布有两个自由度,分别对应于分子(本例中为模型)和分母(本例中为误差)的自由度。
![F distributions under the null hypothesis, for different values of degrees of freedom.](../media/file84.png)
![F distributions under the null hypothesis, for different values of degrees of freedom.](img/file84.png)
图15.5:不同自由度值的零假设下的f分布。
......
......@@ -36,7 +36,7 @@
将少量变量可视化的一个有用方法是将每一对变量相对于另一个绘制成图,有时称为“矩阵散点图”;示例如图 [16.1](#fig:pairpanel) 所示。面板中的每一行/每一列指的是一个变量——在这个例子中,是我们在前面例子中的一个心理变量。图上的对角线元素以直方图的形式显示了每个变量的分布。对角线下方的元素显示了每对矩阵的散点图,上面覆盖了描述变量之间关系的回归线。对角线上方的元素显示每对变量的相关系数。当变量数量相对较少(约10或更少)时,这可能是深入了解多变量数据集的有效方法。
![Scatterplot of matrices for the nine variables in the self-control dataset. The diagonal elements in the matrix show the histogram for each of the individual variables. The lower left panels show scatterplots of the relationship between each pair of variables, and the upper right panel shows the correlation coefficient for each pair of variables.](../media/file85.png)
![Scatterplot of matrices for the nine variables in the self-control dataset. The diagonal elements in the matrix show the histogram for each of the individual variables. The lower left panels show scatterplots of the relationship between each pair of variables, and the upper right panel shows the correlation coefficient for each pair of variables.](img/file85.png)
图16.1:自身对照数据集中九个变量的矩阵散点图。矩阵中的对角线元素显示了每个变量的直方图。左下面板显示每对变量之间关系的散点图,右上面板显示每对变量的相关系数。
......@@ -48,13 +48,13 @@
在某些情况下,我们希望一次可视化大量变量之间的关系,通常侧重于相关系数。一种有用的方法是将相关值绘制成*热图*,其中热图的颜色与相关值相关。图 [16.2](#fig:hmap) 显示了一个变量相对较少的例子,使用了我们上面的心理学例子。在这种情况下,热图有助于数据的结构向我们“突出”;我们看到SSRT变量和UPPS变量之间有很强的相关性,而两组变量之间的相关性相对较小。
![Heatmap of the correlation matrix for the nine self-control variables. The brighter yellow areas in the top left and bottom right highlight the higher correlations within the two subsets of variables.](../media/file86.png)
![Heatmap of the correlation matrix for the nine self-control variables. The brighter yellow areas in the top left and bottom right highlight the higher correlations within the two subsets of variables.](img/file86.png)
图16.2:九个自控变量的相关矩阵热图。左上方和右下方较亮的黄色区域突出显示了这两个变量子集内较高的相关性。
热图对于可视化大量变量之间的相关性变得特别有用。我们可以用脑成像数据作为例子。神经科学研究人员通常使用功能性磁共振成像(fMRI)从大脑中的大量位置收集关于大脑功能的数据,然后评估这些位置之间的相关性,以测量这些区域之间的“功能连接性”。例如,图 [16.3](#fig:parcelheatmap) 显示了一个大型相关矩阵的热图,该热图基于单个个体(你的真实)大脑中300多个区域的活动。只需查看热图,数据中清晰结构的存在就会显现出来。具体来说,我们看到有大量大脑区域的活动彼此高度相关(在沿着相关矩阵对角线的大黄色块中可见),而这些块也与其他块强烈负相关(在对角线外的大蓝色块中可见)。热图是一个强大的工具,可以轻松地可视化大型数据矩阵。
![A heatmap showing the correlation coefficient of brain activity between 316 regions in the left hemisphere of a single individiual. Cells in yellow reflect strong positive correlation, whereas cells in blue reflect strong negative correlation. The large blocks of positive correlation along the diagonal of the matrix correspond to the major connected networks in the brain](../media/file87.png)
![A heatmap showing the correlation coefficient of brain activity between 316 regions in the left hemisphere of a single individiual. Cells in yellow reflect strong positive correlation, whereas cells in blue reflect strong negative correlation. The large blocks of positive correlation along the diagonal of the matrix correspond to the major connected networks in the brain](img/file87.png)
图16.3:显示一个人左半球316个区域之间大脑活动相关系数的热图。黄色单元反映了强正相关,而蓝色单元反映了强负相关。沿着矩阵对角线的大块正相关对应于大脑中的主要连接网络
......@@ -70,7 +70,7 @@
一种常用的聚类距离度量是*欧几里德距离*,它基本上是连接两个数据点的线的长度。图 [16.4](#fig:eucdist) 显示了一个有两个数据点和两个维度(X和Y)的数据集的例子。这两点之间的欧几里得距离是连接空间中的点的虚线的长度。
![A depiction of the Euclidean distance between two points, (1,2) and (4,3). The two points differ by 3 along the X axis and by 1 along the Y axis.](../media/file88.png)
![A depiction of the Euclidean distance between two points, (1,2) and (4,3). The two points differ by 3 along the X axis and by 1 along the Y axis.](img/file88.png)
图16.4:两点(1,2)和(4,3)之间欧几里得距离的描述。这两个点沿X轴相差3 °,沿Y轴相差1°。
......@@ -96,7 +96,7 @@
在选择了我们希望找到的聚类数( *K* )之后,我们必须得出K个位置,这将是我们对聚类中心的开始猜测(因为我们最初不知道中心在哪里)。一种简单的开始方式是随机选择K个实际数据点,并使用它们作为我们的起点,它们被称为*质心*。然后,我们计算每个数据点到每个质心的欧几里德距离,并根据每个点最近的质心将其分配到一个聚类中。使用这些新的聚类分配,我们通过平均分配给该聚类的所有点的位置来重新计算每个聚类的质心。然后重复这一过程,直到找到稳定的解决方案;我们称之为*迭代*过程,因为它会迭代直到答案不变,或者直到达到某种其他限制,比如最大可能迭代次数。
![A two-dimensional depiction of clustering on the latitude and longitude of countries across the world. The square black symbols show the starting centroids for each cluster, and the lines show the movement of the centroid for that cluster across the iterations of the algorithm.](../media/file89.png)
![A two-dimensional depiction of clustering on the latitude and longitude of countries across the world. The square black symbols show the starting centroids for each cluster, and the lines show the movement of the centroid for that cluster across the iterations of the algorithm.](img/file89.png)
图16.5:世界各国纬度和经度聚类的二维描述。黑色方形符号显示每个聚类的起始质心,线条显示该聚类的质心在算法迭代过程中的移动。
......@@ -122,7 +122,7 @@
虽然在这个例子中我们知道实际的聚类(即世界的大陆),但一般来说,我们实际上不知道无监督学习问题的基本事实,所以我们只能相信聚类方法已经在数据中找到了有用的结构。然而,关于K-means聚类和迭代过程的一个要点是,它们不能保证每次运行时都给出相同的答案。使用随机数来确定起点意味着起点每次都可能不同,并且根据数据,这有时会导致找到不同的解决方案。对于这个例子,K-means聚类有时会找到包含北美和南美的单个聚类,有时会找到两个聚类(就像这里使用的随机种子的特定选择一样)。每当使用涉及迭代解决方案的方法时,使用不同的随机种子多次重新运行该方法是很重要的,以确保运行之间的答案不会相差太大。如果是这样,那么我们应该避免根据不稳定的结果做出强有力的结论。事实上,在更普遍的聚类结果的基础上避免强有力的结论可能是一个好主意;它们主要用于直观地了解数据集中可能存在的结构。
![A visualization of the clustering results from 10 runs of the K-means clustering algorithm with K=3\. Each row in the figure represents a different run of the clustering algorithm (with different random starting points), and variables sharing the same color are members of the same cluster.](../media/file90.png)
![A visualization of the clustering results from 10 runs of the K-means clustering algorithm with K=3\. Each row in the figure represents a different run of the clustering algorithm (with different random starting points), and variables sharing the same color are members of the same cluster.](img/file90.png)
图16.6:K = 3的K均值聚类算法的10次运行的聚类结果的可视化。图中的每一行代表聚类算法的不同运行(具有不同的随机起点),共享相同颜色的变量是同一聚类的成员。
......@@ -138,7 +138,7 @@
最常用的层次聚类过程被称为*凝聚聚类*。该过程首先将每个数据点视为其自己的聚类,然后通过组合两个聚类之间距离最小的两个聚类来逐步创建新的聚类。它继续这样做,直到只剩下一个集群。这需要计算集群之间的距离,有许多方法可以做到这一点;在本例中,我们将使用*平均关联*方法,该方法简单地取两个聚类中每个数据点之间所有距离的平均值。例如,我们将检查上述自控变量之间的关系。
![A dendrogram depicting the relative similarity of the nine self-control variables. The three colored vertical lines represent three different cutoffs, resulting in either two (blue line), three (green line), or four (red line) clusters.](../media/file91.png)
![A dendrogram depicting the relative similarity of the nine self-control variables. The three colored vertical lines represent three different cutoffs, resulting in either two (blue line), three (green line), or four (red line) clusters.](img/file91.png)
图16.7:描述九个自控变量相对相似性的树状图。三条彩色垂直线代表三个不同的截止点,产生两个(蓝线)、三个(绿线)或四个(红线)聚类。
......@@ -168,13 +168,13 @@
在我们的二维例子中,我们可以计算主成分,并将它们绘制在数据上(图 [16.8](#fig:pcaPlot) )。我们看到的是,第一个主成分(显示为绿色)遵循最大方差的方向。这条线与线性回归线相似,但不完全相同;当线性回归解决方案最小化在相同X值的每个数据点和回归线之间的距离(即垂直距离)时,主成分最小化数据点和表示该成分的线之间的欧几里德距离(即垂直于该成分的距离)。第二个分量指向与第一个分量垂直的方向(相当于不相关)。
![A plot of synthetic data, with the first principal component plotted in green and the second in red.](../media/file92.png)
![A plot of synthetic data, with the first principal component plotted in green and the second in red.](img/file92.png)
图16.8:合成数据图,第一个主成分标为绿色,第二个标为红色。
通常使用主成分分析来降低更复杂数据集的维数。例如,假设我们想知道早期数据集中所有四个停止信号任务变量的表现是否与五个冲动性调查变量相关。我们可以分别对这些数据集执行PCA,并检查数据中有多少方差是由第一主成分解释的,这将作为我们对数据的总结。
![A plot of the variance accounted for (or *scree plot*) for PCA applied separately to the response inhibition and impulsivity variables from the Eisenberg dataset.](../media/file93.png)
![A plot of the variance accounted for (or *scree plot*) for PCA applied separately to the response inhibition and impulsivity variables from the Eisenberg dataset.](img/file93.png)
图16.9:五氯苯甲醚的方差图(或 *scree图*)分别应用于艾森伯格数据集的反应抑制和冲动性变量。
......@@ -196,11 +196,11 @@
我们也可以一次对所有这些变量进行主成分分析。查看图 [16.7](#fig:dendro) 中的方差图(也称为*scree图),我们可以看到前两个分量占数据中方差的很大一部分。然后,我们可以查看这两个组件上每个单独变量的负载,以了解每个特定变量如何与不同的组件相关联。
![Plot of variance accounted for by PCA components computed on the full set of self-control variables.](../media/file94.png)
![Plot of variance accounted for by PCA components computed on the full set of self-control variables.](img/file94.png)
(#fig:imp_pc_scree)根据全套自控变量计算的PCA成分的方差图。
![Plot of variable loadings in PCA solution including all self-control variables. Each variable is shown in terms of its loadings on each of the two components; reflected in the two rows respectively.](../media/file95.png)
![Plot of variable loadings in PCA solution including all self-control variables. Each variable is shown in terms of its loadings on each of the two components; reflected in the two rows respectively.](img/file95.png)
图16.10:包含所有自控变量的PCA溶液中的可变负荷图。每个变量都以其在两个分量上的载荷来表示;分别反映在两排。
......@@ -220,7 +220,7 @@
我们可以通过显示与所有这些变量相关的关联矩阵的热图来进一步检查数据(图 [16.7](#fig:dendro) )。我们由此看到,有三组变量对应我们的三个潜变量,这是理所应当的。
![A heatmap showing the correlations between the variables generated from the three underlying latent variables.](../media/file96.png)
![A heatmap showing the correlations between the variables generated from the three underlying latent variables.](img/file96.png)
(#fig:efa_cor_hmap)热图显示了从三个潜在变量生成的变量之间的相关性。
......@@ -259,7 +259,7 @@
我们还可以检查参数估计,以查看模型是否恰当地识别了数据中的结构。通常将其绘制成图表,从潜在变量(表示为椭圆)指向观察变量(表示为矩形),其中箭头表示潜在变量上观察变量的实际负载;这种图形通常被称为*路径图*,因为它反映了与变量相关的路径。如图 [16.11](#fig:faDiagram) 所示。在这种情况下,EFA程序正确地识别了数据中存在的结构,既识别了哪些观察变量与每个潜在变量相关,又识别了潜在变量之间的相关性。
![Path diagram for the exploratory factor analysis model.](../media/file97.png)
![Path diagram for the exploratory factor analysis model.](img/file97.png)
图16.11:探索性因素分析模型的路径图。
......@@ -273,13 +273,13 @@
有人可能会认为,我们可以简单地看看模型的拟合程度,然后挑选出最拟合的因素数量,但这是行不通的,因为更复杂的模型总是会更好地拟合数据(正如我们在前面关于过度拟合的讨论中看到的)。出于这个原因,我们需要使用一个模型拟合的度量标准,它对模型中的参数数量进行惩罚。出于这个例子的目的,我们将选择一种用于量化模型拟合的常用方法,它被称为*样本大小调整贝叶斯信息标准*(或 *SABIC* )。这种方法量化了模型与数据的拟合程度,同时还考虑了模型中的参数数量(在这种情况下与因子数量相关)以及样本大小。虽然SABIC的绝对值是不可解释的,但当使用相同的数据和相同类型的模型时,我们可以使用SABIC来比较模型,以确定哪个模型最适合该数据。关于SABIC和类似的其他指标(被称为*信息标准*)需要知道的一件重要事情是,较低的值代表模型更好的拟合,因此在这种情况下,我们希望找到具有最低SABIC的因子的数量。在图 [16.12](#fig:sabicPlot) 中,我们看到具有最低SABIC的模型有三个因子,这表明这种方法能够准确地确定用于生成数据的因子的数量。
![Plot of SABIC for varying numbers of factors.](../media/file98.png)
![Plot of SABIC for varying numbers of factors.](img/file98.png)
图16.12:不同因素的SABIC图。
现在,让我们看看当我们将该模型应用于来自Eisenberg等人的数据集的真实数据时会发生什么,该数据集包含在上述示例中模拟的所有八个变量的测量值。对于这些真实数据,具有三个因素的模型也具有最低的SABIC。
![Path diagram for the three-factor model on the Eisenberg et al. data.](../media/file99.png)
![Path diagram for the three-factor model on the Eisenberg et al. data.](img/file99.png)
图16.13:艾森伯格等人数据的三因素模型的路径图。
......
......@@ -40,7 +40,7 @@
### 17.1.3 3:准备用于分析的数据
![Box plots for each condition, with the 50th percentile (i.e the median) shown as a black line for each group.](../media/file100.png)
![Box plots for each condition, with the 50th percentile (i.e the median) shown as a black line for each group.](img/file100.png)
图17.1:每种情况下的箱线图,第50个百分位数(即中位数)显示为每组的黑线。
......@@ -112,13 +112,13 @@
我们要做的第一件事是评论这个模型,以确保它是合适的。我们可以做的一件事是查看模型的残差。在图 [17.2](#fig:residualPlot) 中,我们绘制了按饮食分组的每个人的残差。不同条件下的残差分布没有明显的差异,我们可以继续分析。
![Distribution of residuals for for each condition](../media/file101.png)
![Distribution of residuals for for each condition](img/file101.png)
图17.2:每种条件下的残差分布
我们应用于线性模型的统计检验的另一个重要假设是模型的残差是正态分布的。线性模型要求*数据*呈正态分布,这是一种常见的误解,但事实并非如此;正确统计的唯一要求是残差呈正态分布。图 [17.3](#fig:diagnosticQQPlot) 的右侧面板显示了Q-Q(分位数-分位数)图,该图根据残差在正态分布中的分位数,绘制了残差与其期望值的关系。如果残差呈正态分布,那么数据点应该沿着虚线分布,在这种情况下,它看起来很好,除了在底部很明显的几个异常值,因为该模型对违反正态分布的情况也相对稳健,这些异常值相当小,我们将继续使用结果。
![Q-Q plot of actual residual values against theoretical residual values](../media/file102.png)
![Q-Q plot of actual residual values against theoretical residual values](img/file102.png)
图17.3:实际残差值与理论残差值的Q-Q图
......
......@@ -69,7 +69,7 @@ PPV的定义是:
我们可以对此进行模拟,以显示PPV如何与统计功效相关,作为假设为真的先验概率的函数(见图 [18.1](#fig:PPVsim) )
![A simulation of posterior predictive value as a function of statistical power (plotted on the x axis) and prior probability of the hypothesis being true (plotted as separate lines).](../media/file103.png)
![A simulation of posterior predictive value as a function of statistical power (plotted on the x axis) and prior probability of the hypothesis being true (plotted as separate lines).](img/file103.png)
图18.1:后验预测值作为统计功效(绘制在x轴上)和假设为真的先验概率(绘制为单独的线条)的函数的模拟。
......@@ -87,7 +87,7 @@ Jonathan Schoenfeld和John Ioannidis在一篇题为“我们吃的所有东西
我们可以对此进行模拟,以了解显著结果的估计效应大小与实际潜在效应大小之间的关系。让我们生成真实效应大小为d = 0.2的数据,并估计那些检测到显著效应的结果的效应大小。图 [18.2](#fig:CurseSim) 的左图显示,当功率较低时,与实际效果大小相比,显著结果的估计效果大小可能被大大夸大。
![Left: A simulation of the winner's curse as a function of statistical power (x axis). The solid line shows the estimated effect size, and the dotted line shows the actual effect size. Right: A histogram showing effect size estimates for a number of samples from a dataset, with significant results shown in blue and non-significant results in red. ](../media/file104.png)
![Left: A simulation of the winner's curse as a function of statistical power (x axis). The solid line shows the estimated effect size, and the dotted line shows the actual effect size. Right: A histogram showing effect size estimates for a number of samples from a dataset, with significant results shown in blue and non-significant results in red. ](img/file104.png)
图18.2:左图:作为统计能力(x轴)函数的赢家诅咒的模拟。实线表示估计的效果大小,虚线表示实际的效果大小。右图:一个直方图,显示了数据集内多个样本的效应大小估计值,显著结果显示为蓝色,不显著结果显示为红色。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册