Docsity

Appunti Statistics Bologna, Appunti di Statistica

Toggle sidebar
bg1
1
STATISTICS
LECTURE 1
The ai mis to consider a population, get a sample and study it. There are issues that can arise if you don’t do this
well.
CASE STUDY
• Objective: Evaluate the effectiveness of cognitive-behavior therapy for chronic fatigue syndrome.
• Participant pool: 142 patients who were recruited from referrals by primary care physicians and consultants
to a hospital clinic specializing in chronic fatigue syndrome. (very specific)
• Actual participants: Only 60 of the 142 referred patients entered the study. Some were excluded because they
didn’t meet the diagnostic criteria, some had other health issues, and some refused to be a part of the study.
(bias, voluntary response that leads to a limitation of the study).
Patients randomly assigned to treatment and control groups, 30 patients in each group:
• Treatment: Cognitive behavior therapy – collaborative, educative, and with a behavioral emphasis. Patients
were shown on how activity could be increased steadily and safely without exacerbating symptoms.
• Control: Relaxation – No advice was given about how activity could be increased. Instead progressive
muscle relaxation, visualization, and rapid relaxation skills were taught.
The table below shows the distribution of patients with good outcomes at 6-month follow-up. Note that 7 patients
dropped out of the study: 3 from the treatment and 4 from the control group.
Proportion with good outcomes in treatment group: 19/27 circa 0.70 -> 70%
Proportion with good outcomes in control group: 5/26 circa 0.19 -> 19%
This seems to suggest that treatment increases the good outcome, however this may be due to few different
reasons. The statistical question is what is more plausible by a statistical pov. The two main issues:
Do the data show a “real” difference between the groups? 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 fluctuation
is part of almost any type of data generating process. The observed difference between the two groups (70 - 19 =
51%) may be real, or may be due to natural variation. Since the difference is quite large, it is more believable that
the difference is real. We need statistical tools to determine if the difference is so large that we should reject the
notion that it was due to chance.
Are the results of this study generalizable to all patients with chronic fatigue syndrome?
These patients had specific characteristics and volunteered to be a part of this study, therefore they may not be
representative of all patients with chronic fatigue syndrome. While we cannot immediately generalize the results to
all patients, this first study is encouraging. The method works for patients with some narrow set of characteristics,
and that gives hope that it will work, at least to some degree, with other patients.
DATA BASICS
Variables are characteristics recorded for each case or observational unit in a data set. In the standard organization
of data using a data matrix, variables correspond to the columns.
Variables are generally classified into two primary groups: numerical and categorical.
• Numerical Variables
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Anteprima parziale del testo

Scarica Appunti Statistics Bologna e più Appunti in PDF di Statistica solo su Docsity!

STATISTICS

LECTURE 1

The ai mis to consider a population, get a sample and study it. There are issues that can arise if you don’t do this

well.

CASE STUDY

  • Objective: Evaluate the effectiveness of cognitive-behavior therapy for chronic fatigue syndrome.
  • Participant pool: 142 patients who were recruited from referrals by primary care physicians and consultants

to a hospital clinic specializing in chronic fatigue syndrome. (very specific)

  • Actual participants: Only 60 of the 142 referred patients entered the study. Some were excluded because they

didn’t meet the diagnostic criteria, some had other health issues, and some refused to be a part of the study.

(bias, voluntary response that leads to a limitation of the study).

Patients randomly assigned to treatment and control groups, 30 patients in each group:

  • Treatment: Cognitive behavior therapy – collaborative, educative, and with a behavioral emphasis. Patients

were shown on how activity could be increased steadily and safely without exacerbating symptoms.

  • Control: Relaxation – No advice was given about how activity could be increased. Instead progressive

muscle relaxation, visualization, and rapid relaxation skills were taught.

The table below shows the distribution of patients with good outcomes at 6-month follow-up. Note that 7 patients

dropped out of the study: 3 from the treatment and 4 from the control group.

Proportion with good outcomes in treatment group: 19/27 circa 0.70 - > 70%

Proportion with good outcomes in control group: 5/26 circa 0.19 - > 19%

This seems to suggest that treatment increases the good outcome, however this may be due to few different

reasons. The statistical question is what is more plausible by a statistical pov. The two main issues:

Do the data show a “real” difference between the groups? 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 fluctuation

is part of almost any type of data generating process. The observed difference between the two groups (70 - 19 =

51%) may be real, or may be due to natural variation. Since the difference is quite large, it is more believable that

the difference is real. We need statistical tools to determine if the difference is so large that we should reject the

notion that it was due to chance.

Are the results of this study generalizable to all patients with chronic fatigue syndrome?

These patients had specific characteristics and volunteered to be a part of this study, therefore they may not be

representative of all patients with chronic fatigue syndrome. While we cannot immediately generalize the results to

all patients, this first study is encouraging. The method works for patients with some narrow set of characteristics,

and that gives hope that it will work, at least to some degree, with other patients.

DATA BASICS

Variables are characteristics recorded for each case or observational unit in a data set. In the standard organization

of data using a data matrix , variables correspond to the columns.

Variables are generally classified into two primary groups: numerical and categorical.

  • Numerical Variables

A variable is considered numerical if it takes a wide range of numerical values and if arithmetic operations, such as

adding, subtracting, or calculating averages, are sensible for those values. Numerical variables are further divided

based on the nature of their values:

  • Discrete Numerical Variables: These variables can only take specific numerical values with jumps, often

representing counts. They usually take whole non-negative numbers (e.g., 0, 1, 2, ...). An example is the

population count (pop) or the number of siblings.

  • Continuous Numerical Variables: These variables can take any value within a given range, varying

continuously (e.g., height, income, rates).

  • Categorical Variables

A variable is considered categorical if its responses are defined as categories. The possible values a categorical

variable can take are called the variable's levels.

Categorical variables can be sub-classified by whether their levels have a natural ordering:

  • Regular Categorical Variables: These are regular categorical variables that do not have an inherent special

ordering (also called unordered categorical). An example is the US state where a borrower resides (state).

  • Ordinal Variables: These variables are categorical, but their levels have a natural ordering. The variable

median edu, which takes values like below hs , hs diploma , some college , or bachelors , is an example of an

ordinal variable. For simplifying analyses, ordinal variables are often treated as nominal (unordered

categorical).

Many statistical analyses are motivated by finding a relationship between two or more variables.

  • Associated or Dependent Variables: When two variables show some connection or discernible pattern with

one another, they are called associated variables.

  • Independent Variables: If two variables are not associated, they are considered independent, meaning

there is no evident relationship between them. A pair of variables must be either associated or

independent, but not both.

When researchers suspect a causal connection —that a change in one variable might affect another they assign the

roles of explanatory and response variables:

  • Explanatory Variable: The variable suspected of causing or affecting another variable.
  • Response Variable: The variable that is potentially affected or influenced by the explanatory variable.

It is important to remember that simply labeling variables as explanatory or response does not guarantee a causal

relationship exists; association does not imply causation , and causal conclusions can only be reliably inferred from

a randomized experiment.

Variables in statistics act like coordinates on a map: some, like continuous numerical variables, allow movement

anywhere within a range (like longitude/latitude), while others, like discrete numerical variables, only allow

movement in specific, countable steps (like house numbers). Categorical variables, on the other hand, define

regions or types (like states or zones). Understanding these differences determines which mathematical tools can

be used to navigate and interpret the data.

What type of variable is a telephone area code? (b) numerical, discrete

DATA COLLECTION PRINCIPLES

Research question: Can people become better, more efficient runners on their own, merely by running? Sample:

Group of adult women who recently joined a running group. The conclusion cannot be generalized to everyone, but

only to the group of adult women who has joined the running group; not men, children, or all adult women. If the

conclusion is valid for this group we can speculate that the conclusion could be valid for evedryone, but there is the

need to extend the study to confirm.

Anti-smoking research started in the 1930s and 1940s when cigarette smoking became increasingly popular. While

some smokers seemed to be sensitive to cigarette smoke, others were completely unaffected. Anti-smoking

research was faced with resistance based on anecdotal evidence such as “My uncle smokes three packs a day and

he’s in perfectly good health”, evidence based on a limited sample size that might not be representative of the

population. It was concluded that “smoking is a complex human behavior, by its nature difficult to study,

these 1,200 surveys that were completed, 960 agreed with the policy change and 240 disagreed. Which of the

following statements are true?

I. Some of the mailings may have never reached the parents.

II. The school district has strong support from parents to move forward with the policy approval.

III. It is possible that majority of the parents of high school students disagree with the policy change.

IV. The survey results are unlikely to be biased because all parents were mailed a survey.

(a) Only I (b) I and II (c) I and III (d) III and IV (e) Only IV

Observational studies and experimental studies (also interventions)

The two primary methods researchers use to collect data and investigate relationships between variables. They

differ fundamentally in how data is collected and what conclusions can be drawn, particularly regarding causality.

  • Observational study :

Researchers collect data in a way that does not directly interfere with how the data arise, i.e. they merely “observe”,

and can only establish an association between the explanatory and response variables. Data collection methods

include information via surveys, reviewing medical records, or following a cohort of similar individuals (e.g., the

Nurses’ Health Study). Observational studies can provide evidence of a naturally occurring association between

variables, meaning they show a connection or discernible pattern. Crucially, observational studies cannot by

themselves show a causal connection. Making causal conclusions based on observational data is considered

treacherous and is not recommended.

The association might be explained by a confounding variable (or lurking variable) that is correlated with both the

explanatory and response variables, which is difficult or impossible to measure or eliminate in an observational

setting. For example, finding an association between increased sunscreen use and skin cancer does not mean

sunscreen causes cancer; the confounding variable of sun exposure likely explains the relationship.

Confounding variables are central to the critical limitation of observational studies. Observational studies, where

researchers collect data without directly interfering, can only provide evidence of a natural association between

variables. Making causal conclusions based on such data is generally considered treacherous and is not

recommended. The presence of a confounding variable means that an observed association might be explained not

by a direct causal link between the explanatory and response variables, but by the influence of the unmeasured

confounding variable. This is why the principle holds that association does not imply causation. Although one

strategy to try and justify causal conclusions from an observational study is to exhaust the search for confounding

variables, there is no guarantee that all confounding variables can be examined or measured

  • Experiment:

Researchers randomly assign subjects to various treatments in order to establish causal connections between the

explanatory and response variables. Establishing Causation:

  • Randomized Experiment: When individuals are randomly assigned to different groups, the experiment is

called a randomized experiment. This method is the gold standard for data collection.

  • Causality: Only a randomized experiment allows researchers to reliably infer causation (that a change in

one variable causes a change in another).

Key Components of an Experiment:

(a) Explanatory Variable and Response Variable: The explanatory variable is the one suspected of causing or

affecting the response variable.

(b) Treatment Group: The group that receives the intervention being tested (e.g., a stent and medical

management).

(c) Control Group: A group that receives either no treatment or a placebo, providing a reference point against

which the medical impact of the treatment group can be measured.

Randomized experiments are generally built on four principles:

  1. Controlling: Researchers attempt to minimize or manage any other differences between the groups

besides the assigned treatment.

  1. Randomization: This procedure assigns patients into treatment groups to prevent accidental bias from

entering the study and helps to even out differences in variables that cannot be explicitly controlled (like

dietary habits or inherent susceptibility to disease).

  1. Replication: Collecting a sufficiently large sample ensures a more accurate estimate of the effect of the

explanatory variable on the response. Replication also refers to a group of scientists verifying an earlier

finding.

  1. Blocking: This advanced strategy involves first grouping individuals based on a variable known or

suspected to influence the response (e.g., low-risk vs. high-risk patients for heart attacks) into blocks, and

then randomly assigning treatments within those blocks. This ensures that each treatment group has an

equal representation of patients from these critical categories.

Feature Observational Study Experimental Study (Randomized)

Intervention

Researchers do not interfere; they observe

existing data.

Researchers assign treatments to cases.

Causal

Conclusion

Can only establish association (correlation);

association does not imply causation.

Can infer causation because of

randomization and control.

Primary Risk

Confounding variables (lurking variables) that

cannot be controlled or measured.

Bias introduced by expectations (resolved

through blinding and placebo).

If you’re going to walk away with one thing from this class, let it be “correlation does not imply causation”.

What type of study is this, observational study or an experiment?

“Girls who regularly ate breakfast, particularly one that includes cereal, were slimmer than those who skipped the

morning meal, according to a study that tracked nearly 2,400 girls for 10 years. [...] As part of the survey, the girls

were asked once a year what they had eaten during the previous three days.” What is the conclusion of the study?

Who sponsored the study?

This is an observational study. 3 possible explanations:

1. Eating breakfast causes girls to be thinner. (causal explanation)

2. Being thin causes girls to eat breakfast. (causal explanation in opposite direction)

3. A third variable is responsible for both. What could it be? An extraneous variable that affects both the

explanatory and the response variable and that make it seem like there is a relationship between the two

are called confounding variables. (confunding variable, no causal relation).

To answer and find the real explanation you will need to do an experimental study.

EXAMINING NUMERICAL DATA

DOT PLOTS

Useful for visualizing one numerical variable. Darker colors represent areas where there are more observations.

The mean , also called the average (marked with a triangle in the above plot), is one way to measure the center of a

distribution of data. The mean GPA is 3.59.

The sample mean is a type of sample statistic. A sample statistic is a value that is calculated based on the

observed sample. A sample is defined as a subset of the cases chosen from the population. It does not represent

the whole population. The population mean is an example of a population parameter. A population parameter is a

numerical value that describes a characteristic of the entire group of cases that the research question refers to,

known as the population.

With a frequency distribution, the mean is computed as

Moreover, a very useful identity follows naturally from the definition

of the mean. To simplify, consider to have raw data.

CONTINUOS VARIABLES

Continuous numerical variables are a specific type of numerical variable that can take any value within a given

range and vary continuously. A continuous numerical variable does not take

values with specific jumps; rather, its values flow smoothly across an interval.

Like all numerical variables, it is sensible to perform arithmetic operations—

such as adding, subtracting, or taking averages—with the values of a

continuous variable. Continuous variables belong to the broader category of

numerical variables. The overall classification breakdown shows that all

variables can be divided into numerical or categorical, and numerical variables

are further divided into continuous and discrete. You usually make

bins/intervals.

If we do not have the raw data, the mean can be only approximated. It is computed as

Where ci is a value in the bin (xi1,xi], typically (xi1 +xi)/2.

You can plot that variable with a HISTOGRAM

Histograms provide a view of the data density. Higher bars represent where the data are relatively more common.

Histograms are especially convenient for describing the shape of the data distribution.

The height of bars is proportional to the frequency of the

corresponding bin.

If the frequency of the bin (xj1,xj] is nj then the corresponding

bar can be fixed to have height equal to

!"#

(at exam, what information you can get out of this image? Histogram = sketch similar boxplot, or sketch histogram

from boxplot).

Histograms summarize information, depending on the width you get different information. The chosen bid widths

can alter the story the histogram is telling. Some may show too much or too little information. Unlike a data table,

which shows every individual value, a histogram is not meant to display all information directly. Instead, it offers a

simplified visual representation, so the full detail of the table should not be expected to transfer into the histogram.

The idea is a summary.

Modality:

  • Unimodal: The histogram has one clear peak—a single region where the bars are noticeably higher than

the rest.

  • Bimodal: The histogram has two prominent peaks, often suggesting two different subgroups or processes

in the data.

  • Multimodal: The histogram has three or more peaks, indicating a more complex distribution.
  • Uniform: The bars are roughly the same height, so no peaks stand out; the distribution is flat.

In order to determine modality, step back and imagine a smooth curve over the histogram – imagine that the bars

are wooden blocks and you drop a limp spaghetti over them, the shape the spaghetti would take could be viewed

as a smooth curve.

To determine the skewness of a histogram, look at how the data tail extends:

  • Right-skewed (positively skewed): The tail extends to the right (toward larger values). Most data are piled

on the left.

  • Left-skewed (negatively skewed): The tail extends to the left (toward smaller values). Most data are piled on

the right.

  • Symmetric: The histogram is balanced on both sides, with tails of roughly equal length. A symmetric

distribution often looks bell-shaped, but it doesn’t have to.

Histograms are said to be skewed to the side of the long tail.

To check for unusual observations or potential outliers in a histogram, look for features like:

  • Isolated bars: One or more bars that sit far away from the main cluster of data.
  • Long, thin tails: A stretch of very low bars on one side that might indicate extreme values.
  • Gaps: A noticeable empty region between the main group of bars and a bar farther out.

If any of these appear, they may suggest outliers or unusual observations.

LECTURE 2

Which of these variables do you expect to be uniformly

distributed?

(a) weights of adult females (symmetric unimodal possibly)

(b) salaries of a random sample of people from North Carolina

(right skew)

(c) house prices (right skew)

(d) birthdays of classmates (day of the month) (uniform)

VARIABILITY

Variability refers to the extent to which values

differ from one another. Variability can also be

thought of as how much values differ from their

mean, that is how spread out a distribution is.

The terms variability, spread, and dispersion are

synonyms.

Example: same mean, different dispersion.

Depending on varibility the mean may not be

very representative of the sample.

A measure of dispersion must start by looking at the deviation, which is the distance of an observation from the

mean. Averaging these deviations results in zero, a consequence of the mean acting as the balancing point of the

distribution. Squared deviations : by using these squared deviations, the sources define the primary measure of

dispersion: the variance. The variance is defined as the average squared distance from the mean.

Squaring the deviations achieves two primary goals:

  1. Eliminating Negative Signs: It removes negative signs from the deviations, ensuring that observations far

below the mean contribute positively to the overall measure of spread.

  1. Magnifying Large Differences: It makes observations that are far away from the mean (large deviations)

relatively much larger than observations close to the mean.

The population variance is a parameter given by

The concepts of median, Interquartile Range (IQR), first quartile (Q1), and third quartile (Q3) are all measures used

to describe the center and variability of numerical data, particularly when using a box plot.

  • If there is an odd number of observations , the median is the single observation right in the middle that

splits the data.

  • If there is an even number of observations (like the 50 loans in the dataset), there will be two values in the

middle, and the median is taken as the average of those two middle observations

Quartiles (Q1 and Q3)

The quartiles mark the boundaries of the middle 50% of the data.

  • First Quartile (Q1):

o Definition: Q1 is the 25th percentile.

o Location: 25% of the data falls below this value.

o Box Plots: Q1 forms the lower boundary of the box in a box plot.

o Relationship to Median: 25% of the data falls between Q1 and the median.

  • Third Quartile (Q3):

o Definition: Q3 is the 75th percentile.

o Location: 75% of the data falls below this value.

o Box Plots: Q3 forms the upper boundary of the box in a box plot.

o Relationship to Median: 25% of the data falls between the median and Q3.

Interquartile Range (IQR)

The IQR is a measure of variability or spread in the data, analogous to the standard deviation.

  • Definition: The IQR is the length of the box in a box plot. It represents the spread of the middle 50% of the

data.

  • Calculation: The IQR is computed as the difference between the third quartile (Q3) and the first quartile
  • Variability: Data sets with larger variability tend to have a larger IQR.
  • Robustness: The IQR is a robust statistic because it is only sensitive to numbers near Q1 and Q3, meaning

extreme observations (outliers) have little influence on its value.

  • Outlier Detection: The IQR is used to define the reach of the whiskers on a box plot, as the whisker's reach

is never allowed to be more than 1.5 beyond the box boundaries (Q1 or Q3). Any observation outside this

range is flagged as an outlier.

  • The 25th percentile is also called the first quartile, Q1.
  • The 50th percentile is also called the median.
  • The 75th percentile is also called the third quartile, Q3.
  • Between Q1 and Q3 is the middle 50% of the data. The range these data span is called the interquartile

range, or the IQR.

IQR = Q3 - Q

The box in a box plot represents the middle 50% of the data, and the thick line in the box is the median. Need one

numerical variable. The box plot is a visualization tool used to

summarize a numerical data set using five key statistics,

while also identifying potential unusual Aobservations. It is

often displayed alongside other plots, like a vertical dot plot,

to provide a complete view of the data.

Components and Construction

The construction of a box plot relies on five main statistics:

  1. Median: The first step in building a box plot is drawing a

dark line inside the box to denote the median. The median is

the observation that splits the ordered data exactly in half

(the 50th percentile).

  1. The Box ( Q 1 to Q 3 ): A rectangle is drawn to represent the

middle 50% of the data.

  • The lower boundary of this box is the first quartile ( Q 1 ) (the 25th percentile, meaning 25% of the data

falls below this value).

  • The upper boundary of this box is the third quartile ( Q 3 ) (the 75th percentile).
  1. Interquartile Range (IQR): The total length of the box is called the Interquartile Range (IQR), which is calculated

as Q 3 − Q 1. The IQR is a measure of variability.

  1. Whiskers: Lines, called whiskers, extend out from the box to capture the data outside of the middle 50%.
    • The whiskers' reach is never allowed to be more than 1.5×IQR beyond the box boundaries ( Q 1 or Q 3).

They capture everything within this limit.

  1. Outliers: Any observation lying beyond the whiskers (outside the 1.5×IQR range) is labeled with a dot and

classified as an outlier. The purpose of labeling these points separately is to identify observations that appear

unusually distant from the rest of the data.

Uses and Advantages of Box Plots

  • Summarizing Data: Box plots summarize data using the five key statistics (minimum, Q 1, median, Q 3,

maximum whisker reach).

  • Identifying Outliers: They are specifically designed to help identify any observations that appear to be

unusually distant from the rest of the data. For example, for the loan interest rate data, rates of 24.85% and

26.30% were identified as outliers.

  • Comparing Groups: Box plots are a traditional and convenient tool for comparing numerical data across

groups using a single graph, such as side-by-side box plots. They are especially useful for comparing centers

(medians) and spreads (IQRs) between groups.

Mean pushed towards the tail due to large values

that have big impact.

Extremely large values, median and iqr do not

change. The mean is a affected, moving to 309k,

as consequence of 1 individual change. Similar

for standard diviation, it goes up from 200k to

800k - > variability has increased esponencially, but in reality only one is extremely large, one unusual income that

has major impact.

If we move the smallest to 10m, median and iqr shift only a little or stay the same. Mean and standard diviation

change a lot.

If the distribution is symmetric, center is often defined as the mean: mean

overlapping with median. Standard deviations is a good representation of

variability in the data.

If the distribution is skewed or has extreme outliers, center is often defined as the median

  • Right-skewed: mean > median
  • Left-skewed: mean < median

The right one is b) as the mean follows more the tail (influenced by

extreme values) than the median.

Contingency tables

The contingency table is a foundational tool used to summarize and analyze data for two categorical variables.

Each value within the contingency table represents the number of times a particular combination of variable

outcomes occurred. Contingency tables typically include row and column totals.

o Row totals provide the total counts across each row.

o Column totals provide the total counts down each column.

For example, a contingency table from the source material summarizes the app type (individual or joint) and

homeownership (rent, mortgage, or own) variables for 10,000 loans:

homeownership rent mortgage own Total (Row Totals)

individual 3496 3839 1170 8505

joint 362 950 183 1495

Total (Column Totals) 3858 4789 1353 10000

  • The number 3496 represents the number of loans where the borrower rents their home and the

application type was by an individual.

  • The row total 8505 is the sum of all individual applications (3496 + 3839 + 1170).

Contingency tables, especially when converted to proportions, are essential for determining if two categorical

variables are associated (related) or independent.

  • Checking for Association: If the proportions vary between the different levels of a variable, it provides

evidence that the two variables are associated.

o For instance, if the fraction of loan applications made by individuals varies significantly across the

three levels of homeownership (rent, mortgage, own), then the variables are associated.

  • Explanatory vs. Response Variables: When there is a clear explanatory-response relationship between the

variables (e.g., email format might explain spam status), it is usually most useful to "condition" on the

explanatory variable and compute the relative frequencies (proportions) for that variable.

A bar plot is a fundamental type of graph

used primarily to display and summarize

categorical data. It is one of the most

common and effective ways to visualize

frequencies or proportions of a single

categorical variable or to compare two

categorical variables simultaneously.

A relative frequencies bar plot is a type of

bar plot that visualizes the proportions of

observations within each category of a categorical variable. In statistical contexts, "relative frequency" is

synonymous with proportion.

Standardized Stacked Bar Plot , which, along with the Mosaic Plot , are specialized visualization techniques used to

summarize the relationship between two categorical variables based on data from a contingency table. Both plots

are designed to help determine if the two categorical variables are associated (related).

Standardized Stacked Bar Plot (Segmented Bar Plot)

A stacked bar plot is a graphical display where bars, grouped by one categorical variable, are divided (segmented)

by the levels of a second categorical variable. The standardized version is particularly effective for comparison; this

plot takes the column or row proportions from a contingency table and translates them into a bar plot where every

bar reaches the same height (1.0 or 100%).

Mosaic Plot

The mosaic plot is a refined visualization technique specifically designed for contingency tables that incorporates

the benefits of the standardized stacked bar plot while retaining information about group size.

  • Construction Process:
    1. First Split (Width): A square is first broken into columns corresponding to the categories of the

primary variable (e.g., homeownership). The column widths correspond to the proportion of loans

(the relative size) in each of those categories. This ensures that the viewer can see the relative

group sizes of the primary variable.

  1. Second Split (Height): Each column is then further divided (segmented) using the second variable

(e.g., app type). The segments within each column are proportional to the number of cases in that

group combination.

  • Box Area: In a mosaic plot, the area of each resulting box represents the number of cases (the frequency)

in that specific combination of categories.

  • Association Check: Like the standardized stacked bar plot, an association between the variables is

indicated if the columns are divided (segmented) at different vertical locations.

  • Explanatory Variable: If there is a clear explanatory-response relationship between the variables, it is

common to use the explanatory variable to determine the first split (the column widths).

In essence, the mosaic plot improves upon the standardized stacked bar plot by using the width of the columns to

represent the overall size of the groups, which is information lost in the standardized bar plot.

The pie chart is a method for visualizing individual categorical data, though it is explicitly noted that they are not

the preferred visualization tool. Pie charts can be useful for giving a high-level

Side-by-side box plots are a traditional and convenient

graphical tool specifically designed for comparing

numerical data across two or more groups using a single

plot. When conducting investigations that require

examining numerical data across groups, all that is

required is to make a numerical plot (like a box plot) for

each group in the same graph. A side-by-side box plot

places two or more box plots, one for each group being

compared, into one plotting window and draws them on

the same scale. Side-by-side box plots are especially useful

for quickly comparing key features of the distributions across different groups: They are highly effective for

comparing the centers of the groups (specifically the medians, which are marked by the dark line inside each box).

They are also very useful for comparing the spreads (variability) of the data, primarily by comparing the length of

the Interquartile Range (IQR) for each box.

Does there appear to be a relationship between class year and number of clubs students are in?

If you look at the median is roughly stable, the 25% percentile is quite stable, …

In the sample, in the first year the median is 2 clubs, half of students are btw the 25% and 75%, which is btw 1

and 3, and some above and below. No particularly strong trend, only noise.

RELATIONSHIP AMONG VARIABLES

The relationship among variables is a central focus of data analysis, involving techniques to summarize, visualize,

and test for connections between two or more variables.

The concepts of association and dependence are fundamentally related in statistics, especially when analyzing the

relationship between two variables.

Based on the sources, here is how the concepts of association and independence (the complement of dependence)

are explained and applied, particularly when examining categorical variables:

o If the proportions vary between the different levels of a variable, it provides evidence that the two

variables are associated.

  • Explanatory vs. Response: If one variable is clearly the explanatory variable (e.g., email format) and the

other is the response variable (e.g., spam status), it is usually most useful to "condition" on the explanatory

variable and compute the relative frequencies (proportions) for that variable.

  • Visualizations: Relationships between two categorical variables are visualized using:

o Stacked Bar Plots

o Side-by-Side Bar Plots

o Standardized Stacked Bar Plots: These plots standardize bar height (to 100%) to emphasize the

relative frequencies for checking association.

o Mosaic Plots: These plots, which resemble standardized stacked bar plots, use box area to

represent the number of cases in each category combination and check for association by seeing

if the columns are divided at different vertical locations.

3. Relationship Between One Numerical and One Categorical Variable (Comparing Groups)

To compare a numerical variable across groups defined by a categorical variable, the sources recommend:

  • Side-by-Side Box Plots: This traditional method places a box plot for the numerical data for each group

into one plotting window on the same scale. They are especially useful for comparing the centers

(medians) and spreads (IQRs) of the distributions across groups.

  • Hollow Histograms: These are the outlines of histograms for each group placed on the same plot. They are

more useful than box plots for seeing the distribution shape, skew, and potential anomalies of each group.

4. Inferring Causal Relationships

When analyzing relationships, the type of study dictates whether a causal relationship can be inferred:

  • Experiments: Since patients are randomly assigned to experiment groups, results from an experiment can

be used to evaluate a causal relationship between variables (e.g., whether a vaccine affected the rate of

infection).

  • Observational Data: When using observational data (like comparing median household income across

counties with or without population gain), researchers must remember that a causal connection cannot be

firmly established.

The relationship among variables is often assessed by comparing observed differences against the expected

differences if the variables were independent (the H_0 or independence model). Tools like randomization and

simulation can be used to determine if the observed difference is due to chance or represents a real relationship.

SCATTERPLOT

A scatterplot is a graphical display that provides a case-

by-case view of data for two numerical variables.

  • Data Type: Scatterplots are used specifically to

examine the relationship between two numerical

variables.

  • Structure: In a scatterplot, each individual

point represents a single case (or observation) in the

data set.

Scatterplots are helpful in quickly spotting associations

that relate variables. These associations can be simple

trends or more complex relationships.

Types of Associations Revealed

Scatterplots can reveal different types of associations

between variables:

  • Positive Association : As one variable

increases, the other tends to increase.

  • Negative Association : As one variable increases, the other tends to decrease.
  • Linear Association: The relationship follows a straight trend.
  • Nonlinear Association: The relationship shows curvature in the trend.
  • Horseshoe-Shaped Association: A complex nonlinear relationship where a variable (e.g.,

health/productivity) is good only in moderation relative to another (e.g., water consumption/stress).

  • No Association/Independence: When no relationship is apparent, the variables may be independent.

Is it reasonable to assume that there is a causal effect btw life expectancy and total fertility? Is it totally

unreasonable and most probably there is a confunder = wealth.

Does there appear to be a relationship between GPA

and number of hours students study per week? Can

you spot anything unusual about any of the data

points?

Studying more does not really increase GPA. This is not

an intervention study, is an observational study. In this

case maybe people studying less actually need to study

few hours than others.

Based on the scatterplot on the right, which of the following

statements is correct about the head and skull lengths of

possums?

  1. Head length and skull width are positively

associated.

Duration of eruption and waiting time btw eruptions. Trend is positive

as the line goes up.

Eruptions with longer duration have longer waiting time btw eruptions.

Not sure the causal effect but understand the connection btw data.

Quality control. Each indicates a measurement on daily basis.

Two variables as scatterplots helps checking association btw variables.

Input and quality charachteristics: negative trend, when you produce more

the quality of the individual product goes down.

No causal relationship but reasonable association.

trend can be more clearly modeled. Once a trend is identified, one might be interested in fitting a trend line (a

statistical model, such as a regression line) to the data.

EXERCISE 1.

Exercise 1.1 presents a scenario based on a randomized controlled study designed to investigate whether

acupuncture relieves migraine pain.

  • Objective: To determine the efficacy of acupuncture specifically designed to treat migraines.
  • Study Design: A randomized controlled study was conducted (experimental study, intervention)
  • Subjects: 89 females diagnosed with migraine headaches.
  • Groups:

o Treatment Group: 43 patients received acupuncture specifically designed for migraines.

o Control Group: 46 patients received placebo acupuncture (needle insertion at non-acupoint

locations).

  • Outcome: 24 hours after treatment, patients were asked if they were pain free.
  • Results (Contingency Table): The results are summarized in a contingency table:

Pain free (Yes) Pain free (No) Total

Treatment Group 10 33 43

Control Group 2 44 46

Total 12 77 89

(a) What percent of patients in the treatment group were pain free 24 hours after receiving acupuncture?

The treatment group had 43 patients, and 10 were pain free. 10/43=23%

(b) What percent were pain free in the control group?

The control group had 46 patients, and 2 were pain free. 2/46=4%

(c) In which group did a higher percent of patients become pain free 24 hours after receiving acupuncture?

The Treatment group had a higher percentage (23.26%) of patients who were pain free compared to the Control

group (4.35%). Suggests acupunture works. Observe association btw the 2 variables.

(d) 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 that can be drawn based on your findings so

far. 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?

We can conclude that there is a causal effect because the study is experimental, where the people were randomly

allocated. Because this was done at random that means that at the start of the study those two groups are on average

in terms of symptoms, in terms of characteristics they have, which are important for the study. The only difference

that there is between groups is a treatment. Other than that, the two groups are similar. Therefore, it's extremely

unlikely that there is a confounder, because the confounder will be on average, will have the same effect in the two

groups. (a cofounder could be like the strength of the symptoms and if your symptoms are very strong then its

unlikely you are pain free after 1 treatment). In the two groups the only difference is due to the treatment, we can

actually conclude that there is a causal relation = if you get the treatment increases the probability you are pain free.

Since this was a randomized controlled study, the other major alternative explanation for the observed difference is

that the difference is due entirely to randomness. Although the percentages are different (23.26% vs. 4.35%), it is

possible that the difference is simply the result of random fluctuation in the data generating process. Even if the

study allows to assess causal relationship; is there really a difference? The statistical question would be if is that real

difference or if maybe it is just due to variability.

It's very unlikely that it's due to random noise and the reason is that it's very large difference from 4 to 23% and it is

unlikely it is due to randomness and probably it is a real difference.

When determining the relationship between variables, the explanatory variable is the one suspected of causing a

change, and the response variable is the outcome that may be affected. Since this was an experiment where the

researchers assigned the treatments, we can identify these roles clearly:

  • Explanatory Variable (Treatment/Cause): The type of acupuncture received by the patient.

o Levels: The source material indicates two levels: 1) Treatment group (specific migraine

acupuncture) and 2) Control group (placebo acupuncture).

  • Response Variable (Outcome/Effect): Whether the patient was pain free 24 hours after receiving

acupuncture.

o Levels: This variable is categorical, taking values of "Yes" (pain free) or "No" (not pain free).

The explanatory variable is the variable that is suspected of causing or influencing a change in another variable

(implies causation).

The response variable is the variable that measures the outcome of interest or the result that may be affected by

the explanatory variable.

The reference population (or target population) is the larger group to which the researchers wish to generalize

their findings. The study subjects were females diagnosed with migraine headaches who were experiencing a

migraine attack that started no more than four hours prior to enrollment. Therefore, the reference population for

this study is all females diagnosed with migraine headaches who might consider this specific acupuncture

treatment. The results can only be applied to the population represented by the sample, which in this case is highly

specific: females with migraines examined at a particular headache center in Turin University. The generalized

population of interest for researchers conducting this randomized experiment would be all people with migraine

headaches who have the potential to receive this treatment, provided the results can be shown to be generalizable,

though the current study only samples females.

You can speculate that, because this treatment was successful in females with diagnosed migraine headaches,

similar results might also occur in other groups. However, the reference population is females with a confirmed

diagnosis, so we cannot draw conclusions about women without a diagnosis, nor about men. While it is reasonable

to assume that men might also benefit from the treatment, this cannot be concluded from the available data.

Population sampling = the entire group of interest is the population (e.g., all Duke graduates in the last 5 years),

and the smaller group selected for review is the sample (e.g., the graduates selected). Researchers always seek to

randomly select a sample from a population to reduce the chance of introducing biases.

Simple Random Sample (SRS): This is the most basic type of random selection, equivalent to conducting a raffle.

In a simple random sample, each case in the population has an equal chance of being included in the final

sample, and the selection of one case provides no useful information about which other cases are included.

Bias: Bias is introduced when the sample selection method is flawed, often unintentionally. For example, if a

student majoring in nutrition selects graduates for a study, they might inadvertently pick a disproportionate

number of graduates from health-related fields , creating a biased sample. Random sampling helps to resolve this

problem.

Non-response Bias: Even if people are randomly selected (e.g., for surveys), a high non-response rate (e.g., only

30% respond) means the results may not be

representative of the entire population, as the

population actually sampled is incomplete.

Convenience Sample: This is a common downfall

where individuals who are easily accessible are

more likely to be included in the sample, which

often makes it difficult to discern what sub-

population the sample truly represents.

EXERCISE 1.

Scientific study conducted to determine the effectiveness of the Buteyko method (a shallow breathing technique)

in reducing asthma symptoms and improving the quality of life for asthma patients who rely on medication.

  • Study Design: A randomized experiment was performed.
  • Subjects: 600 asthma patients aged 18-69 who relied on medication for asthma treatment.