Chapter page 5 / 381 Hello data
English

1  Hello data

Scientists seek to answer questions using rigorous methods and careful observations. These observations – collected from the likes of field notes, surveys, and experiments – form the backbone of a statistical investigation and are called data. Statistics is the study of how best to collect, analyze, and draw conclusions from data. In this first chapter, we focus on both the properties of data and on the collection of data.

1.1 Case study: Using stents to prevent strokes

In this section we introduce a classic challenge in statistics: evaluating the efficacy of a medical treatment. Terms in this section, and indeed much of this chapter, will all be revisited later in the text. The plan for now is simply to get a sense of the role statistics can play in practice.

An experiment is designed to study the effectiveness of stents in treating patients at risk of stroke (Chimowitz et al. 2011). Stents are small mesh tubes that are placed inside narrow or weak arteries to assist in patient recovery after cardiac events and reduce the risk of an additional heart attack or death.

Many doctors have hoped that there would be similar benefits for patients at risk of stroke. We start by writing the principal question the researchers hope to answer:

Does the use of stents reduce the risk of stroke?

The researchers who asked this question conducted an experiment with 451 at-risk patients. Each volunteer patient was randomly assigned to one of two groups:

  • Treatment group. Patients in the treatment group received a stent and medical management. The medical management included medications, management of risk factors, and help in lifestyle modification.
  • Control group. Patients in the control group received the same medical management as the treatment group, but they did not receive stents.

Researchers randomly assigned 224 patients to the treatment group and 227 to the control group. In this study, the control group provides a reference point against which we can measure the medical impact of stents in the treatment group.

Researchers studied the effect of stents at two time points: 30 days after enrollment and 365 days after enrollment. The results of 5 patients are summarized in Table 1.1. Patient outcomes are recorded as stroke or no event, representing whether the patient had a stroke during that time period.

The stent30 data and stent365 data can be found in the openintro R package.

Table 1.1: Results for five patients from the stent study.
patient group 30 days 365 days
1 treatment no event no event
2 treatment stroke stroke
3 treatment no event no event
4 treatment no event no event
5 control no event no event

It would be difficult to answer a question on the impact of stents on the occurrence of strokes for all study patients using these individual observations. This question is better addressed by performing a statistical data analysis of all observations. Table 1.2 summarizes the raw data in a more helpful way. In this table, we can quickly see what happened over the entire study. For instance, to identify the number of patients in the treatment group who had a stroke within 30 days after the treatment, we look in the leftmost column (30 days), at the intersection of treatment and stroke: 33. To identify the number of control patients who did not have a stroke after 365 days after receiving treatment, we look at the rightmost column (365 days), at the intersection of control and no event: 199.

Table 1.2: Descriptive statistics for the stent study.
30 days
365 days
Group Stroke No event Stroke No event
Control 13 214 28 199
Treatment 33 191 45 179
Total 46 405 73 378

Of the 224 patients in the treatment group, 45 had a stroke by the end of the first year. Using these two numbers, compute the proportion of patients in the treatment group who had a stroke by the end of their first year. (Note: answers to all Guided Practice exercises are provided in footnotes!)1

We can compute summary statistics from the table to give us a better idea of how the impact of the stent treatment differed between the two groups. A summary statistic is a single number summarizing data from a sample. For instance, the primary results of the study after 1 year could be described by two summary statistics: the proportion of people who had a stroke in the treatment and control groups.

  • Proportion who had a stroke in the treatment (stent) group: \(45/224 = 0.20 = 20\%.\)
  • Proportion who had a stroke in the control group: \(28/227 = 0.12 = 12\%.\)

These two summary statistics are useful in looking for differences in the groups, and we are in for a surprise: an additional 8% of patients in the treatment group had a stroke! This is important for two reasons. First, it is contrary to what doctors expected, which was that stents would reduce the rate of strokes. Second, it leads to a statistical question: do the data show a “real” difference between the groups?

This second question is subtle. Suppose you flip a coin 100 times. While the chance a coin lands heads in any given coin flip is 50%, we probably won’t observe exactly 50 heads. This type of variation is part of almost any type of data generating process. It is possible that the 8% difference in the stent study is due to this natural variation. However, the larger the difference we observe (for a particular sample size), the less believable it is that the difference is due to chance. So, what we are really asking is the following: if in fact stents have no effect, how likely is it that we observe such a large difference?

While we do not yet have statistical tools to fully address this question on our own, we can comprehend the conclusions of the published analysis: there was compelling evidence of harm by stents in this study of stroke patients.

Be careful: Do not generalize the results of this study to all patients and all stents. This study looked at patients with very specific characteristics who volunteered to be a part of this study and who may not be representative of all stroke patients. In addition, there are many types of stents, and this study only considered the self-expanding Wingspan stent (Boston Scientific). However, this study does leave us with an important lesson: we should keep our eyes open for surprises.

1.2 Data basics

Effective presentation and description of data is a first step in most analyses. This section introduces one structure for organizing data as well as some terminology that will be used throughout this book.

1.2.1 Observations, variables, and data matrices

Table 1.3 displays six rows of a dataset for 50 randomly sampled loans offered through Lending Club, which is a peer-to-peer lending company. This dataset will be referred to as loan50.

The loan50 data can be found in the openintro R package.

Each row in the table represents a single loan. The formal name for a row is a case or observation or unit of observation. The columns represent characteristics of each loan, where each column is referred to as a variable. For example, the first row represents a loan of $22,000 with an interest rate of 10.90%, where the borrower is based in New Jersey (NJ) and has an income of $59,000.

What is the grade of the first loan in Table 1.3? And what is the home ownership status of the borrower for that first loan? Reminder: for these Guided Practice questions, you can check your answer in the footnote.2

In practice, it is especially important to ask clarifying questions to ensure important aspects of the data are understood. For instance, it is always important to be sure we know what each variable means and its units of measurement. Descriptions of the variables in the loan50 dataset are given in Table 1.4.

Table 1.3: Six observations from the loan50 dataset.
loan_amount interest_rate term grade state total_income homeownership
1 22,000 10.90 60 B NJ 59,000 rent
2 6,000 9.92 36 B CA 60,000 rent
3 25,000 26.30 36 E SC 75,000 mortgage
4 6,000 9.92 36 B CA 75,000 rent
5 25,000 9.43 60 B OH 254,000 mortgage
6 6,400 9.92 36 B IN 67,000 mortgage
Table 1.4: Variables and their descriptions for the loan50 dataset.
Variable Description
loan_amount Amount of the loan received, in US dollars.
interest_rate Interest rate on the loan, in an annual percentage.
term The length of the loan, which is always set as a whole number of months.
grade Loan grade, which takes a values A through G and represents the quality of the loan and its likelihood of being repaid.
state US state where the borrower resides.
total_income Borrower's total income, including any second income, in US dollars.
homeownership Indicates whether the person owns, owns but has a mortgage, or rents.

The data in Table 1.3 represent a data frame, which is a convenient and common way to organize data, especially if collecting data in a spreadsheet. A data frame where each row is a unique case (observational unit), each column is a variable, and each cell is a single value is commonly referred to as tidy data (Wickham 2014).

When recording data, use a tidy data frame unless you have a very good reason to use a different structure. This structure allows new cases to be added as rows or new variables as new columns and facilitates visualization, summarization, and other statistical analyses.

The grades for assignments, quizzes, and exams in a course are often recorded in a gradebook that takes the form of a data frame. How might you organize a course’s grade data using a data frame? Describe the observational units and variables.3

We consider data for 3,142 counties in the United States, which includes the name of each county, the state where it resides, its population in 2017, the population change from 2010 to 2017, poverty rate, and nine additional characteristics. How might these data be organized in a data frame?4

The data described in the Guided Practice above represents the county dataset, which is shown as a data frame in Table 1.5. The variables as well as the variables in the dataset that did not fit in Table 1.5 are described in Table 1.6.

Table 1.5: Six observations and six variables from the county dataset.
name state pop2017 pop_change unemployment_rate median_edu
Autauga County Alabama 55,504 1.48 3.86 some_college
Baldwin County Alabama 212,628 9.19 3.99 some_college
Barbour County Alabama 25,270 -6.22 5.90 hs_diploma
Bibb County Alabama 22,668 0.73 4.39 hs_diploma
Blount County Alabama 58,013 0.68 4.02 hs_diploma
Bullock County Alabama 10,309 -2.28 4.93 hs_diploma
Table 1.6: Variables and their descriptions for the county dataset.
Variable Description
name Name of county.
state Name of state.
pop2000 Population in 2000.
pop2010 Population in 2010.
pop2017 Population in 2017.
pop_change Population change from 2010 to 2017 (in percent).
poverty Percent of population in poverty in 2017.
homeownership Homeownership rate, 2006-2010.
multi_unit Multi-unit rate: percent of housing units that are in multi-unit structures, 2006-2010.
unemployment_rate Unemployment rate in 2017.
metro Whether the county contains a metropolitan area, taking one of the values yes or no.
median_edu Median education level (2013-2017), taking one of the values below_hs, hs_diploma, some_college, or bachelors.
per_capita_income Per capita (per person) income (2013-2017).
median_hh_income Median household income.
smoking_ban Describes the type of county-level smoking ban in place in 2010, taking one of the values none, partial, or comprehensive.

The county data can be found in the usdata R package.

1.2.2 Types of variables

Examine the unemployment_rate, pop2017, state, and median_edu variables in the county dataset. Each of these variables is inherently different from the other three, yet some share certain characteristics.

First consider unemployment_rate, which is said to be a numerical variable since it can take a wide range of numerical values, and it is sensible to add, subtract, or take averages with those values. On the other hand, we would not classify a variable reporting telephone area codes as numerical since the average, sum, and difference of area codes does not have any clear meaning. Instead, we would consider area codes as a categorical variable.

The pop2017 variable is also numerical, although it seems to be a little different than unemployment_rate. This variable of the population count can only take whole non-negative numbers (0, 1, 2, …). For this reason, the population variable is said to be discrete since it can only take numerical values with jumps. On the other hand, the unemployment rate variable is said to be continuous.

The variable state can take up to 51 values after accounting for Washington, DC: Alabama, Alaska, …, and Wyoming. Because the responses themselves are categories, state is called a categorical variable, and the possible values (states) are called the variable’s levels (e.g., District of Columbia, Alabama, Alaska, etc.) .

Finally, consider the median_edu variable, which describes the median education level of county residents and takes values below_hs, hs_diploma, some_college, or bachelors in each county. This variable seems to be a hybrid: it is a categorical variable, but the levels have a natural ordering. A variable with these properties is called an ordinal variable, while a regular categorical variable without this type of special ordering is called a nominal variable. To simplify analyses, any categorical variable in this book will be treated as a nominal (unordered) categorical variable (see Figure 1.1).

Types of variables are broken down into numerical (which can be discrete or continuous) and categorical (which can be ordinal or nominal).
Figure 1.1: Breakdown of variables into their respective types.

Data were collected about students in a statistics course. Three variables were recorded for each student: number of siblings, student height, and whether the student had previously taken a statistics course. Classify each of the variables as continuous numerical, discrete numerical, or categorical.


The number of siblings and student height represent numerical variables. Because the number of siblings is a count, it is discrete. Height varies continuously, so it is a continuous numerical variable. The last variable classifies students into two categories – those who have and those who have not taken a statistics course – which makes this variable categorical.

An experiment is evaluating the effectiveness of a new drug in treating migraines. A group variable is used to indicate the experiment group for each patient: treatment or control. The num_migraines variable represents the number of migraines the patient experienced during a 3-month period. Classify each variable as either numerical or categorical?5

1.2.3 Relationships between variables

Many analyses are motivated by a researcher looking for a relationship between two or more variables. A social scientist may like to answer some of the following questions:

Does a higher-than-average increase in county population tend to correspond to counties with higher or lower median household incomes?

If homeownership in one county is lower than the national average, will the percent of housing units that are in multi-unit structures in that county tend to be above or below the national average?

How much can the median education level explain the median household income for counties in the US?

To answer these questions, data must be collected, such as the county dataset shown in Table 1.5. Examining summary statistics can provide numerical insights about the specifics of each of these questions. Alternatively, graphs can be used to visually explore the data, potentially providing more insight than a summary statistic.

Scatterplots are one type of graph used to study the relationship between two numerical variables. Figure 1.2 displays the relationship between the variables homeownership and multi_unit, which is the percent of housing units that are in multi-unit structures (e.g., apartments, condos). Each point on the plot represents a single county. For instance, the highlighted dot corresponds to County 413 in the county dataset: Chattahoochee County, Georgia, which has 39.4% of housing units that are in multi-unit structures and a homeownership rate of 31.3%. The scatterplot suggests a relationship between the two variables: counties with a higher rate of housing units that are in multi-unit structures tend to have lower homeownership rates. We might brainstorm as to why this relationship exists and investigate each idea to determine which are the most reasonable explanations.

A scatterplot of homeownership (on the y-axis) versus the percent of housing units that are in multi-unit structures (on the x-axis) for US counties. The observation from Chattahoochee County, Georgia is highlighted as having a multi-unit rate of 39.4% and a homeownership rate of 31.3%
Figure 1.2: A scatterplot of homeownership versus the percent of housing units that are in multi-unit structures for US counties. The highlighted dot represents Chattahoochee County, Georgia, which has a multi-unit rate of 39.4% and a homeownership rate of 31.3%.

The multi-unit and homeownership rates are said to be associated because the plot shows a discernible pattern. When two variables show some connection with one another, they are called associated variables.

Examine the variables in the loan50 dataset, which are described in Table 1.4. Create two questions about possible relationships between variables in loan50 that are of interest to you.6

This example examines the relationship between the percent change in population from 2010 to 2017 and median household income for counties, which is visualized as a scatterplot in Figure 1.3. Are these variables associated?


The larger the median household income for a county, the higher the population growth observed for the county. While it isn’t true that every county with a higher median household income has a higher population growth, the trend in the plot is evident. Since there is some relationship between the variables, they are associated.

A scatterplot showing population change (on the y-axis) against median household income (on the x-axis). Owsley County of Kentucky is highlighted, which lost 3.63% of its population from 2010 to 2017 and had median household income of $22,736.
Figure 1.3: A scatterplot showing population change against median household income. Owsley County of Kentucky is highlighted, which lost 3.63% of its population from 2010 to 2017 and had median household income of $22,736.

Because there is a downward trend in Figure 1.2 – counties with more housing units that are in multi-unit structures are associated with lower homeownership – these variables are said to be negatively associated. A positive association is shown in the relationship between the median_hh_income and pop_change variables in Figure 1.3, where counties with higher median household income tend to have higher rates of population growth.

If two variables are not associated, then they are said to be independent. That is, two variables are independent if there is no evident relationship between the two.

Associated or independent, not both.

A pair of variables are either related in some way (associated) or not (independent). No pair of variables is both associated and independent.

1.2.4 Explanatory and response variables

When we ask questions about the relationship between two variables, we sometimes also want to determine if the change in one variable causes a change in the other. Consider the following rephrasing of an earlier question about the county dataset:

If there is an increase in the median household income in a county, does this drive an increase in its population?

In this question, we are asking whether one variable affects another. If this is our underlying belief, then median household income is the explanatory variable, and the population change is the response variable in the hypothesized relationship.7

Explanatory and response variables.

When we suspect one variable might causally affect another, we label the first variable the explanatory variable and the second the response variable. We also use the terms explanatory and response to describe variables where the response might be predicted using the explanatory even if there is no causal relationship.

explanatory variable \(\rightarrow\) might affect \(\rightarrow\) response variable


For many pairs of variables, there is no hypothesized relationship, and these labels would not be applied to either variable in such cases.

Bear in mind that the act of labeling the variables in this way does nothing to guarantee that a causal relationship exists. A formal evaluation to check whether one variable causes a change in another requires an experiment.

1.2.5 Observational studies and experiments

There are two primary types of data collection: experiments and observational studies.

When researchers want to evaluate the effect of particular traits, treatments, or conditions, they conduct an experiment. For instance, we may suspect drinking a high-calorie energy drink will improve performance in a race. To check if there really is a causal relationship between the explanatory variable (whether the runner drank an energy drink or not) and the response variable (the race time), researchers identify a sample of individuals and split them into groups. The individuals in each group are assigned a treatment. When individuals are randomly assigned to a group, the experiment is called a randomized experiment. Random assignment organizes the participants in a study into groups that are roughly equal on all aspects, thus allowing us to control for any confounding variables that might affect the outcome (e.g., fitness level, racing experience, etc.). (See Section 2.2.1 for more information on confounding variables.) For example, each runner in the experiment could be randomly assigned, perhaps by flipping a coin, into one of two groups: the first group receives a placebo (fake treatment, in this case a no-calorie drink) and the second group receives the high-calorie energy drink. See the case study in Section 1.1 for another example of an experiment, though that study did not employ a placebo.

Researchers perform an observational study when they collect data in a way that does not directly interfere with how the data arise. For instance, researchers may collect information via surveys, review medical or company records, or follow a cohort of many similar individuals to form hypotheses about why certain diseases might develop. In each of these situations, researchers merely observe the data that arise. In general, observational studies can provide evidence of a naturally occurring association between variables, but they cannot by themselves show a causal connection as they do not offer a mechanism for controlling for confounding variables. (See Section 2.2.1 for more information on confounding variables.)

Association \(\neq\) Causation.

In general, association does not imply causation. An advantage of a randomized experiment is that it is easier to establish causal relationships with such a study. The main reason for this is that observational studies do not control for confounding variables, and hence establishing causal relationships with observational studies requires advanced statistical methods (that are beyond the scope of this book). We revisit ideas of confounding when we discuss experiments in Section 2.2.1.

1.3 Chapter review

1.3.1 Summary

This chapter introduced you to the world of data. Data can be organized in many ways but tidy data, where each row represents an observation and each column represents a variable, lends itself most easily to statistical analysis. Many of the ideas from this chapter will be revisited as we move on to doing end-to-end data analyses. In the next chapter you’re going to learn about how we can design studies to collect the data we need to make conclusions with the desired scope of inference.

1.3.2 Terms

The terms introduced in this chapter are presented in Table 1.7. If you’re not sure what some of these terms mean, we recommend you go back in the text and review their definitions. You should be able to easily spot them as bolded text.

Table 1.7: Terms introduced in this chapter.
associated experiment ordinal
case explanatory variable placebo
categorical independent positive association
cohort level randomized experiment
continuous negative association response variable
data nominal summary statistic
data frame numerical tidy data
dependent observation unit of observation
discrete observational study variable

1.4 Exercises

Answers to odd-numbered exercises can be found in Appendix A.1.

  1. Marvel Cinematic Universe films. The data frame below contains information on Marvel Cinematic Universe films through the Infinity saga (a movie storyline spanning from Ironman in 2008 to Endgame in 2019). Box office totals are given in millions of US Dollars. How many observations and how many variables does this data frame have?8

    Length
    Gross
    Title Hrs Mins Release Date Opening Wknd US US World
    1 Iron Man 2 6 5/2/2008 98.62 319.03 585.8
    2 The Incredible Hulk 1 52 6/12/2008 55.41 134.81 264.77
    3 Iron Man 2 2 4 5/7/2010 128.12 312.43 623.93
    4 Thor 1 55 5/6/2011 65.72 181.03 449.33
    5 Captain America: The First Avenger 2 4 7/22/2011 65.06 176.65 370.57
    ... ... ... ... ... ... ... ...
    23 Spiderman: Far from Home 2 9 7/2/2019 92.58 390.53 1131.93
  1. Cherry Blossom Run. The data frame below contains information on runners in the 2017 Cherry Blossom Run, which is an annual road race that takes place in Washington, DC. Most runners participate in a 10-mile run while a smaller fraction take part in a 5k run or walk. How many observations and how many variables does this data frame have?9

    Time
    Bib Name Sex Age City / Country Net Clock Pace Event
    1 6 Hiwot G. F 21 Ethiopia 3217 3217 321 10 Mile
    2 22 Buze D. F 22 Ethiopia 3232 3232 323 10 Mile
    3 16 Gladys K. F 31 Kenya 3276 3276 327 10 Mile
    4 4 Mamitu D. F 33 Ethiopia 3285 3285 328 10 Mile
    5 20 Karolina N. F 35 Poland 3288 3288 328 10 Mile
    ... ... ... ... ... ... ... ... ... ...
    19961 25153 Andres E. M 33 Woodbridge, VA 5287 5334 1700 5K
  1. Air pollution and birth outcomes, study components. Researchers collected data to examine the relationship between air pollutants and preterm births in Southern California. During the study, air pollution levels were measured by air quality monitoring stations. Specifically, levels of carbon monoxide were recorded in parts per million, nitrogen dioxide and ozone in parts per hundred million, and inhalable particulate matter (PM\(_{10}\)) in \(\mu g/m^3\). Length of gestation data were collected on 143,196 births between the years 1989 and 1993, and air pollution exposure during gestation was calculated for each birth. The analysis suggested that increased ambient PM\(_{10}\) and, to a lesser degree, CO concentrations may be associated with the occurrence of preterm births. (Ritz et al. 2000)

    1. Identify the main research question of the study.

    2. Who are the subjects in this study, and how many are included?

    3. What are the variables in the study? Identify each variable as numerical or categorical. If numerical, state whether the variable is discrete or continuous. If categorical, state whether the variable is ordinal.

  1. Cheaters, study components. Researchers studying the relationship between honesty, age and self-control conducted an experiment on 160 children between the ages of 5 and 15. Participants reported their age, sex, and whether they were an only child or not. The researchers asked each child to toss a fair coin in private and to record the outcome (white or black) on a paper sheet, and said they would only reward children who report white. (Bucciol and Piovesan 2011)

    1. Identify the main research question of the study.

    2. Who are the subjects in this study, and how many are included?

    3. The study’s findings can be summarized as follows: “Half the students were explicitly told not to cheat and the others were not given any explicit instructions. In the no instruction group probability of cheating was found to be uniform across groups based on child’s characteristics. In the group that was explicitly told to not cheat, girls were less likely to cheat, and while rate of cheating didn’t vary by age for boys, it decreased with age for girls.” How many variables were recorded for each subject in the study in order to conclude these findings? State the variables and their types.

  1. Gamification and statistics, study components. Gamification is the application of game-design elements and game principles in non-game contexts. In educational settings, gamification is often implemented as educational activities to solve problems by using characteristics of game elements. Researchers investigating the effects of gamification on learning statistics conducted a study where they split college students in a statistics class into four groups: (1) no reading exercises and no gamification, (2) reading exercises but no gamification, (3) gamification but no reading exercises, and (4) gamification and reading exercises. Students in all groups also attended lectures. Students in the class were from two majors: Electrical and Computer Engineering (n = 279) and Business Administration (n = 86). After their assigned learning experience, each student took a final evaluation comprised of 30 multiple choice question and their score was measured as the number of questions they answered correctly. The researchers considered students’ gender, level of studies (first through fourth year) and academic major. Other variables considered were expertise in the English language and use of personal computers and games, both of which were measured on a scale of 1 (beginner) to 5 (proficient). The study found that gamification had a positive effect on student learning compared to traditional teaching methods involving lectures and reading exercises. They also found that the effect was larger for females and Engineering students. (Legaki et al. 2020)

    1. Identify the main research question of the study.

    2. Who were the subjects in this study, and how many were included?

    3. What are the variables in the study? Identify each variable as numerical or categorical. If numerical, state whether the variable is discrete or continuous. If categorical, state whether the variable is ordinal.

  1. Stealers, study components. In a study of the relationship between socio-economic class and unethical behavior, 129 University of California undergraduates at Berkeley were asked to identify themselves as having low or high social-class by comparing themselves to others with the most (least) money, most (least) education, and most (least) respected jobs. They were also presented with a jar of individually wrapped candies and informed that the candies were for children in a nearby laboratory, but that they could take some if they wanted. After completing some unrelated tasks, participants reported the number of candies they had taken. (Piff et al. 2012)

    1. Identify the main research question of the study.

    2. Who were the subjects in this study, and how many were included?

    3. The study found that students who were identified as upper-class took more candy than others. How many variables were recorded for each subject in the study in order to conclude these findings? State the variables and their types.

  1. Migraine and acupuncture. A migraine is a particularly painful type of headache, which patients sometimes wish to treat with acupuncture. To determine whether acupuncture relieves migraine pain, researchers conducted a randomized controlled study where 89 individuals who identified as female diagnosed with migraine headaches were randomly assigned to one of two groups: treatment or control. Forty-three (43) patients in the treatment group received acupuncture that is specifically designed to treat migraines. Forty-six (46) patients in the control group received placebo acupuncture (needle insertion at non-acupoint locations). Twenty-four (24) hours after patients received acupuncture, they were asked if they were pain free. Results are summarized in the contingency table below. Also provided is a figure from the original paper displaying the appropriate area (M) versus the inappropriate area (S) used in the treatment of migraine attacks. 10 (Allais et al. 2011)

    Pain free?
    Group No Yes
    Control 44 2
    Treatment 33 10
    1. What percent of patients in the treatment group were pain free 24 hours after receiving acupuncture?

    2. What percent were pain free in the control group?

    3. In which group did a higher percent of patients become pain free 24 hours after receiving acupuncture?

    4. Your findings so far might suggest that acupuncture is an effective treatment for migraines for all people who suffer from migraines. However this is not the only possible conclusion. What is one other possible explanation for the observed difference between the percentages of patients that are pain free 24 hours after receiving acupuncture in the two groups?

    5. What are the explanatory and response variables in this study?

  1. Sinusitis and antibiotics. Researchers studying the effect of antibiotic treatment for acute sinusitis compared to symptomatic treatments randomly assigned 166 adults diagnosed with acute sinusitis to one of two groups: treatment or control. Study participants received either a 10-day course of amoxicillin (an antibiotic) or a placebo similar in appearance and taste. The placebo consisted of symptomatic treatments such as acetaminophen, nasal decongestants, etc. At the end of the 10-day period, patients were asked if they experienced improvement in symptoms. The distribution of responses is summarized below.11 (Garbutt et al. 2012)

    Improvement
    Group No Yes
    Control 16 65
    Treatment 19 66
    1. What percent of patients in the treatment group experienced improvement in symptoms?

    2. What percent experienced improvement in symptoms in the control group?

    3. In which group did a higher percentage of patients experience improvement in symptoms?

    4. Your findings so far might suggest a real difference in the effectiveness of antibiotic and placebo treatments for improving symptoms of sinusitis. However this is not the only possible conclusion. What is one other possible explanation for the observed difference between the percentages patients who experienced improvement in symptoms?

    5. What are the explanatory and response variables in this study?

  1. Daycare fines, study components. Researchers tested the deterrence hypothesis which predicts that the introduction of a penalty will reduce the occurrence of the behavior subject to the fine, with the condition that the fine leaves everything else unchanged, by instituting a fine for late pickup at daycare centers. For this study, they worked with 10 volunteer daycare centers that did not originally impose a fine to parents for picking up their kids late. They randomly selected 6 of these daycare centers and instituted a monetary fine (of a considerable amount) for picking up children late and then removed it. In the remaining 4 daycare centers no fine was introduced. The study period was divided into four: before the fine (weeks 1–4), the first 4 weeks with the fine (weeks 5-8), the last 8 weeks with fine (weeks 9–16), and the after fine period (weeks 17-20). Throughout the study, the number of kids who were picked up late was recorded each week for each daycare. The study found that the number of late-coming parents increased discernibly when the fine was introduced, and no reduction occurred after the fine was removed.12 (Gneezy and Rustichini 2000)

    center week group late_pickups study_period
    1 1 test 8 before fine
    1 2 test 8 before fine
    1 3 test 7 before fine
    1 4 test 6 before fine
    1 5 test 8 first 4 weeks with fine
    ... ... ... ... ...
    10 20 control 13 after fine
    1. Is this an observational study or an experiment? Explain your reasoning.

    2. What are the cases in this study and how many are included?

    3. What is the response variable in the study and what type of variable is it?

    4. What are the explanatory variables in the study and what types of variables are they?

  1. Efficacy of COVID-19 vaccine on adolescents, study components. Results of a Phase 3 trial announced in March 2021 show that the Pfizer-BioNTech COVID-19 vaccine demonstrated 100% efficacy and robust antibody responses on 12 to 15 years old adolescents with or without prior evidence of SARS-CoV-2 infection. In this trial 2,260 adolescents were randomly assigned to two groups: one group got the vaccine (n = 1,131) and the other got a placebo (n = 1,129). While 18 cases of COVID-19 were observed in the placebo group, none were observed in the vaccine group.13 (Pfizer 2021)

    1. Is this an observational study or an experiment? Explain your reasoning.

    2. What are the cases in this study and how many are included?

    3. What is the response variable in the study and what type of variable is it?

    4. What are the explanatory variables in the study and what types of variables are they?

  1. Palmer penguins. Data were collected on 344 penguins living on three islands (Torgersen, Biscoe, and Dream) in the Palmer Archipelago, Antarctica. In addition to which island each penguin lives on, the data contains information on the species of the penguin (Adelie, Chinstrap, or Gentoo), its bill length, bill depth, and flipper length (measured in millimeters), its body mass (measured in grams), and the sex of the penguin (female or male). 14 (Gorman et al. 2014)

    1. How many cases were included in the data?
    2. How many numerical variables are included in the data? Indicate what they are, and if they are continuous or discrete.
    3. How many categorical variables are included in the data, and what are they? List the corresponding levels (categories) for each.
  1. Smoking habits of UK residents. A survey was conducted to study the smoking habits of 1,691 UK residents. Below is a data frame displaying a portion of the data collected in this survey. A blank cell indicates that data for that variable was not available for a given respondent.15

    amount
    sex age marital_status gross_income smoke weekend weekday
    1 Female 61 Married 2,600 to 5,200 No
    2 Female 61 Divorced 10,400 to 15,600 Yes 5 4
    3 Female 69 Widowed 5,200 to 10,400 No
    4 Female 50 Married 5,200 to 10,400 No
    5 Male 31 Single 10,400 to 15,600 Yes 10 20
    ... ... ... ... ... ...
    1691 Male 49 Divorced Above 36,400 Yes 15 10
    1. What does each row of the data frame represent?

    2. How many participants were included in the survey?

    3. Indicate whether each variable is numerical or categorical. If numerical, identify as continuous or discrete. If categorical, indicate if the variable is ordinal.

  1. US Airports. The visualization below shows the geographical distribution of airports in the contiguous United States and Washington, DC. This visualization was constructed based on a dataset where each observation is an airport.16

    1. List the variables you believe were necessary to create this visualization.

    2. Indicate whether each variable is numerical or categorical. If numerical, identify as continuous or discrete. If categorical, indicate if the variable is ordinal.

  1. UN Votes. The visualization below shows voting patterns in the United States, Canada, and Mexico in the United Nations General Assembly on a variety of issues. Specifically, for a given year between 1946 and 2019, it displays the percentage of roll calls in which the country voted yes for each issue. This visualization was constructed based on a dataset where each observation is a country/year pair.17

    1. List the variables used in creating this visualization.

    2. Indicate whether each variable is numerical or categorical. If numerical, identify as continuous or discrete. If categorical, indicate if the variable is ordinal.

  1. UK baby names. The visualization below shows the number of baby girls born in the United Kingdom (comprised of England & Wales, Northern Ireland, and Scotland) who were given the name “Fiona” over the years.18

    1. List the variables you believe were necessary to create this visualization.

    2. Indicate whether each variable is numerical or categorical. If numerical, identify as continuous or discrete. If categorical, indicate if the variable is ordinal.

  1. Shows on Netflix. The visualization below shows the distribution of ratings of TV shows on Netflix (a streaming entertainment service) based on the decade they were released in and the country they were produced in. In the dataset, each observation is a TV show.19

    1. List the variables you believe were necessary to create this visualization.

    2. Indicate whether each variable is numerical or categorical. If numerical, identify as continuous or discrete. If categorical, indicate if the variable is ordinal.

  1. Stanford Open Policing. The Stanford Open Policing project gathers, analyzes, and releases records from traffic stops by law enforcement agencies across the United States. Their goal is to help researchers, journalists, and policy makers investigate and improve interactions between police and the public. The following is an excerpt from a summary table created based off of the data collected as part of this project. (Pierson et al. 2020)

    Driver
    Car
    County State Race / Ethnicity Arrest rate Stops / year Search rate
    Apache County AZ Black 0.016 266 0.077
    Apache County AZ Hispanic 0.018 1008 0.053
    Apache County AZ White 0.006 6322 0.017
    Cochise County AZ Black 0.015 1169 0.047
    ... ... ... ... ... ...
    Wood County WI Hispanic 0.029 27 0.036
    Wood County WI White 0.029 1157 0.033
    1. What variables were collected on each individual traffic stop in order to create the summary table above?

    2. State whether each variable is numerical or categorical. If numerical, state whether it is continuous or discrete. If categorical, state whether it is ordinal or not.

    3. Suppose we wanted to evaluate whether vehicle search rates are different for drivers of different races. In this analysis, which variable would be the response variable and which variable would be the explanatory variable?

  1. Space launches. The following summary table shows the number of space launches in the US by the type of launching agency and the outcome of the launch (success or failure).20

    1957 - 1999
    2000-2018
    Failure Success Failure Success
    Private 13 295 10 562
    State 281 3751 33 711
    Startup 0 0 5 65
    1. What variables were collected on each launch in order to create to the summary table above?

    2. State whether each variable is numerical or categorical. If numerical, state whether it is continuous or discrete. If categorical, state whether it is ordinal or not.

    3. Suppose we wanted to study how the success rate of launches vary between launching agencies and over time. In this analysis, which variable would be the response variable and which variable would be the explanatory variable?

  1. Pet names. The city of Seattle, WA has an open data portal that includes pets registered in the city. For each registered pet, we have information on the pet’s name and species. The following visualization plots the proportion of dogs with a given name versus the proportion of cats with the same name. The 20 most common cat and dog names are displayed. The diagonal line on the plot is the \(x = y\) line; if a name appeared on this line, the name’s popularity would be exactly the same for dogs and cats.21

    1. Are these data collected as part of an experiment or an observational study?

    2. What is the most common dog name? What is the most common cat name?

    3. What names are more common for cats than dogs?

    4. Is the relationship between the two variables positive or negative? What does this mean in context of the data?

  1. Stressed out in an elevator. In a study evaluating the relationship between stress and muscle cramps, half the subjects are randomly assigned to be exposed to increased stress by being placed into an elevator that falls rapidly and stops abruptly and the other half are left at no or baseline stress.

    1. What type of study is this?

    2. Can this study be used to conclude a causal relationship between increased stress and muscle cramps?


  1. The proportion of the 224 patients who had a stroke within 365 days: \(45/224 = 0.20.\)↩︎

  2. The loan’s grade is B, and the borrower rents their residence.↩︎

  3. There are multiple strategies that can be followed. One common strategy is to have each student represented by a row, and then add a column for each assignment, quiz, or exam. Under this setup, it is easy to review a single line to understand the grade history of a student. There should also be columns to include student information, such as one column to list student names.↩︎

  4. Each county may be viewed as a case, and there are eleven pieces of information recorded for each case. A table with 3,142 rows and 14 columns could hold these data, where each row represents a county and each column represents a particular piece of information.↩︎

  5. The group variable can take just one of two group names, making it categorical. The num_migraines variable describes a count of the number of migraines, which is an outcome where basic arithmetic is sensible, which means this is a numerical outcome; more specifically, since it represents a count, num_migraines is a discrete numerical variable.↩︎

  6. Two example questions: (1) What is the relationship between loan amount and total income? (2) If someone’s income is above the average, will their interest rate tend to be above or below the average?↩︎

  7. In some disciplines, it’s customary to refer to the explanatory variable as the independent variable and the response variable as the dependent variable. However, this becomes confusing since a pair of variables might be independent or dependent, so we avoid this language.↩︎

  8. The mcu_films data used in this exercise can be found in the openintro R package.↩︎

  9. The run17 data used in this exercise can be found in the cherryblossom R package.↩︎

  10. The migraine data used in this exercise can be found in the openintro R package.↩︎

  11. The sinusitis data used in this exercise can be found in the openintro R package.↩︎

  12. The daycare_fines data used in this exercise can be found in the openintro R package.↩︎

  13. The biontech_adolescents data used in this exercise can be found in the openintro R package.↩︎

  14. Artwork by Allison Horst.↩︎

  15. The smoking data used in this exercise can be found in the openintro R package.↩︎

  16. The usairports data used in this exercise can be found in the airports R package.↩︎

  17. The data used in this exercise can be found in the unvotes R package.↩︎

  18. The ukbabynames data used in this exercise can be found in the ukbabynames R package.↩︎

  19. The netflix_titles data used in this exercise can be found in the tidytuesdayR R package.↩︎

  20. The data used in this exercise comes from the JSR Launch Vehicle Database, 2019 Feb 10 Edition.↩︎

  21. The seattlepets data used in this exercise can be found in the openintro R package.↩︎

中文

1  你好,数据

科学家力求通过严谨的方法和细致的观察来回答问题。这些观察——收集自实地笔记、调查和实验等——构成了统计调查的支柱,被称为 数据。统计学是研究如何最好地收集、分析数据并从数据中得出结论的学科。在这第一章中,我们既关注数据的性质,也关注数据的收集。

1.1 案例研究:使用支架预防中风

在本节中,我们介绍统计学中一个经典的挑战:评估医疗疗法的疗效。本节中的术语,实际上本章的大部分内容,都将在本书后文再次讨论。目前的目的只是初步了解统计学在实践中所能发挥的作用。

一项实验旨在研究支架在治疗有中风风险的患者方面的有效性 (Chimowitz 等人。 2011)。支架是一种小型网状管,放置在狭窄或脆弱的动脉内,以帮助患者在心脏事件后康复,并降低再次心脏病发作或死亡的风险。

许多医生一直希望支架能为有中风风险的患者带来类似的益处。我们首先写出研究人员希望回答的主要问题:

使用支架能否降低中风的风险?

提出这个问题的研究人员对451名存在风险的患者进行了一项实验。每位志愿患者被随机分配到以下两组之一:

  • 治疗组。治疗组的患者接受了支架和医疗管理。医疗管理包括药物治疗、危险因素管理以及生活方式改变方面的帮助。
  • 对照组。对照组的患者接受了与治疗组相同的医疗管理,但他们没有接受支架。

研究人员将224名患者随机分配到治疗组,227名分配到对照组。在这项研究中,对照组提供了一个参照基准,我们可以据此衡量支架对治疗组的医疗影响。

研究人员研究了支架在两个时间点的效果:入组后30天和入组后365天。5名患者的结果总结在 表 1.1. 患者结局记录为 strokeno event,表示患者在该时间段内是否发生了卒中。

stent30 数据和 stent365 数据可以在 openintro R 包中找到。

表 1.1:支架研究中五名患者的结果。
患者 组别 30 天 365天
1 治疗 无事件 无事件
2 治疗 脑卒中 脑卒中
3 治疗 无事件 无事件
4 治疗 无事件 无事件
5 控制 无事件 无事件

很难回答关于支架对卒中发生影响的问题,对于 所有 研究患者使用这些 单个 观测值。这个问题更适合通过对 所有 观测值进行统计分析来解答。 表 1.2 以更有帮助的方式汇总了原始数据。在这张表中,我们可以快速看到整个研究期间发生了什么。例如,要找出治疗组中在治疗后30天内发生中风的患者人数,我们查看最左边一列(30天),在“治疗”与“中风”的交叉处:33。要找出对照组中在接受治疗365天后未发生中风的患者人数,我们查看最右边一列(365天),在“对照”与“无事件”的交叉处:199。

表 1.2:支架研究的描述性统计。
30 天
365 天
组别 卒中 无事件 卒中 无事件
对照组 13 214 28 199
治疗 33 191 45 179
总计 46 405 73 378

治疗组的224名患者中,有45人在第一年结束时发生了中风。使用这两个数字,计算治疗组中在第一年结束时发生中风的患者比例。(注意:所有引导练习的答案都在脚注中提供!)1

我们可以从表格中计算汇总统计量,以便更好地了解支架治疗在两组之间的影响有何不同。所谓 汇总统计量 是指用一个单独的数字概括来自样本的数据。例如,研究开展1年后的主要结果可以用两个汇总统计量来描述:治疗组和对照组中发生中风的人所占的比例。

  • 治疗组(支架)中发生中风的比例: \(45/224 = 0.20 = 20\%.\)
  • 对照组中发生中风的比例: \(28/227 = 0.12 = 12\%.\)

这两个汇总统计量有助于寻找两组之间的差异,而我们即将看到一个令人意外的结果:治疗组中另有8%的患者发生了中风!这一点之所以重要有两个原因。第一,它与医生的预期相反,医生原本期望支架会 降低 中风的发生率。第二,它引出了一个统计学问题:数据是否显示两组之间存在“真实”的差异?

第二个问题很微妙。假设你抛一枚硬币100次。虽然每次抛硬币时正面朝上的概率是50%,但我们很可能不会恰好观察到50次正面。这种类型的变异几乎是任何数据生成过程的一部分。支架研究中的8%差异有可能正是由这种自然变异造成的。然而,我们观察到的差异越大(在特定样本量下),差异由偶然造成的可信度就越低。因此,我们真正要问的是:如果支架实际上没有效果,那么观察到如此大的差异的可能性有多大?

虽然我们目前还没有统计工具来完全自行解答这个问题,但我们可以理解已发表分析的结论:在这项针对中风患者的研究中,有令人信服的证据表明支架造成了伤害。

注意: 不要将这项研究的结果推广到所有患者和所有支架。这项研究的对象是具有非常特定特征且自愿参与研究的患者,他们可能无法代表所有中风患者。此外,支架有许多类型,而这项研究只考虑了自膨胀式Wingspan支架(Boston Scientific)。不过,这项研究确实给我们留下了一个重要的教训:我们应该对意外情况保持警觉。

1.2 数据基础

有效地展示和描述数据是大多数分析的第一步。本节介绍一种组织数据的结构,以及一些将在本书中通篇使用的术语。

1.2.1 观测、变量与数据矩阵

表 1.3 展示了某数据集的六行数据,该数据集包含通过 Lending Club(一家点对点借贷公司)提供的 50 笔随机抽取的贷款。该数据集将被称为 loan50.

loan50 数据可以在 openintro R 包中找到。

表中每一行代表一笔单独的贷款。一行的正式名称是 案例观测观测单位。各列代表每笔贷款的特征,其中每一列被称为 变量. 例如,第一行表示一笔金额为 $22,000、利率为 10.90% 的贷款,其中借款人位于新泽西州(NJ),其收入为 $59,000。

第一笔贷款的等级在 表 1.3中是什么?另外,第一笔贷款的借款人的住房所有权状况如何?提醒:对于这些引导练习题,你可以在脚注中核对答案。2

在实践中,提出澄清性问题以确保理解数据的重要方面尤为重要。例如,确保我们了解每个变量的含义及其测量单位始终十分重要。在数据集 loan50 中,各变量的描述见 表 1.4.

表 1.3:来自数据集的六个观测 loan50 数据集的最后五行。
loan_amount interest_rate term grade state total_income homeownership
1 22,000 10.90 60 B NJ 59,000 租金
2 6,000 9.92 36 B CA 60,000 租金
3 25,000 26.30 36 E SC 75,000 抵押贷款
4 6,000 9.92 36 B CA 75,000 租金
5 25,000 9.43 60 B OH 254,000 抵押贷款
6 6,400 9.92 36 B IN 67,000 抵押贷款
表 1.4:变量及其描述,适用于 loan50 数据集的最后五行。
变量 描述
loan_amount 收到的贷款金额,单位为美元。
interest_rate 贷款利率,以年百分比表示。
term 贷款期限,总是设定为整数个月。
grade 贷款等级,取值为 A 到 G,代表贷款的质量及其被偿还的可能性。
state 借款人所居住的美国州。
total_income 借款人的总收入(包括任何第二份收入),以美元为单位。
homeownership 表示该人是拥有住房、拥有但带有抵押贷款,还是租房居住。

表 1.3 中的数据构成一个 数据框,这是一种方便且常见的数据组织方式,尤其是在以电子表格收集数据时。每一行是一个唯一的个案(观测单元)、每一列是一个变量、每个单元格是单个值的数据框,通常被称为 整洁数据 (Wickham 2014).

在记录数据时,除非你有非常充分的理由使用其他结构,否则应使用整洁数据框。这种结构允许将新的个案作为新的行添加,或将新的变量作为新的列添加,并有助于可视化、汇总和其他统计分析。

一门课程中作业、随堂测验和考试的成绩通常记录在成绩册中,而成绩册采用数据框的形式。你会如何使用数据框来组织一门课程的成绩数据?请描述观测单位和变量。3

我们考察美国 3,142 个县的数据,其中包括每个县的名称、该县所在的州、2017 年的人口、2010 年至 2017 年的人口变化、贫困率以及其他九项特征。这些数据可以如何组织在一个数据框中?4

上文引导练习中所描述的数据即为 county 数据集,该数据集以数据框的形式呈现于 表 1.5。这些变量,以及数据集中未能在 表 1.5 中展示的变量,其描述见 表 1.6.

表 1.5:六个观测和六个变量,来自 county 数据集的最后五行。
name state pop2017 pop_change unemployment_rate median_edu
Autauga County 阿拉巴马州 55,504 1.48 3.86 some_college
Baldwin County 阿拉巴马州 212,628 9.19 3.99 some_college
巴伯县 阿拉巴马州 25,270 -6.22 5.90 hs_diploma
比伯县 阿拉巴马州 22,668 0.73 4.39 hs_diploma
布朗特县 阿拉巴马州 58,013 0.68 4.02 hs_diploma
布洛克县 阿拉巴马州 10,309 -2.28 4.93 hs_diploma
表 1.6:变量及其说明,针对 county 数据集的最后五行。
变量 描述
name 县名。
state 州名。
pop2000 2000年人口。
pop2010 2010年人口。
pop2017 2017年人口。
pop_change 2010年至2017年的人口变化(百分比)。
poverty 2017年贫困人口百分比。
homeownership 住房自有率,2006-2010年。
multi_unit 多户住宅比例:处于多户结构中的住房单元所占百分比,2006-2010年。
unemployment_rate 2017 年的失业率。
metro 该县是否包含大都市区,取值为 yes 或 no。
median_edu 教育水平中位数(2013-2017),取以下值之一:below_hs、hs_diploma、some_college 或 bachelors。
per_capita_income 人均(每人)收入(2013-2017)。
median_hh_income 家庭收入中位数。
smoking_ban 描述 2010 年实施的县级禁烟令类型,取以下值之一:none、partial 或 comprehensive。

county 数据可以在 usdata R 包中找到。

1.2.2 变量的类型

检查 unemployment_rate, pop2017, statemedian_edu 变量,它们位于 county 数据集中。这些变量中的每一个在本质上都与其他三个不同,但其中一些具有某些共同特征。

首先考虑 unemployment_rate,它被认为是一个 数值型 变量,因为它可以取很大范围内的数值,并且对这些数值进行相加、相减或求平均值都是有意义的。另一方面,我们不会将表示电话区号的变量归类为数值型,因为区号的平均值、总和与差值都没有任何明确的意义。相反,我们会将区号视为一个分类变量。

pop2017 变量也是数值型的,尽管它似乎与 unemployment_rate稍有不同。这个表示人口数量的变量只能取非负整数 (0, 1, 2, …)。因此,人口变量被认为是 离散 的,因为它只能取跳跃式变化的数值。另一方面,失业率变量则被认为是 连续.

的。变量 state 在计入华盛顿特区后最多可取 51 个值:阿拉巴马、阿拉斯加、……、怀俄明。因为这些响应本身是类别, state 被称为一个 分类 变量,而其可能的取值(州)则被称为该变量的 水平 (例如,哥伦比亚特区、阿拉巴马、阿拉斯加等)。

最后,考虑 median_edu 变量,它描述了县居民的教育水平中位数,其在每个县中的取值为 below_hs, hs_diploma, some_college,或 bachelors 。这个变量似乎是混合型的:它是一个分类变量,但其各个水平具有自然的顺序。具有这些性质的变量被称为 定序 变量,而没有这种特殊排序的普通分类变量则被称为 定类 变量。为了简化分析,本书中的任何分类变量都将被视为名义(无序)分类变量(参见 图 1.1).

Types of variables are broken down into numerical (which can be discrete or continuous) and categorical (which can be ordinal or nominal).
图 1.1:变量按其各自类型的划分。

某统计学课程收集了关于学生的数据。为每位学生记录了三个变量:兄弟姐妹的人数、学生身高,以及该学生此前是否修过统计学课程。请将每个变量分类为连续数值型、离散数值型或分类型。


兄弟姐妹的人数和学生身高属于数值变量。由于兄弟姐妹的人数是一个计数,所以它是离散的。身高是连续变化的,因此它是一个连续数值变量。最后一个变量将学生分为两类——修过统计学课程的学生和未修过统计学课程的学生——这使该变量成为分类变量。

一项实验正在评估一种新药治疗偏头痛的疗效。实验中使用一个 group 变量来指明每位患者所属的实验组:治疗组或对照组。而 num_migraines 变量表示患者在 3 个月期间所经历的偏头痛次数。请将每个变量分类为数值型还是分类型?5

1.2.3 变量之间的关系

许多分析都源于研究者想要寻找两个或多个变量之间的关系。社会科学家可能想要回答以下一些问题:

县人口出现高于平均水平的增长,是否往往对应于家庭收入中位数较高或较低的县?

如果某个县的住房自有率低于全国平均水平,那么该县位于多单元结构中的住房单元百分比是倾向于高于还是低于全国平均水平?

美国各县的中位数教育水平能在多大程度上解释中位数家庭收入?

要回答这些问题,必须收集数据,例如 county 数据集展示于 表 1.5。查看 汇总统计 可以就每个问题的具体细节提供数值上的洞察。或者,也可以使用图形来直观地探索数据,这可能比单个汇总统计量提供更多的洞察。

散点图 是一类用于研究两个数值变量之间关系的图形。 图 1.2 展示了变量之间的关系: homeownershipmulti_unit,即处于多单元结构(例如公寓、共管公寓)中的住房单元所占的百分比。图中的每个点代表一个县。例如,高亮的点对应第413号县,来自 county 数据集:佐治亚州查塔胡奇县(Chattahoochee County),该县有 39.4% 的住房单元处于多单元结构中,住房自有率为 31.3%。散点图表明这两个变量之间存在某种关系:多单元结构住房单元比例较高的县,其住房自有率往往较低。我们可以就这种关系为何存在展开头脑风暴,并对每一种想法进行研究,以确定哪些是最合理的解释。

A scatterplot of homeownership (on the y-axis) versus the percent of housing units that are in multi-unit structures (on the x-axis) for US counties. The observation from Chattahoochee County, Georgia is highlighted as having a multi-unit rate of 39.4% and a homeownership rate of 31.3%
图 1.2:美国各县住房自有率与多单元结构住房单元百分比的散点图。高亮的点表示佐治亚州查塔胡奇县(Chattahoochee County),该县的多单元比率为 39.4%,住房自有率为 31.3%。

多单元比率与住房自有率被认为是相关联的,因为图中显示出一种可辨认的模式。当两个变量彼此之间表现出某种联系时,它们被称为 关联 变量。

查看变量,位于 loan50 数据集,其相关描述见 表 1.4。请就 loan50 中你感兴趣的变量之间可能存在的关系提出两个问题。6

本示例考察各县 2010 年至 2017 年的人口百分比变化与家庭收入中位数之间的关系,这一关系以散点图的形式展示在 图 1.3中。这些变量是相关联的吗?


一个县的家庭收入中位数越高,该县观察到的人口增长幅度就越大。尽管并非每一个家庭收入中位数较高的县都有较高的人口增长,但图中呈现的趋势是显而易见的。由于这些变量之间存在某种关系,因此它们是相关联的。

A scatterplot showing population change (on the y-axis) against median household income (on the x-axis). Owsley County of Kentucky is highlighted, which lost 3.63% of its population from 2010 to 2017 and had median household income of $22,736.
图 1.3:展示人口变化与家庭收入中位数关系的散点图。图中突出显示了肯塔基州的奥斯利县,该县在 2010 年至 2017 年间人口减少了 3.63%,其家庭收入中位数为 $22,736。

由于 图 1.2 中呈现下降趋势——拥有更多多户结构住房单元的县与较低的自有住房率相关联——这些变量被称为 负相关正关联 体现在 median_hh_incomepop_change 变量在 图 1.3中的关系中,其中家庭收入中位数较高的县往往有较高的人口增长率。

如果两个变量不相关联,则称它们为 独立。也就是说,如果两个变量之间没有明显的关系,那么这两个变量就是独立的。

关联或独立,二者不可兼得。

一对变量要么存在某种联系(关联),要么没有联系(独立)。没有任何一对变量既是关联的又是独立的。

1.2.4 解释变量与响应变量

当我们提出关于两个变量之间关系的问题时,我们有时还想要确定一个变量的变化是否会导致另一个变量的变化。考虑以下对之前关于 county 数据集的问题的改述:

如果一个县的家庭收入中位数增加,这是否会带动该县人口的增长?

在这个问题中,我们问的是一个变量是否会影响另一个变量。如果这是我们的基本信念,那么 家庭收入中位数 是该假设关系中的 解释变量,而 人口变化 是该假设关系中的 响应变量7

解释变量与响应变量。

当我们怀疑一个变量可能会对另一个变量产生因果影响时,我们将第一个变量称为解释变量,第二个变量称为响应变量。我们也使用术语 解释变量响应变量 来描述这样的变量,其中 响应变量 或许可以通过 解释变量 来进行预测,即使两者之间并不存在因果关系。

解释变量 \(\rightarrow\) 可能会影响 \(\rightarrow\) 响应变量


对于许多变量对而言,两者之间并没有被假设存在某种关系,在这种情况下,这些标签就不会用于其中任何一个变量。

请记住,以这种方式为变量贴标签的做法并不能保证因果关系的存在。要正式评估一个变量是否会引起另一个变量的变化,需要进行实验。

1.2.5 观察研究与实验

数据收集有两种主要类型:实验和观察性研究。

当研究人员想要评估特定特征、处理或条件的影响时,他们会进行一项 实验. 例如,我们可能怀疑饮用高热量能量饮料会提高比赛中的表现。为了检验解释变量(跑者是否饮用了能量饮料)与响应变量(比赛用时)之间是否真的存在因果关系,研究人员选取一个由个体组成的样本并将其分成若干组。每组中的个体会被 分配 一种处理。当个体被随机分配到一个组时,该实验被称为 随机实验。随机分配将研究中的参与者分成在各方面都大致均等的组,从而使我们能够控制任何可能影响结果的混杂变量(例如体能水平、比赛经验等)。(参见 第2.2.1节 ,以了解有关混杂变量的更多信息。)例如,实验中的每位跑者都可以被随机分配——比如通过抛硬币——到两组之一:第一组接受一种 安慰剂 (虚假处理,在本例中为一种无热量饮料),第二组则接受高热量能量饮料。参见 第1.1节 中的案例研究,其中提供了实验的另一个例子,不过该研究并未使用安慰剂。

研究人员进行 观察性研究 ,即以一种不直接干扰数据产生的方式收集数据。例如,研究人员可以通过调查收集信息、查阅医疗或公司记录,或者跟踪一个由许多相似个体组成的 队列 ,以形成关于某些疾病为何会发生的假设。在上述每一种情形中,研究人员仅仅观察所产生的数据。一般而言,观察性研究能够为变量之间自然出现的关联提供证据,但它们本身无法表明因果联系,因为它们不提供控制混杂变量的机制。(参见 第2.2.1节 ,以了解有关混杂变量的更多信息。)

关联 \(\neq\) 因果关系。

一般来说,关联并不意味着因果。随机化实验的一个优点是,利用这类研究更容易确立因果关系。其主要原因在于,观察性研究并未对混杂变量加以控制,因此借助观察性研究确立因果关系需要高级的统计方法(这超出了本书的范围)。当我们讨论实验时会重新探讨混杂的概念,参见 第2.2.1节.

1.3 本章复习

1.3.1 小结

本章带你走进了数据的世界。数据可以按多种方式进行组织,但整洁数据——即每一行代表一次观测、每一列代表一个变量——最易于进行统计分析。随着我们继续开展端到端的数据分析,本章中的许多思想还会被再次提及。在下一章中,你将学习如何设计研究来收集我们所需的数据,从而在期望的推断范围内得出结论。

1.3.2 术语

本章中介绍的术语列于 表 1.7。如果您不确定其中一些术语的含义,我们建议您回到正文中复习它们的定义。您应该能够很容易地发现它们是 粗体文本.

表1.7:本章中介绍的术语。
关联 实验 定序
案例 解释变量 安慰剂
分类 独立 正关联
队列 水平 随机实验
连续 负关联 响应变量
数据 定类 汇总统计量
数据框 数值型 整洁数据
因变量 观测 观测单位
离散 观察性研究 变量

1.4 练习

奇数编号习题的答案见 附录 A.1.

  1. 漫威电影宇宙电影。 下面的数据框包含漫威电影宇宙无限传奇(一个从2008年的《钢铁侠》跨越至2019年的《终局之战》的电影故事线)电影的相关信息。票房总额以百万美元为单位给出。这个数据框有多少个观测值和多少个变量?8

    片长
    总票房
    片名 小时 分钟 上映日期 美国首映周末 美国 世界
    1 钢铁侠 2 6 5/2/2008 98.62 319.03 585.8
    2 无敌浩克 1 52 6/12/2008 55.41 134.81 264.77
    3 钢铁侠2 2 4 5/7/2010 128.12 312.43 623.93
    4 雷神 1 55 5/6/2011 65.72 181.03 449.33
    5 美国队长:复仇者先锋 2 4 7/22/2011 65.06 176.65 370.57
    ... ... ... ... ... ... ... ...
    23 蜘蛛侠:英雄远征 2 9 7/2/2019 92.58 390.53 1131.93
  1. 樱花赛跑。 下方的数据框包含2017年樱花赛跑参赛者的信息,这是一项在华盛顿特区举行的年度公路赛跑。大多数跑者参加10英里跑,而较小比例的人参加5公里跑或步行。这个数据框有多少个观测值和多少个变量?9

    时间
    号码布 姓名 性别 年龄 城市 / 国家 净计时 时钟 配速 项目
    1 6 希沃特·G. F 21 埃塞俄比亚 3217 3217 321 10英里
    2 22 布泽·D. F 22 埃塞俄比亚 3232 3232 323 10英里
    3 16 格拉迪斯·K. F 31 肯尼亚 3276 3276 327 10英里
    4 4 玛米图·D. F 33 埃塞俄比亚 3285 3285 328 10英里
    5 20 卡罗利娜·N. F 35 波兰 3288 3288 328 10英里
    ... ... ... ... ... ... ... ... ... ...
    19961 25153 Andres E. 33 弗吉尼亚州伍德布里奇 5287 5334 1700 5公里
  1. 空气污染与出生结局,研究组成部分。 研究人员收集数据,以考察南加利福尼亚州空气污染物与早产之间的关系。研究期间,空气污染水平由空气质量监测站测量。具体而言,一氧化碳水平以百万分率为单位记录,二氧化氮和臭氧以亿分率为单位记录,以及可吸入颗粒物(PM\(_{10}\))以 \(\mu g/m^3\)为单位记录。妊娠时长数据收集自1989年至1993年间的143,196例分娩,并针对每次分娩计算了其妊娠期间的空气污染暴露量。分析表明,环境中PM\(_{10}\) 和(程度较轻的)CO浓度的升高可能与早产的发生有关。 (Ritz 等,2000)

    1. 指出该研究的主要研究问题。

    2. 这项研究的对象是谁?共包含多少人?

    3. 研究中的变量有哪些?请将每个变量识别为数值型或类别型。若为数值型,请说明该变量是离散的还是连续的;若为类别型,请说明该变量是否为有序变量。

  1. 作弊者,研究组成部分。 研究诚实、年龄与自我控制能力之间关系的研究人员对160名年龄在5至15岁之间的儿童开展了一项实验。参与者报告了他们的年龄、性别,以及是否为独生子女。研究人员要求每个孩子私下抛掷一枚均匀的硬币,并将结果(白色或黑色)记录在一张纸上,同时表示他们只会奖励那些报告为白色的孩子。 (Bucciol 和 Piovesan,2011)

    1. 指出该研究的主要研究问题。

    2. 这项研究的对象是谁?共包含多少人?

    3. 该研究的发现可以总结如下: “一半学生被明确告知不许作弊,其他人则未得到任何明确指示。在无指示组中,作弊概率被发现在按儿童特征划分的各子群体间是相同的。在被明确告知不许作弊的组中,女孩作弊的可能性较低;男孩的作弊率不随年龄变化,而女孩的作弊率则随年龄增长而下降。” 为了得出这些发现,研究中为每个研究对象记录了多少个变量?请说明这些变量及其类型。

  1. 游戏化与统计学,研究组成部分。 游戏化是指在非游戏情境中应用游戏设计元素和游戏原则。在教育环境中,游戏化通常被实施为借助游戏元素的特征来解决问题的教育活动。研究游戏化对统计学学习之影响的研究人员开展了一项研究,他们将统计学课堂上的大学生分为四个小组:(1) 无阅读练习且无游戏化,(2) 有阅读练习但无游戏化,(3) 有游戏化但无阅读练习,(4) 有游戏化且有阅读练习。所有小组的学生同时也参加讲座。该班级的学生来自两个专业:电气与计算机工程 (n = 279) 和工商管理 (n = 86)。在完成各自被分配的学习体验后,每名学生参加了一次由30道选择题组成的期末测评,其得分以答对的题目数量来衡量。研究人员考虑了学生的性别、就读年级(一年级至四年级)和所学专业。所考虑的其他变量还包括英语水平以及个人电脑和游戏的使用情况,这两者均以1(初学者)至5(熟练)的量表进行测量。研究发现,与包含讲座和阅读练习的传统教学方法相比,游戏化对学生的学习有积极影响。他们还发现,这一影响对女生和工程专业的学生更大。 (Legaki et al. 2020)

    1. 指出该研究的主要研究问题。

    2. 这项研究的对象是谁?共包含多少人?

    3. 研究中的变量有哪些?请将每个变量识别为数值型或类别型。若为数值型,请说明该变量是离散的还是连续的;若为类别型,请说明该变量是否为有序变量。

  1. 偷糖者,研究组成部分。 在一项关于社会经济阶层与不道德行为之间关系的研究中,129名加州大学伯克利分校的本科生被要求通过将自己与拥有最多(最少)金钱、受过最多(最少)教育以及从事最(最不)受人尊敬职业的他人进行比较,来认定自己属于低社会阶层还是高社会阶层。研究人员还向他们展示了一罐独立包装的糖果,并告知这些糖果是给附近实验室的孩子们准备的,但如果他们想要,可以拿一些。在完成一些不相关的任务后,参与者报告了自己拿走的糖果数量。 (Piff et al. 2012)

    1. 指出该研究的主要研究问题。

    2. 这项研究的对象是谁?共包含多少人?

    3. 研究发现,被认定为上层阶级的学生比其他人拿走了更多糖果。为了得出这些发现,研究中为每个研究对象记录了多少个变量?请说明这些变量及其类型。

  1. 偏头痛与针灸。 偏头痛是一种疼痛尤为剧烈的头痛类型,患者有时希望用针灸来治疗。为了确定针灸是否能缓解偏头痛疼痛,研究人员开展了一项随机对照研究,将89名自我认同为女性且被诊断患有偏头痛的个体随机分配到两组之一:治疗组或对照组。治疗组中的43名患者接受了专门用于治疗偏头痛的针灸。对照组中的46名患者接受了假针灸(在非穴位部位进针)。患者接受针灸24小时后,被问及是否已无疼痛。结果汇总在下面的列联表中。同时还提供了原论文中的一幅图,显示了用于治疗偏头痛发作的适宜区域(M)与不适宜区域(S)。 10 (Allais et al. 2011)

    疼痛消失?
    组别
    对照组 44 2
    治疗 33 10
    1. 治疗组中有多大百分比的患者在接受针灸24小时后疼痛消失?

    2. 对照组中有多大百分比的患者疼痛消失?

    3. 哪一组中有更大百分比的患者在接受针灸24小时后疼痛消失?

    4. 你到目前为止的发现可能表明,针灸对所有偏头痛患者都是一种有效的治疗方法。然而,这并不是唯一可能的结论。对于两组患者在接受针灸24小时后疼痛消失的百分比之间所观察到的差异,还有一种其他可能的解释是什么?

    5. 这项研究中的解释变量和响应变量是什么?

  1. 鼻窦炎与抗生素。 为研究抗生素治疗与对症治疗相比对急性鼻窦炎的疗效,研究人员将166名被诊断为急性鼻窦炎的成年人随机分配到两组之一:治疗组或对照组。研究参与者要么接受为期10天的阿莫西林(一种抗生素)疗程,要么接受在外观和味道上与之相似的安慰剂。安慰剂由对乙酰氨基酚、鼻用减充血剂等对症治疗组成。在10天周期结束时,询问患者症状是否有所改善。回答的分布总结如下。11 (Garbutt et al. 2012)

    改善
    组别
    对照组 16 65
    治疗 19 66
    1. 治疗组中有百分之多少的患者症状得到了改善?

    2. 对照组中有百分之多少的人症状得到了改善?

    3. 哪一组中症状得到改善的患者百分比更高?

    4. 你目前为止的发现可能表明,抗生素治疗和安慰剂治疗在改善鼻窦炎症状方面的效果存在真实差异。然而,这并不是唯一可能的结论。对于观察到的症状得到改善的患者百分比之间的差异,还有哪一种其他可能的解释?

    5. 这项研究中的解释变量和响应变量是什么?

  1. 托儿所罚款,研究组成部分。 研究人员通过在托儿所对晚接孩子实施罚款来检验威慑假说。该假说预测,在罚款不改变其他一切条件的前提下,引入惩罚将会减少受罚行为的发生。在这项研究中,他们与10家志愿托儿所合作,这些托儿所原本并不因家长晚接孩子而对其罚款。他们从这些托儿所中随机选取了6家,对晚接孩子的行为实施了金钱罚款(金额相当可观),随后又取消了该罚款。其余4家托儿所则未引入罚款。研究期被划分为四个阶段:罚款前(第1–4周)、实施罚款的前4周(第5-8周)、实施罚款的后8周(第9–16周),以及罚款结束后(第17-20周)。在整个研究期间,每周都会记录每个托儿所被晚接走的孩子数量。研究发现,引入罚款后,晚来的家长数量明显增加,而在罚款取消后数量并未减少。12 (Gneezy 和 Rustichini 2000)

    center week 组别 late_pickups study_period
    1 1 测试 8 罚款前
    1 2 测试 8 罚款前
    1 3 测试 7 罚款前
    1 4 测试 6 罚款前
    1 5 测试 8 实施罚款的前4周
    ... ... ... ... ...
    10 20 控制 13 罚款后
    1. 这是一项观察性研究还是实验?请解释你的理由。

    2. 这项研究中的案例是什么?共包含多少个案例?

    3. 这项研究中的响应变量是什么?它是什么类型的变量?

    4. 这项研究中的解释变量是什么?它们是什么类型的变量?

  1. COVID-19疫苗对青少年的有效性,研究的组成部分。 2021年3月公布的一项3期临床试验结果显示,辉瑞-BioNTech COVID-19疫苗在12至15岁青少年中表现出100%的有效性和强劲的抗体应答,且无论其此前有无SARS-CoV-2感染的证据。在这项试验中,2,260名青少年被随机分配到两组:一组接种疫苗(n = 1,131),另一组接受安慰剂(n = 1,129)。安慰剂组中观察到18例COVID-19病例,而疫苗组中无一例。13 (辉瑞 2021)

    1. 这是一项观察性研究还是实验?请解释你的理由。

    2. 这项研究中的案例是什么?共包含多少个案例?

    3. 这项研究中的响应变量是什么?它是什么类型的变量?

    4. 这项研究中的解释变量是什么?它们是什么类型的变量?

  1. 帕尔默企鹅。 数据收集自生活在南极洲帕默群岛三个岛屿(Torgersen、Biscoe 和 Dream)上的 344 只企鹅。除了每只企鹅所居住的岛屿之外,数据还包含企鹅所属物种(阿德利, 帽带,或 巴布亚)、喙长、喙深和鳍肢长度(以毫米为单位)、体重(以克为单位),以及企鹅的性别(雌性或雄性)。 14 (Gorman 等人 2014)

    1. 数据中包含了多少个案例?
    2. 数据中包含多少个数值型变量?请指出它们分别是什么,以及它们是连续型还是离散型。
    3. 数据中包含多少个分类变量?它们分别是什么?请列出每个变量对应的水平(类别)。
  1. 英国居民的吸烟习惯。 为研究 1,691 名英国居民的吸烟习惯而开展了一项调查。下面是一个数据框,显示了此次调查中收集的部分数据。空白单元格表示某位受访者的该变量数据缺失。15

    amount
    sex age marital_status gross_income 吸烟 周末 工作日
    1 女性 61 已婚 2,600 至 5,200
    2 女性 61 离异 10,400 至 15,600 5 4
    3 女性 69 丧偶 5,200 至 10,400
    4 女性 50 已婚 5,200 至 10,400
    5 男性 31 单身 10,400 至 15,600 10 20
    ... ... ... ... ... ...
    1691 男性 49 离异 36,400 以上 15 10
    1. 数据框的每一行代表什么?

    2. 调查中包含了多少名参与者?

    3. 指出每个变量是数值型还是分类型。如果是数值型,请说明是连续型还是离散型。如果是分类型,请说明该变量是否为有序变量。

  1. 美国机场。 下面的可视化展示了美国本土及华盛顿特区的机场地理分布情况。该可视化基于一个数据集构建,其中每个观测值都是一个机场。16

    1. 列出你认为创建此可视化所必需的变量。

    2. 指出每个变量是数值型还是分类型。如果是数值型,请说明是连续型还是离散型。如果是分类型,请说明该变量是否为有序变量。

  1. 联合国投票。 下图显示了美国、加拿大和墨西哥在联合国大会上就各类议题的投票模式。具体来说,对于1946年至2019年间的给定年份,它显示了该国就每个议题投赞成票的唱名表决所占的百分比。此可视化基于一个数据集构建,其中每个观测值是一个国家/年份对。17

    1. 列出用于创建此可视化的变量。

    2. 指出每个变量是数值型还是分类型。如果是数值型,请说明是连续型还是离散型。如果是分类型,请说明该变量是否为有序变量。

  1. 英国婴儿名字。 下图显示了多年来英国(由英格兰和威尔士、北爱尔兰以及苏格兰组成)取名为“Fiona”的女婴数量。18

    1. 列出你认为创建此可视化所必需的变量。

    2. 指出每个变量是数值型还是分类型。如果是数值型,请说明是连续型还是离散型。如果是分类型,请说明该变量是否为有序变量。

  1. Netflix 上的节目。 下图显示了 Netflix(一家流媒体娱乐服务)上的电视节目评分的分布,按节目发布的年代和制作国家划分。在数据集中,每个观测值是一个电视节目。19

    1. 列出你认为创建此可视化所必需的变量。

    2. 指出每个变量是数值型还是分类型。如果是数值型,请说明是连续型还是离散型。如果是分类型,请说明该变量是否为有序变量。

  1. 斯坦福开放警务。 斯坦福开放警务项目收集、分析并发布美国各地执法部门交通拦停的相关记录。其目标是帮助研究人员、记者和政策制定者调查并改善警察与公众之间的互动。以下是基于该项目所收集数据创建的汇总表的节选。 (Pierson等人 2020)

    驾驶员
    汽车
    国营 种族 / 族裔 逮捕率 拦截次数 / 年 搜查率
    阿帕奇县 AZ 黑人 0.016 266 0.077
    阿帕奇县 AZ 西班牙裔 0.018 1008 0.053
    阿帕奇县 AZ 白人 0.006 6322 0.017
    科奇斯县 AZ 黑人 0.015 1169 0.047
    ... ... ... ... ... ...
    伍德县 WI 西班牙裔 0.029 27 0.036
    伍德县 WI 白人 0.029 1157 0.033
    1. 为了创建上面的汇总表,每一次交通拦停都收集了哪些变量?

    2. 说明每个变量是数值型还是分类型。如果是数值型,请说明它是连续的还是离散的;如果是分类型,请说明它是否为有序变量。

    3. 假设我们想评估不同种族驾驶员的车辆搜查率是否不同。在这个分析中,哪个变量是响应变量,哪个变量是解释变量?

  1. 太空发射。 下面的汇总表显示了美国按发射机构类型和发射结果(成功或失败)划分的太空发射次数。20

    1957 - 1999
    2000-2018
    失败 成功 失败 成功
    私营 13 295 10 562
    国营 281 3751 33 711
    初创公司 0 0 5 65
    1. 为了制作上面的汇总表,每次发射收集了哪些变量?

    2. 说明每个变量是数值型还是分类型。如果是数值型,请说明它是连续的还是离散的;如果是分类型,请说明它是否为有序变量。

    3. 假设我们想研究发射成功率在不同发射机构之间以及随时间的变化情况。在这个分析中,哪个变量是响应变量,哪个变量是解释变量?

  1. 宠物名字。 华盛顿州西雅图市有一个开放数据门户,其中收录了在该市注册的宠物。对于每只注册的宠物,我们有关于其名字和物种的信息。下面的可视化图绘制了具有某给定名字的狗的比例与具有相同名字的猫的比例。图中显示了20个最常见的猫名和狗名。图中的对角线是 \(x = y\) 线;如果某个名字出现在这条线上,则该名字在狗和猫中的受欢迎程度就会完全相同。21

    1. 这些数据是通过实验还是观察性研究收集的?

    2. 最常见的狗名是什么?最常见的猫名是什么?

    3. 哪些名字在猫中比在狗中更常见?

    4. 这两个变量之间的关系是正相关还是负相关?这在数据的情境中意味着什么?

  1. 在电梯里压力重重。 在一项评估压力与肌肉痉挛之间关系的研究中,一半受试者被随机分配接受增强的压力,即被放入一部快速下坠并骤然停止的电梯中,另一半受试者则处于无压力或基线压力状态。

    1. 这是一项什么类型的研究?

    2. 这项研究能否用于得出压力增加与肌肉痉挛之间存在因果关系的结论?


  1. 224名患者在365天内发生中风的比例: \(45/224 = 0.20.\)↩︎

  2. 该贷款的等级为B,且借款人租住房屋。↩︎

  3. 可以采取多种策略。一种常见的策略是让每个学生对应一行,然后为每一项作业、测验或考试添加一列。在这种设置下,只需查看单独一行就能轻松了解某个学生的成绩历史。此外,还应设置包含学生信息的列,例如用一列来列出学生的姓名。↩︎

  4. 每个县都可以被视为一个案例,每个案例都记录了十一条信息。一张包含3,142行和14列的表格可以容纳这些数据,其中每一行代表一个县,每一列代表一条特定的信息。↩︎

  5. group 变量只能取两个组别名称中的一个,这使它成为分类变量。该 num_migraines 变量描述的是偏头痛发作次数的计数,这类结果可以合理地进行基本算术运算,这意味着这是一个数值型的结果;更具体地说,由于它表示一个计数, num_migraines 是一个离散的数值变量。↩︎

  6. 两个示例问题:(1) 贷款金额与总收入之间有什么关系?(2) 如果某人的收入高于平均水平,那么其利率往往会高于还是低于平均水平?↩︎

  7. 在某些学科中,习惯上将解释变量称为 自变量 ,而将响应变量称为 因变量。然而,这会变得令人困惑,因为一个 一对 变量可能相互独立,也可能相互依赖,因此我们避免使用这种表述。↩︎

  8. mcu_films 本练习中使用的数据可在 openintro R 包中找到。↩︎

  9. run17 本练习中使用的数据可在 cherryblossom R 包中找到。↩︎

  10. migraine 本练习中使用的数据可在 openintro R 包中找到。↩︎

  11. sinusitis 本练习中使用的数据可在 openintro R 包中找到。↩︎

  12. daycare_fines 本练习中使用的数据可在 openintro R 包中找到。↩︎

  13. biontech_adolescents 本练习中使用的数据可在 openintro R 包中找到。↩︎

  14. 插图作者 Allison Horst.↩︎

  15. smoking 本练习中使用的数据可在 openintro R 包中找到。↩︎

  16. usairports 本练习中使用的数据可在 airports R 包中找到。↩︎

  17. 本练习中使用的数据可以在 unvotes R 包中找到。↩︎

  18. ukbabynames 本练习中使用的数据可在 ukbabynames R 包中找到。↩︎

  19. netflix_titles 本练习中使用的数据可在 tidytuesdayR R 包中找到。↩︎

  20. 本练习中使用的数据来自 JSR 运载火箭数据库,2019年2月10日版.↩︎

  21. seattlepets 本练习中使用的数据可在 openintro R 包中找到。↩︎