Docsity

Data Analysis - introductive theoretical part, Appunti di Analisi Dei Dati

Toggle sidebar
bg1
DATA ANALYSIS
There’s has been many changes in data analysis over time (from a punch card with a kind of a
binary code, with which a different combination gives different outcomes). This type of technology
is now used in different fields (from industries to hospitals or research).
Research means: ask questions, have answers, ask why you obtain a certain result
Data process:
-Information gathering: collection of data, gain of information which will be organize into data.
- Surveys, experiments and direct observation: direct presence of the researcher
- Police records, census materials, hospital files: already exists, some else already collected
the information (these information could be worst just because the people who collected
them hadn’t in mind the research porpoise)
How you organize the data decide what type of research you are doing both quantitative and
qualitative can use different types of data collection
- Observations
-Data: usually organize in rows and columns, some of them are specific asked (age or
education) other are just general (the year you are taking the survey)
Statistics: consists of a body of methods for obtaining and analysing data. It provides methods for:
-Design: planning how to obtain data
-Description: summarizing the data (a type of statistical analysis)
-Inference: making prediction based on the data, a type of statistical analysis (generalize from
the sample to the population, to do that you can build an inter-vole or a range of values where
there’s the value of the population. Of course passing from the sample to the population isn’t
easy so this range is considered as a margin of error)
Terminology:
-Subjects: entities that are observed in a study (could be people but also animals)
-Population: total set of subjects of interest in a study (the ultimate goal is to know something
about populations)
-Sample: subset of the population on which the study collects the data
(it is almost always necessary and more practical to observe samples
from population)
Different types of statistics:
-Descriptive statistics: summarize information from collected data (usually a sample, but also
populations). We summarize the information using a statistic.
-Inferential statistics: provide predictions about a population, based on data from a sample of
that population. A numerical summary of a population is given by a parameter (considered an
idea, you can’t know them in the most cases, you know it in few cases ex. voting pole). Ex. you
do an inference when you taste a little spaghetti to figure out if the whole packed is cooked; of
course if we are taking into consideration people is more difficult because we are not identical.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Anteprima parziale del testo

Scarica Data Analysis - introductive theoretical part e più Appunti in PDF di Analisi Dei Dati solo su Docsity!

DATA ANALYSIS

There’s has been many changes in data analysis over time (from a punch card with a kind of a

binary code, with which a different combination gives different outcomes). This type of technology

is now used in different fields (from industries to hospitals or research).

Research means: ask questions, have answers, ask why you obtain a certain result

Data process :

  • Information gathering : collection of data, gain of information which will be organize into data.
    • Surveys, experiments and direct observation: direct presence of the researcher
    • Police records, census materials, hospital files: already exists, some else already collected

the information (these information could be worst just because the people who collected

them hadn’t in mind the research porpoise)

How you organize the data decide what type of research you are doing both quantitative and

qualitative can use different types of data collection

- Observations

  • Data : usually organize in rows and columns, some of them are specific asked (age or

education) other are just general (the year you are taking the survey)

Statistics : consists of a body of methods for obtaining and analysing data. It provides methods for:

  • Design : planning how to obtain data
  • Description : summarizing the data (a type of statistical analysis)
  • Inference : making prediction based on the data, a type of statistical analysis (generalize from

the sample to the population, to do that you can build an inter-vole or a range of values where

there’s the value of the population. Of course passing from the sample to the population isn’t

easy so this range is considered as a margin of error)

Terminology:

  • Subjects : entities that are observed in a study (could be people but also animals)
  • Population : total set of subjects of interest in a study (the ultimate goal is to know something

about populations)

  • Sample : subset of the population on which the study collects the data

(it is almost always necessary and more practical to observe samples

from population)

Different types of statistics:

  • Descriptive statistics : summarize information from collected data (usually a sample, but also

populations). We summarize the information using a statistic.

  • Inferential statistics : provide predictions about a population, based on data from a sample of

that population. A numerical summary of a population is given by a parameter (considered an

idea, you can’t know them in the most cases, you know it in few cases ex. voting pole). Ex. you

do an inference when you taste a little spaghetti to figure out if the whole packed is cooked; of

course if we are taking into consideration people is more difficult because we are not identical.

A variable is a characteristic that can vary in value among subjects in a sample or population (ex.

age, gender, education, had covid or no). Distinguish variables to persuade different methods.

  • Quantitative variables : the measurement scale has numerical values (age, number of siblings,

income). The possible numerical values of quantitative variable form an interval scale, they

have a specific numerical distance between each pair of level (how much smaller or bigger one

outcome is than the other)

  • Categorical variables : the measurement scale is a set of categories (marital status, religious,

type of music). Categorical variables can be nominal (unordered categories ex. religious,

martial status) or ordinal (ordered categories ex. level of education, frequency of activity)

Because different statistical methods apply to each type. The valid statistical methods for a variable

depend on its measurement scale.

Another way to classify a variable refers to the number of values in the measurement scale:

  • Discrete variable : values form a set of separate numbers such as 0,1,2,3 which are basic unit

of measurement that cannot be divided (ex. number of children visiting the doctor)

  • Continuous variable : infinite continuum of possible real number values, between any two

possible values is always another possible value (ex. heigh, weight, time to read a book)

The sample should be representative of the population, other ways we cannot generalize to the

population and make inference. We want to access causality: experimental design (the best

situation to have casual representative sample, use randomization to assign a given treatment to a

subject), sample surveys (select and interview a sample of people from a population),

observational studies (when we can’t use the first type, there’s no experimental control over the

subjects).

Inferential statistical methods use sample statistics to make predictions about population

parameters, the quality of the inference depends on how well the sample represents the

population. Randomization is a mechanism for achieving good sample representation (simple

random sampling, systematic random sampling, cluster sampling, stratified random sampling,

multistage sampling).

The sampling error of a statistic equals the error that occurs when we use a statistic based on a

sample to predict the value of a population parameter.

Issues of bias (mistakes or errors), we have to be aware of it cause we don’t know (what part of

the story could be missing? they can mess up the results):

  • Sampling bias : non-probably sampling, undercoverage (ex. do questionnaire per e-mail I could

exclude all people who doesn’t have it)

  • Response bias : different ways people answer my questions, response set, lying and social

desirability, interviewer and wording effect (that’s why we have to check it before)

  • Non-response bias : people don’t answer, missing values, response rates

Don’t’ take everything as true, control it, evaluate critically the conclusions by noting the makeup

of the sample (how was it selected? How large is it? How were the questions worded?) The less

information is available the less it trustworthy.

Binary data are all observations with just two values: 1 and 0 (all observations take value 0 or 1), it

is used to construct dummy variables (it captures the presence or absence of a certain property).

The median equals the more common outcome, we cannot calculate the mean (the mean equals

the proportion of observations that equal 1), it says nothing about the relative size of the two

groups.

Depending on what type of data or result you have there always a best ways to represent it.

Describing the variability of the data : a measure of center alone is not adequate for numerically

describing data for a quantitative variable. It describes the center, but not the spread of the data

about that typical value.

Distributions with equal means and different distributions (doted line is

a bell shape, the other is a flatted curve). Consider the range that’s the

different between the largest and the smallest observations, it tells us

which distribution has the greatest variability but is blind to variation

toward the center. Important but not sufficient cause we have

distribution with equal means and different distributions.

Deviations form the mean : the deviation of an observation from the sample mean

y

1

− y

(ex. the distance between the average age of the class and my personal age is called deviation). A

deviation can be positive (the deviation falls above the average) or negative (the observations falls

below the average). Since y is the center of gravity of the data, the sum of all deviations about the

mean is equal to zero (this is not very useful measure of variability), therefore measures of

variability use either absolute values of the deviation or more common the square of the

deviation.

The standard deviation s of n observations is:

s =

( y ¿ ¿ 1 − y )

2

n − 1

∑

of squared deviations

sample ¿

 The positive square root of the variance s

2

( y ¿¿ 1 − y )

2

n − 1

The variance is approximately an average of the squared deviations. The units of measurement are

the squares of the original data. This makes the variance more difficult to interpret and we prefer

the standard deviation. The expression ∑ ( y ¿¿ 1 − y )

2

is called the sum of squares. The larger the

deviations from mean, the larger the sum of squares and the larger s tends to be.

Properties of the standard deviation :

  • s ≥ 0
  • s = 0 only when all observations have the same value
  • The greater the variability around the mean, the larger the value of the standard deviation
  • The reason for using

n − 1 instead of

n is tied to the technical issues regarding inference for

population parameters

  • If the data are rescaled, so are the standard deviations

The empirical rule : if the histogram of the data is approximately bell

shaped then:

  • About 68% of the observations fall between

y − s and

y + s

  • About 95% of the observations fall between

y − 2 s and

y + 2 s

  • Nearly 99% all of the observations fall between

y − 3 s and

y + 3 s

Measures of positions : another way to describe a distribution. This tell us the point at which a

given percentage of the data fall below or above that point. The range uses two measures of

position (the maximum and the minimum values), the median is a measure of position, because

half of the data fall below it and half above it.

Percentiles : the median is a special case of a set of measures of position. The pth percentile is the

point such that the p % of the observations fall below or at that point and ( 100 − p ) % fall above it.

The median is the 50

th

percentile in addition is larger than 50% of the observations and smaller

than 50% of the others.

Quartiles : cut the distribution into four (find the median and divide the sample into two parts, the

lower and the higher part than divide them into two, first lower quartile and last upper quartile)

  • The 25

th

percentile is called lower quartile

p = 25 aka the first quartile or

Q

1

. One quarter of

data (25%) fall below the lower quartile

  • The 50

th

percentile is the median

p = 50 aka the second quartile or

Q

2

  • The 75

th

percentile is called the upper quartile

p = 75 or

Q

3

. One quarter of data (25%) fall

above he upper quartile

The interquartile range (IQR) is the difference between the upper and the lower quartile so it

describes the spread of the middle half of the distribution. It increases with the variability of the

data but is not sensitive to outliers (the observation falls more than 1.5xIQR above the upper

quartile or more than 1.5xIRQ below the lower quartile).

Example of a distribution : the external bars

represent the minimum and the maximum

of the sample, the line in the middle of the

red square the mean, the dot outside the

lines represent an outsider.

The z-score is another way to measure position. It is the number of standard deviations that an

observation falls away from the mean (for the empirical rule it is very uncommon for an

observation to fall more than three standard deviations away from the mean).

z =

Observation − Mean

Standard deviation

Probability : the probability that an observation has a particular outcome (given a random sample

or randomised experiment) is the proportion of times that the outcome would occur in a very long

sequence of observations. It is usually defined as falling between 0 and 1 , and often expressed as

percentages.

 Idea behind coin flipping: 50% of the time you will get a head, for the other 50% you’ll get a

cross. If you flip the coin just few times, you have to be lucky to obtain a 50% probability (it’s

for instance not impossible that for four times in a raw you get heads) but in the long term is

easier to get this 50% percentage.

The larger σ the more spread out is the distribution.

If the probability distribution is bell shaped the empirical rule helps to interpret σ.

The normal probability distribution tends to be symmetric, bell-shaped, characterised by its

mean and by its standard deviation sigma.

The probability of an observation falling within any

particular number of standard deviations of μ is the same

for all normal distribution: the probability equals 0.

within 1 standard deviation (z), 0.95 within 2 standard

deviations (z) and 0.997 within 3 standard deviations (z).

The area under the curve is calculated as

μ − z σ if below

the mean and

μ + z σ if above the mean.

Having the two values (mean and standard deviation) gives us the possibility to calculate more or

less the generalization from a sample with a normal distribution. We just need to subtract and sum

form the mean the z-score multiplied by the standard deviation. The z-value can of course be 1 2

or 3 depending on which percentage range of people we want to calculate (1 for the 68%, 2 for the

95% and 3 for the 99%), we just need to follow the empirical rule.

The tabulate normal tail probabilities allows us to find the corresponding z-values to the

probabilities (represented as decimal numbers).

Using z-values : many inferential methods use them corresponding to certain normal curve

probabilities. Starting with a tail probability, we find (using the Standard Normal Table ) the z-value

that provides the number of standard deviations that the number falls away from the mean.

 To find probability: find the z-value, than point it out in the graph (in order to understand

where is in correspondence with the mean), than calculate the probability with the formula

μ − z σ (the probability that falls below) and

μ + z σ (the probability that falls above)

 Example with IQ scores: having a specific value of the mean (ex. 100) and the standard

deviation (16), we can find the IQ score corresponding to different percentiles.

  • Ex. the 99

th

percentile: the first thing to do is to draw the curve and figure out what you

are looking for (in this case it is above the mean). We care about the 1% probability (as

100%-99% is 1%). Than take the table and search for the corresponding probability of 1%

which is 0.01 (find the closest number to it or the average between the more closer two).

Look at the founded value (0.0099 in this case) to the corresponding z-values (2.33 in this

case). So the 99

th

percentile of IQ score is 2.33 standard deviations above the mean. Now

we can use the formula and find the proper IQ=100+2.33x16=

IQ = μ + zσ → IQ score = mean + zσ ( value × standard deviation )

  • Ex. the 5

th

percentile: the first thing to do is to draw the curve and figure out what you are

looking for (in this case it is below the mean). We care about the 5% probability (as it is

below the mean). Than take the table and search for the corresponding probability of 5%

which is 0.05 (find the closest number to it or the average between the more closer two).

Look at the founded value (0.0505 in this case) the corresponding z-values (1.645 in this

case). So the 5

th

percentile of IQ score is 1.645 standard deviations above the mean. Now

we can use the formula and find the proper IQ=100-1.645x16=

IQ = μ − zσ → IQ score = mean − zσ ( value× standard deviation )

The z-score : the z refers to the distance between a possible value y of a variable and the mean of

its probability distribution, in terms of the number of standard deviations that y falls away from

the mean.

z =

y − μ

σ

  • Positive z-scores occur when y falls above the mean
  • Negative z-score occur when y falls below the mean

Standard normal distribution : it is a special normal distribution that has mean=0 and standard

deviations=1.

The number that falls z standard deviations away from the mean is z: μ + z σ = 0 + z ( 1 ) = z

If a variable has a normal distribution the values can be converted to z-scores by subtracting the μ

and dividing by the σ. Then the z-scores have the standard normal distribution.

Probability distributions summarize probabilities of possible outcomes but in practice probability

distributions for population outcomes are rarely known, therefore we use sample data to make

inferences about parameters of there distributions.

 Example: for an election with nearly 7 million voters, we use an exit poll of 2705 voters to

predict who won. The 56.5% reported voting for A, how can we trust this result? Imagine that

in the population both A and B got 50% of the votes (population proportion is 0.5). Taking a

random sample of size n the value will be close to 0.5 but the more samples we take the more

we get closer to the actual result. If half the population of voters voted for Aa we would have

expected between 47% and 53% of voters in the exit poll (sample) to have voted for A, so the

56.5% is a value that is unusual.

Voting preference (object of our research) is a variable that varies among voters. The sample

proportion is also a variable (it varies from sample to sample and it is unknown before the sample

is obtained). If we take multiple samples of the same size we would get a certain variability in the

sample proportion values and putting these values together we can get the sampling distribution.

A sampling distribution of a statistic is the probability distribution that specifies probabilities for

the possible values the statistic can take. Each sample statistic has a sampling distribution (ex.

sampling distribution of a sample mean, sampling distribution of a sample median, sampling

distribution of a sample proportion…). The sampling distribution will have a bell-shape.

From sample to population:

  • Mean (center) : when we analyse sample data and find the mean (

y ), we don’t know how

close it falls to the population mean (μ) because this value is unknown, so using information

about spread of the sampling distribution we can predict it. The sample mean y is a variable

(varies from sample to sample) and fluctuate around the population mean μ.

The mean of the sampling distribution of

y equals μ.

  • Standard deviation (variability or spread) : the spread of the sampling distribution of

y is

described by its standard deviation which is called the standard error of

y

. It tells us how

much the mean

y fluctuate from the mean of the population:

σ

y

σ

√ n

. The standard error gets

smaller as the sample size gets bigger.

The sampling error is something different from the standard error. The sampling error which is not

a mistake but an actual fact in statistic, results from using y to estimate μ because we sampled

estimator of the population proportion. The sample mean is an unbiased and usually efficient

estimator of the population mean.

 Ronald A. Fisher (18090-1962): the observed statistic would have had a greater chance of

occurring if the parameter equalled that number, than if the parameter equalled any other

number.

To be truly informative, an inference should provide also an indication of how close the estimate is

likely to fall to the parameter value. This is given by the width of an interval estimate around the

parameter.

Confidence interval : for a parameter is an interval of numbers

within which the parameter is believed to fall.

In the graph the dots are the points estimates, while the line are

the confidence intervals so the population mean is likely to fall

within that range. Of course the dot is centered and the tails are

symmetric.

Confidence level is the probability that this method produces an interval that contains the true

population parameter. The range is a number chosen to be close to 1 (the best confidence level).

The key to constructing the confidence interval is the sampling distribution of the point estimator.

Confidence interval :

  • For a proportion : calculate the population proportion at first (it will be a number falling

between 0 and 1, denoted as

π

. Remember that it is the mean μ of the probability distribution

having probabilities P(1)=

π and P(0)=1-

π ). Its point estimator is the sample proportion

denoted as ^ π. The standard deviation of the probability distribution is σ =

π ( 1 − π ) and the

standard error of the sample mean is

σ

y

σ

√ n

. Because the mean equals the proportion we

can put the two formulas together getting the standard error of the sample proportion

σ

^ π

σ

^ π

√

π ( 1 − π )

n

. The CLT applies, as the sample proportion is a sample mean, therefore we take

proportion value adding and subtracting the

σ

^ π

multiplied by the z-score.

 With a probability of 0.95, ^ π falls between

π −1.96 σ

^ π

and

π +1.96 σ

^ π

A value of

^ π occurs so that the interval:

^ π −1.96 σ

^ π

and

^ π +1.96 σ

^ π

contains the true

population proportion

π

The interval

^ π ± 1.96 σ

^ π

is an interval estimate for

π with confidence level 0.95, so we have

the 95% confidence level

 Depending on research we might use a different multiplier as the confidence level

changes. We find it taking the percentage subtracted to 100, we make it a proportion, we

divide the result and with this last value find the z-score.

 The larger the sample size, the smaller the margin of error and therefore the interval. As n

increase, the estimated standard error gets closer to the true standard error. For the

general rule, we need to have at least 15 observations both in the category of interest and

not in it.

As in practice the value of the standard error is based on the unknown parameter

π , we use

the following formula to calculate it: σ

^ π

√

π ^ ( 1 − π ^ )

n

  • For a mean : the point estimate for the population mean μ is the sample mean

y

. For large

random samples, by the CLT, the sampling distribution of y is approximately normal, therefore

we can find a margin of error by multiplying a z-score from the normal distribution times the

standard error. The standard error of the sample mean is

σ

y

σ

n

where the σ is the

population standard deviation. Since this value is unknown, we estimate the standard error

using the standard deviation of the sample

σ

y

s

√ n

 Using the estimate standard error, we introduce an extra error which can occur if the

sample size n is small. Therefore we use the t-distribution instead of the z-distribution

because its shape is slightly more spread out and the tail values are larger. The t-

distribution changes depending on the sample size; the larger the sample size the more it

looks like the z-distribution. The difference happens especially at the base of the tails, so

the value depends on the degrees of freedom (calculated as the sample size minus 1). The

t-score multiplied by the estimated standard error gives the margin of error for a

confidence interval for the mean. Remember that this system function if the sample size is

at least 15, for larger samples the CLT comes into play (the system is not robust when the

data is highly skewed, has outliers or when the data are not produced through

randomization).

Margin of error : defined as the

σ

^ π

multiplied by the z-score. We settle for less than 100%

confidence because a 100% confidence interval would be too wide to say anything meaningful

about where the population parameter falls. In practice, we settle for less confidence in favour of a

more precise estimate. Therefore we compromise (as the confidence interval increases, the

precision decreases).

Error probability : the probability that the estimation yields a confidence interval that does not

contain the parameter, denoted by α. (Of course 1- α is the confidence level).

The confidence level for the confidence interval describes how the method performs when used

over and over with many different random samples (so if we constructed many random samples of

a given size, we would get many different confidence intervals). Of

course in reality we don’t have multiple samples, we generally only have

one sample with a fixed sample size n and we construct one confidence

interval hoping it falls there. Our confidence is based on the long-term

properties of the procedure. In the image, the fourth interval totally

missed the population mean value, while the other lines contain it.

Significance tests :

To properly approach the argument we need to

go back and look at what we are doing when we

do research. Doing a research the goal is to

verify if data meet your expectations. To do so

The P-value is the probability that the test statistic equals the observed value (or is more

extreme). It is the probability that

y falls at least as far from

μ

0

in either direction as the

observed value of

y .

  1. Conclusion : the P-value helps reaching a conclusion. If it is very small then it is unlikely that we

would get such a result if it did not reflect the population parameter. Usually we reject the

H

0

if p ≤ 0.05 of 5% (it means that if the null hypothesis were true the chance of getting such an

extreme result in the data would be no greater than 5%).

In a two-sided test (uncover effects in both directions, the confidence intervals are indeed two-

side):

P >0.

: if the P-value is greater than 0.05, the 95% confidence interval contains the

H

0

value

of

μ

P ≤ 0.

: if the P-value is smaller than 0.05, the 95% confidence interval does not contain the

H

0

value of μ

In a one-sided test (using it, the result tend to be in the direction to reject):

H

a

: μ > μ

0

The P-value is the probability of a t-score above the observed t-score

P equals the right tail probability

H

a

: μ < μ

0

The P-value is the probability of a t-score below the observed t-score

P equals the left tail probability

The α-Level is a number such that we reject the

H

0

if the p-value is less than or equal to it. It is also

called the significance level. The most common level are the 0.05 and the 0.01.

Significance test for a mean :

We assumes that the population distribution is normal so that the sampling distribution is normal

even for small size sample (as the sample size increases this is less important because of the CLT).

Two-sided inferences are robust to violations of the assumption, while one-sided inferences aren’t.

  • The population mean is μ and

μ

0

is a particular value for the population mean

  • The null hypothesis about the population mean has the form of
H

0

: μ = μ

0

  • The alternative hypothesis is
H

a

: μ≠ μ

0

H

a

can be two-sided (the value can be smaller or larger than the

μ

0

) or one sided if

H

a

: μ > μ

0

  • The sample mean y estimates the population mean μ
  • Under the presumption that the null hypothesis is true, the center of the sampling distribution

of

y is the value

μ

0

(it would be unusual to find

y far from

μ

0

, if strong evidence against

H

0

  • It is summarized by the number of standard errors that y far away from the null hypothesis

μ

0

- The formula to test statistic is t =

y − μ

0

se

where

se =

s

n

If the

y is equal to

μ

0

(so the null hypothesis is true) then the t equal 1 (most consistent value)

The larger, in absolute terms, t the farther away we are from the null hypothesis value (the

farther

y falls from

μ

0

), so the stronger the evidence against the null hypothesis

  • To interpret the t we transform it into a probability called P-value
  • The smaller the P is, the stronger the evidence against the
H

0

and in favour of

H

a

  • In order to accept the null hypothesis: small value of t and large value of p
  • Confidence interval gives a range of possible values so it could be useful to interpret our

hypotheses

Significance test for a proportion :

As assumption we need to remember the randomization and a sufficiently large sample size (equal

or above 20) so that the sampling distribution is approximately normal.

  • For a categorical variable, the parameter is the population proportion for a category
  • π is the population proportion in that category
  • The test finds a P-value for a test statistic measuring the number of standard errors a point

estimate falls from a

H

0

value

π

0

represents a particular proportion value between 0 and 1

  • The null hypothesis about the population mean has the form of
H

0

: π = π

0

  • The alternative hypothesis is
H

a

: π ≠ π

0

  • The one-sided versions are:
H

a

: π > π

0

or

H

a

: π < π

0

  • Form of a test statistic

z =

estimate of parameter − null hypothesis value of parameter

standard error of estimator

π ^− π

0

se

0

where

se

0

√

π

0

( 1 − π

0

n

The z-score measures the number of standard errors the sample proportion falls from

π

0

  • The P-value is the one or two-tail probability using the normal distribution
  • The smaller the P is, the stronger the evidence against the
H

0

and in favour of

H

a

  • We reject the null hypothesis if the P is smaller than α for a pre-specified α-level such as 0.

We cannot accept the

H

0

(it could be a range of numbers as specified in the confidence interval)

therefore the only thing we can is that we “can’t reject it”.

In general we tend to reject

H

0

with a small P-value and a large T-value.

Because of sampling variability, decisions in tests are always uncertain, errors can occur as we

don’t know the real value of the population. We do not know therefore this types of errors are not

our fault. There are two types of potential errors:

  • Type I error : reject the null when it is true - Typer II error : fail to reject the null when it is false

The smaller the probability of a Type I error,

the larger the probability of a Type II error.

The collection of test statistic values for

which the test rejects null hypothesis is called rejection region (ex. for a test of level α=0.05 the

rejection region is the set of test statistic values for which P<=0.05. It happens when in a two-sided

tests for a proportion z >=1.96 (in absolute terms)). The rejection region consists of values of z

resulting from the estimate falling at least 1.96 standard errors from the null hypothesis value.

The significance test tells us whether a parameter differs from the null hypothesis value but it is

not informative about how much it differs and whether this difference is of practical importance

(statistical significance: small P-value while practical significance: size of the effect). Therefore we

should give also the confidence interval that helps us to understand something on the effect’s size.

To calculate the standard error: se =

√

^ π

1

( 1 − π ^

1

n

1

^ π

2

( 1 −^ π

2

n

2

We can than find the confidence interval:

(^ π ¿

¿ 2 − π ^

1

) ± z ( se )¿ .

If the confidence interval contains zero we can’t be sure to reject the

H

0

as the probability is

similar for the two groups, no sufficient evidence to conclude which between

^ π

1

or

^ π

2

is larger

 The significance test can be calculated to compare population proportions

In an example:

H

0

: π

1

= π

2

so that

H

0

: π

2

− π

1

Under the assumption that

π

1

= π

2

we estimate the common value by the sample

proportion of the entire sample (pooled estimate that is the value that ignores difference

between groups)

So the test statistic is:

z =

estimate − null hypothesis value

standard error

that is z =

^

π ¿

^

π

1

)− H

0

se

The obtained result will give us an indication whether to reject or no the null hypothesis

Remember that the P-value, T-value and confidence interval should converge to the same thing ,

should tell us the same result, of course in different ways but the same result.

Sample that have the same subjects repeated over time or where some form of matching between

subjects exists are called dependent samples. With them matched responses are likely to be

associated and standard errors must be adjusted accordingly. Analysing data with clustering means

that we need to adjust the standard errors, usually little bit bigger to avoid type I and type II errors

(ex. longitudinal studies, experimental designs, household data)

Choosing the right technique is crucial:

An association exists between two variables if the distribution of the response variable changes as

the value of the explanatory variable changes.

Associations between categorical variables : there are many ways to assess there relationships:

  1. For the analysis of categorical variables we start from the contingency tables (crosstabs). A

contingency table displays the number of subjects observed at all possible combinations of

possible outcomes of the two variables. Looking at the frequencies will tell us nothing

important about the combinations and

associations therefore we transform frequencies

into percentages (we divide the value in each cell

for the total of the corresponding group to get the

conditional distribution ). When calculating the

percentages it is standard to form the conditional

distribution for the response variable within categories of the explanatory variable (doing the

opposite we get the composition by gender of the response variable party ID but this tells little

on the association between the two). The key thing is to identify which is the dependent

variable (gender) and independent variable (ID).

Bar charts are useful to display the results.

 With graphs and tables tell the reader everything important: clearly the label the variables

and their categories, provide informative title, include the total sample size on which the

percentages were calculated (decimals no more than two)

We are talking about the population and not the sample: the sample data provides some evidence

but not a define answer as we are referring to the population.

Statistical independence : two categorical variables are statistically independent if the population

conditional distributions on one of them are identical at each category of the other. Variables are

statistically independent if the conditional distributions are identical (equal %) in each category.

Statistical dependence : the variables are statistically dependent if the conditional distributions are

not identical. The variables are statistically dependent if the conditional distributions are different

in each category (percentages are different) and not identical.

Therefore we use the Chi-squared test of independence , the X

2

  • Is it plausible that gender and party ID are independent? If gender and ID were truly

independent, could we expect these observed differences just because of sampling variability?

We set the hypothesis:

H

0

: the variables are statistically independent

H

a

: the variables are statistically dependent

The test compares the observed frequencies

f

o

in the contingency table with values that satisfy the

null hypothesis of independence. This values are called expected frequencies

f

e

. It requires

randomization and

f

e

in each cell

An expected frequency is the count expected in the cell if the variables were independent.

f

e

row total × column total

total sample ¿ ¿ ¿

The X

2

statistic summarizes how close the expected frequencies are to the observed frequencies:

X

2

( f

o

− f

e

2

f

e

  • When
H

0

is true, the values of

f

e

and

f

o

tend to be vey close and the X

2

statistic will be small

  • When
H

0

is false, the values of

f

e

and

f

o

tend to be different and the X

2

statistic will be large

  • The larger the X

2

value, the greater the evidence against

H

0

The sampling distribution of the X

2

test statistic indicated how large

X

2

has to be so that there is considerable evidence against

H

0

. For

large sample sizes, the sampling distribution is the chi-squared

probability distribution.

  • The chi-squared distribution ( X

2

) is

  • It is skewed to the right
  • It precise shape depends on the degrees of freedom df =( r − 1 )( c − 1 ) where r are rows and c

are columns

The X

2

tells nothing about the nature or the strength of the association between two variables.

ANOVA set up: “g” denotes the number of groups to compare. The means of the response variable

for the corresponding population ( μ ) and the sample means ( y ). The analysis of variance ANOVA is

an F-test for:

H

0

: μ

1

= μ

n

so all population means are equal

  • Ha: a least two of the population means are unequal

If the

H

0

is false: all the population means differ or some differ or only one differs from the rest.

The test analyses whether the differences observed among the sample means could have

reasonably occurred by chance, if the

H

a

were true

Assumptions: for each group the population distribution of the response variable y is

approximately normal (a large sample size can avoid the problem). The standard deviations (same

shape) of the population distribution is the same for each group (denote by σ). The samples from

the population are independent random samples (this is certain, no exceptions).

The formula of variance is: s

2

∑ ( y

i

− y )

2

n − 1

calculate the deviation of each obserbation from the

overall sample mean.

The test statistic compares two estimates of variance σ

2

for each group:

  • Variability between groups : it estimates the variability between each sample mean (

y

1

) and

the overall mean. How far apart the mean of each sample differs from the overall mean.

  • Variability within groups : it estimates the variability within each group of the sample

observations around their several means

Generally, the greater the variability between sample

means, and the smaller the variability within each

group (A), the stronger the evidence against the null

hypothesis of equal population means (B). The

variance within group describe somehow the

variation and if more spread the groups tend to

overlap.

The F-test is a ration of the two parameters:

F =

between groupestimate of variance

within group estimate of variance

  • If the
H

0

is true, the between and the within estimates will be approximately the same and F

approximately equal 1

  • If the
H

0

is not true, the between group estimate tends to over estimate σ

2

and the between

group estimate will be larger than the within estimate. The F is > than 1

When the null hypothesis is true the F statistic has an F sampling distribution. The shape of the F

depends on the degree of freedom. The P value is the right-tail probability that the F statistic

exceeds the observed F value. The larger the F statistic, the smaller the P value.

  1. Within-group estimate of variance : s

2

Within − group ∑

of squares

df

where

df = total sample ¿− number of gorups g

It is weighted average of the separate sample variances, with greater weight to larger samples

  1. Between-group estimate of variance : s

2

∑n

1

( y

1

− y )

2

g − 1

The squared difference between each sample mean and the overall mean is weighted y the

sample size upon which it is based.

When the population means are unequal, the overall mean values tend to be more variable

than if the population means are equal.

The farther away from the null. The large the between-group variance

With two groups, a F-test will yield the same result from a T-test comparing means but using a

single F test enables us to control the overall probability of type I error. When α=0.05 in the F-test,

the probability of rejecting a true null is exactly 0.05, while when we do a multiple t-test, a type I

error probability applies for each comparison.

A small P-value does not indicate which means are different or how different they are. Therefore

some other things are required to estimate the difference between the groups and calculate the

confidence intervals comparing the means.

  • A confidence interval for

μ

1

is:

y

1

±t

s

n

1

  • A confidence interval for

μ

1

− μ

2

is: (

y

1

− y

2

± ts

√

n

1

n

2

The type of test that we apply

depends on the type of

variable that are involved.

Regression model : you can have more than one independent variables which affects the

dependent. The graph used is the scatterplot (each dots represent each individual observations), a

positive association between the variables create a figure of a line going up (positive slope), a

negative association between the variables create on the other hand a figure going down (negative

slope).

The regression analysis is used to study the relationship between quantitative variables, it allows

investigating whether an association exists by testing the hypothesis of statistical independence. As

always, correlation is not causation. The analysis is made up of two different things:

  1. Regression equation : it allows us to predict the value of the response variable (dependent)

from the value of the explanatory variable (independent). The analysis doesn’t tell anything

about the strength of the correlation

  1. Correlation : is used to measure the strength of the association

The relationship is a linear relationship (if x goes up also y goes up, if x goes down also y goes

down), it doesn’t have to be a perfect line but approximately yes. A situation of U-shaped, a non-

linear relationship is not going to work. The y denote the

response variable and x the explanatory variable.

First graph is a positive linear, second a negative linear

and third there’s no relationship.