Docsity

Cumulative Distribution and Probability Density Functions | MATH 324, Study notes of Applied Statistics

Toggle sidebar
bg1
Chapter 0 Preliminaries January 8, 2009 1
0 Preliminaries
First introductory question: When do we use nonparametric statistics?
Example: Construct a 95% confidence interval on the mean household income of
your community. Test if mean income equals $50,000 versus the alternative that
mean income does not equal $50,000.
(1) How is this done?
∗Take a sample.
∗Take a sample.
(2) What test (or table) is often used?
∗t-test or t-table
∗t-test or t-table
(3) What assumptions are needed?
∗(a) The observations are independently (or close to independently) sampled.
∗(a) The observations are independently (or close to independently) sampled.
∗(b) The sample size is large and σ < ∞(in which case the Central Limit Theorem
may be used), or the observations are from an approximately normal population.
∗(b) The sample size is large and σ < ∞(in which case the Central Limit Theorem
may be used), or the observations are from an approximately normal population.
∗(4) Suppose the sample size is small, and normality is not reasonable, and a trans-
formation to normality is not reasonable, and methods based on other non-normal
distributions are not available or appropriate (or assumptions are not made on the
distribution).
∗(4) Suppose the sample size is small, and normality is not reasonable, and a trans-
formation to normality is not reasonable, and methods based on other non-normal
distributions are not available or appropriate (or assumptions are not made on the
distribution).
∗Then, we use nonparametric methods.
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

Partial preview of the text

Download Cumulative Distribution and Probability Density Functions | MATH 324 and more Study notes Applied Statistics in PDF only on Docsity!

Chapter 0 Preliminaries January 8, 2009 1

0 Preliminaries

First introductory question: When do we use nonparametric statistics?

Example: Construct a 95% confidence interval on the mean household income of

your community. Test if mean income equals $50,000 versus the alternative that mean income does not equal $50,000. (1) How is this done? ∗ Take a sample. ∗ Take a sample. (2) What test (or table) is often used? ∗ t-test or t-table ∗ t-test or t-table (3) What assumptions are needed? ∗ (a) The observations are independently (or close to independently) sampled. ∗ (a) The observations are independently (or close to independently) sampled. ∗ (b) The sample size is large and σ < ∞ (in which case the Central Limit Theorem may be used), or the observations are from an approximately normal population. ∗ (b) The sample size is large and σ < ∞ (in which case the Central Limit Theorem may be used), or the observations are from an approximately normal population. ∗ (4) Suppose the sample size is small, and normality is not reasonable, and a trans- formation to normality is not reasonable, and methods based on other non-normal distributions are not available or appropriate (or assumptions are not made on the distribution). ∗ (4) Suppose the sample size is small, and normality is not reasonable, and a trans- formation to normality is not reasonable, and methods based on other non-normal distributions are not available or appropriate (or assumptions are not made on the distribution). ∗ Then, we use nonparametric methods.

Section 0.1 Cumulative Distributions and Probability Density Functions January 8, 2009 2

∗ Then, we use nonparametric methods. Second introductory question: What are nonparametric statistics? Details on nonparametric methods begin in section 0.5.

0.1 Cumulative Distributions and

Probability Density Functions

A population consists of all possible values for some variable. ∗ A population might consist of all incomes in the United States, and the variable is any given income in the United States. ∗ A population might consist of all incomes in the United States, and the variable is any given income in the United States. A sample consists of a subset of the population, and is often drawn randomly. A random variable denotes an observation selected randomly from the population. A cumulative distribution function (cdf) of a random variable X is P (X ≤ x) for all real x.

Example: Suppose X denotes the income of a randomly selected household. What

does the cumulative distribution of X evaluated at $100,000 represent? ∗ The probability that a randomly selected household has income less than or equal to $100,000 (maybe 80%?). ∗ The probability that a randomly selected household has income less than or equal to $100,000 (maybe 80%?). ∗ Alternatively, the proportion of household incomes which are less than or equal to $100,000. ∗ Alternatively, the proportion of household incomes which are less than or equal to $100,000. 2

(a) Graph the probability density function (pdf) of a standard normal distribution, say, from −3 to 3.

> x < − 0:100 # Generate numbers from 0 to 100.

> x = 0:100 # Generate numbers from 0 to 100.

Alternatively, use:

> x = c(0:100) # ‘c’ means combine.

> x = x / 100 − 0.5 # Generates numbers between − 0 .5 and 0.5.

> x = x ∗ 6 # Generates numbers between −3 and 3.

Alternatively, type:

> x = 6 ∗ ( c(0:100) / 100 − 0.5 )

∗ > x = 6 ∗ ( 0:100 / 100 − 0.5 ) # Alternatively. Colon is executed first.

∗ > x = 6 ∗ ( 0:100 / 100 − 0.5 ) # Alternatively. Colon is executed first.

> help( “dnorm” ) # Help menu for ‘dnorm’.

> ?dnorm # Again, the help menu for ‘dnorm’.

> y = dnorm(x) # f(x); i.e., probability density function for a standard normal r.v.

> # Note that different means and standard deviations may be used.

> plot( x, y )

> plot( x, dnorm(x) )

> plot( x, dnorm(x), type=“s” ) # Use stair step for a nicer looking graph.

∗ Use 1001 points for additional smoothness.

∗ Use 1001 points for additional smoothness.

> x = 6 ∗ ( 0:1000 / 1000 − 0.5 )

> plot( x, dnorm(x), type=“s” )

(b) Graph the probability density function (pdf) of a N(μ = 0. 5 , σ = 0.3) random variable from −3 to 3.

> plot( x, dnorm( x, mean=0.5, sd=0.3 ), type=“s” ) # different mean and sd.

> plot( x, dnorm( x, 0.5, 0.3 ), type=“s” ) # different mean and sd.

∗ See the normal pdf and cdf on p. 2.

∗ See the normal pdf and cdf on p. 2.

(c) Graph the cumulative density function (cdf) of a standard normal random variable from −3 to 3.

∗ > plot( x, pnorm(x) ) # ‘p’ in pnorm means ‘probability.’

∗ > plot( x, pnorm(x) ) # ‘p’ in pnorm means ‘probability.’

(d) Use the macro ‘plot.dist’ to graph the probability density function (pdf) of a N(μ = 50 , σ = 5) random variable from 35 to 65.

> source( “http://www.math.jmu.edu/∼garrenst/math324.dir/Rmacros” ) # Read in the macros.

> ls( ) # List the functions (macros) and variables.

∗ > ls(1); ls(2); ls(3); ls(4) # To see pre-defined R-macros.

∗ > ls(1); ls(2); ls(3); ls(4) # To see pre-defined R-macros.

> plot.dist # To read the source code and comments.

> plot.dist( “dnorm”, 50, 5, xmin=35, xmax=65 )

∗ We defined the bounds of x, instead of defining a vector x.

∗ We defined the bounds of x, instead of defining a vector x.

∗ > plot.dist( “dnorm”, 50, 5 )

∗ > plot.dist( “dnorm”, 50, 5 )

(e) Use the macro ‘plot.dist’ to graph the cumulative distribution function (cdf) of a N(μ = 50, σ = 5) random variable from 35 to 65.

∗ > plot.dist( “pnorm”, 50, 5, xmin=35, xmax=65 )

∗ > plot.dist( “pnorm”, 50, 5, xmin=35, xmax=65 )

∗ > plot.dist( “pnorm”, 50, 5 )

∗ > plot.dist( “pnorm”, 50, 5 )

∗ [1] 319.

∗ [1] 319.

(h) Generate 1000 independent observations from a N(80, 10) distribution. Determine the sample mean, X¯, and the sample standard deviation, s, and graph these obser- vations in a histogram.

> x1 = rnorm( 1000, 80, 10 ) # The ‘r’ in ‘rnorm’ means ‘random.’

> mean( x1 )

> sd( x1 )

> hist( x1 )

> history( ) # To view the history.

> q( ) # To quit!

Central Limit Theorem: If n independent observations are sampled from a population with mean μ and finite standard deviation σ, then the sample mean X¯

has approximately a N(μ, σ/√n) distribution, for large n.

Furthermore, if n independent observations are sampled from an approximately N(μ, σ) population, then the sample mean X¯ has approximately a N(μ, σ/√n) distribution.

∗ The spread of X¯ decreases as n gets large.

∗ The spread of X¯ decreases as n gets large.

∗ If X ∼ N(μ, σ), then Z = (X − μ)/σ ∼ N(0, 1).

∗ If X ∼ N(μ, σ), then Z = (X − μ)/σ ∼ N(0, 1).

∗ Also, if X¯ ∼ N(μ, σ/√n), then Z = ( X¯ − μ)/(σ/√n) ∼ N(0, 1).

∗ Also, if X¯ ∼ N(μ, σ/√n), then Z = ( X¯ − μ)/(σ/√n) ∼ N(0, 1).

A parameter is an (often unknown) quantity which is a characteristic of a population.

∗ μ and σ are parameters of a N(μ, σ) population.

∗ μ and σ are parameters of a N(μ, σ) population.

∗ The distribution itself may be considered a parameter. Hence, nonparametrics is based on unknown distributions.

∗ The distribution itself may be considered a parameter. Hence, nonparametrics is based on unknown distributions.

More on standardizing

In general, if X is any random variable and a and b are constants such that the distri- bution of (X − a)/b does not depend on a or b, then a is a location parameter and b is a scale parameter.

∗ Note that for a N(μ, σ) distribution, μ is a location parameter and σ is a scale parameter, since (X − μ)/σ ∼ N(0, 1).

∗ Note that for a N(μ, σ) distribution, μ is a location parameter and σ is a scale parameter, since (X − μ)/σ ∼ N(0, 1).

∗ Changing μ changes the location of the population, and changing σ changes the scale or spread of the population.

∗ Changing μ changes the location of the population, and changing σ changes the scale or spread of the population.

Then, the probability density function (pdf) of X can be written:

fa,b(x) =^1 b h

( (^) x − a b

) .

∗ The proof is not difficult, and merely involves a simple change of variables, but is saved for Math 426 or 427.

∗ The proof is not difficult, and merely involves a simple change of variables, but is saved for Math 426 or 427.

Example: Let f (x) [or fμ,σ(x)] be the pdf of a N(μ, σ) distribution.

f (x) = e

−(x−μ)^2 /(2σ^2 ) σ

2 π , −∞ < x < ∞

Let h(z) be the pdf of a N(0, 1) distribution. Then,

h(z) = e

−z^2 / 2 √ 2 π , −∞ < z < ∞

∗ > plot.dist( “punif”, 30, 40 ) # cdf

∗ > plot.dist( “punif”, 30, 40 ) # cdf

(d) What is the mean of a uniform random variable?

∗ The average of the two endpoints.

∗ The average of the two endpoints.

(e) Sample 1000 observations from a Uniform(30, 40) distribution, calculate the sample mean and plot the histogram.

> x = runif( 1000, 30, 40 )

> x[ 1 : 50 ] # Observe the first 50 observations.

∗ > mean( x )

∗ > mean( x )

∗ > hist( x )

∗ > hist( x )

2

Example: Applying the Central Limit Theorem to the uniform distribu-

tion using R.

Let U ∼ Uniform(40, 60). Let U¯n be the sample mean of n independent realizations of U.

(a) Plot the pdf and cdf of U.

∗ > plot.dist( “dunif”, 40, 60 ) # pdf

∗ > plot.dist( “dunif”, 40, 60 ) # pdf

∗ > plot.dist( “punif”, 40, 60 ) # cdf

∗ > plot.dist( “punif”, 40, 60 ) # cdf

(b) Sample 30 independent observations of U¯ 2 , using the macro ‘replicate’.

∗ Hence, U¯ 2 is a sample mean based on two observations.

∗ Hence, U¯ 2 is a sample mean based on two observations.

> u.bar = replicate( 30, mean( runif( 2, 40, 60 ) ) )

(c) Construct a histogram of 10,000 independent observations of U¯ 2.

∗ > u.bar = replicate( 10000, mean( runif( 2, 40, 60 ) ) )

∗ > u.bar = replicate( 10000, mean( runif( 2, 40, 60 ) ) )

∗ > hist(u.bar)

∗ > hist(u.bar)

Interpret your graph.

∗ The exact distribution is triangular-shaped.

∗ The exact distribution is triangular-shaped.

∗ Note how the distribution, which has domain from 40 to 60, is already starting to obtain somewhat of a normal shape.

∗ Note how the distribution, which has domain from 40 to 60, is already starting to obtain somewhat of a normal shape.

∗ > hist( replicate( 1e4, mean( runif( 2, 40, 60 ) ) ) )

∗ > hist( replicate( 1e4, mean( runif( 2, 40, 60 ) ) ) )

∗ plot.dist( “dtriang”, 40, 60 ) # Plot the pdf.

∗ plot.dist( “dtriang”, 40, 60 ) # Plot the pdf.

(d) Repeat part (c) for U¯ 5 , U¯ 20 , and U¯ 100.

> hist( replicate( 1e4, mean( runif( 5, 40, 60 ) ) ) )

∗ > hist( replicate( 1e4, mean( runif( 20, 40, 60 ) ) ) )

∗ > hist( replicate( 1e4, mean( runif( 20, 40, 60 ) ) ) )

∗ > hist( replicate( 1e4, mean( runif( 100, 40, 60 ) ) ) )

∗ > hist( replicate( 1e4, mean( runif( 100, 40, 60 ) ) ) )

∗ Notice that the spread (standard deviation) decreases for larger n.

∗ Notice that the spread (standard deviation) decreases for larger n.

∗ Since the better approximation to normality might not be obvious in the histograms with larger n, do the next part below.

> # Graph the pdf of a standard exponential distribution.

> plot.dist

> ?dexp

∗ > plot.dist( “dexp” )

∗ > plot.dist( “dexp” )

> # Graph the pdf of an exponential distribution using ‘rate’ equal to 0.1.

∗ > plot.dist( “dexp”, 0.1 )

∗ > plot.dist( “dexp”, 0.1 )

> # What are the new mean and standard deviation?

> # Generate 10,000 observations from an exponential distribution using ‘rate’ equal to 0.1.

∗ > x = rexp( 10000, 0.1 )

∗ > x = rexp( 10000, 0.1 )

> # Construct a histogram of the data.

∗ > hist( x )

∗ > hist( x )

> # Determine the sample mean of x.

∗ > mean( x )

∗ > mean( x )

∗ Should be close to 10.

∗ Should be close to 10.

> # Determine the sample standard deviation of x.

∗ > sd( x )

∗ > sd( x )

∗ Should be close to 10.

∗ Should be close to 10.

∗ For an exponential distribution, the mean, the standard deviation, and (1 / rate) are the same.

∗ For an exponential distribution, the mean, the standard deviation, and (1 / rate) are the same. 2

Laplace or Double Exponential distribution

A Laplace distribution is symmetric about its mean, such that each half of the pdf is exponential.

The pdf for a standard Laplace distribution is

h 3 (z) = e

−|z√ 2 | √ 2 ,^ −∞^ < z <^ ∞.

The standard Laplace distribution has mean zero and standard deviation one.

> # Graph the pdf of the standard Laplace distribution.

> dlaplace

∗ > plot.dist( “dlaplace” )

∗ > plot.dist( “dlaplace” )

> # Graph the pdf of the Laplace distribution with mean equal to 2 and standard deviation equal to 3.

∗ > plot.dist( “dlaplace”, 2, 3 )

∗ > plot.dist( “dlaplace”, 2, 3 )

> # Generate 10,000 observations from a Laplace distribution with mean equal to 2 and standard deviation equal to 3.

∗ > x = rlaplace( 10000, 2, 3 )

∗ > x = rlaplace( 10000, 2, 3 )

> ?dcauchy

∗ > plot.dist( “dcauchy” )

∗ > plot.dist( “dcauchy” )

∗ > plot.dist( “dcauchy”, 0, 1, “dt”, 1 )

∗ > plot.dist( “dcauchy”, 0, 1, “dt”, 1 )

∗ Cauchy(0,1) and t 1 are identical.

∗ Cauchy(0,1) and t 1 are identical.

∗ To an untrained eye, the Cauchy does not appear to differ all that much from the normal, especially in the central region.

∗ To an untrained eye, the Cauchy does not appear to differ all that much from the normal, especially in the central region.

∗ > plot.dist( “dnorm”, 0, 1, “dcauchy” ) # To plot both standard normal and standard Cauchy.

∗ > plot.dist( “dnorm”, 0, 1, “dcauchy” ) # To plot both standard normal and standard Cauchy.

> # Graph the pdf of a Cauchy distribution with location parameter 40 and scale parameter 5.

∗ > plot.dist( “dcauchy”, 40, 5 )

∗ > plot.dist( “dcauchy”, 40, 5 )

> # If X has the above pdf, determine P (X < 40), using R.

∗ > pcauchy( 40, 40, 5 ) # Answer is 0.5.

∗ > pcauchy( 40, 40, 5 ) # Answer is 0.5.

∗ The location parameter is also the population median.

∗ The location parameter is also the population median.

> # Determine P (X < 35).

∗ > pcauchy( 35, 40, 5 ) # Answer is 0.25.

∗ > pcauchy( 35, 40, 5 ) # Answer is 0.25.

> shade.dist

> shade.dist( 35, “dcauchy”, 40, 5 )

> # Determine P (X < 45).

∗ > pcauchy( 45, 40, 5 ) # Answer is 0.75.

∗ > pcauchy( 45, 40, 5 ) # Answer is 0.75.

∗ > pcauchy( c( 35, 40, 45 ), 40, 5 ) # Answers are 0.25, 0.5 and 0.75.

∗ > pcauchy( c( 35, 40, 45 ), 40, 5 ) # Answers are 0.25, 0.5 and 0.75.

∗ > shade.dist( 45, “dcauchy”, 40, 5 ) # Shade in the region to the left of 45.

∗ > shade.dist( 45, “dcauchy”, 40, 5 ) # Shade in the region to the left of 45.

∗ > shade.dist( c(35, 45), “dcauchy”, 40, 5, F ) # Shade in the region from 35 to 45.

∗ > shade.dist( c(35, 45), “dcauchy”, 40, 5, F ) # Shade in the region from 35 to 45.

∗ The location and scale parameters divide the Cauchy distribution into quartiles (i.e., fourths).

∗ The location and scale parameters divide the Cauchy distribution into quartiles (i.e., fourths). 2

Comparing Normal and Cauchy distributions

Ignoring the constants, the probability density functions of the normal and Cauchy distributions are: e−z^2 and (1 + z^2 )−^1.

Which of these converges to zero faster as z → ∞ (or z → −∞)?

∗ From pre-calculus, the normal pdf converges to zero faster.

∗ From pre-calculus, the normal pdf converges to zero faster.

∗ > hist( x )

∗ > hist( x )

May want to try:

> trunc.hist( x )

> trunc.hist( x, −3, 3 ) # Construct a truncated histogram, excluding values outside −3 and 3.

∗ Try again using 10,000 observations.

∗ Try again using 10,000 observations.

2

Light-tailed distributions, such as uniform and normal, rarely produce outliers.

Heavy-tailed distributions, such as exponential, Laplace and Cauchy, tend to produce outliers.

The Cauchy distribution has very heavy tails.

What is the distribution of the sample mean of n independent N(μ, σ) random variables?

∗ N(μ, σ/√n)

∗ N(μ, σ/√n)

What is the distribution of the sample mean of n independent Cauchy(θ, 1) random variables?

∗ Also, Cauchy(θ, 1). Proof is shown in Math 426 or 427.

∗ Also, Cauchy(θ, 1). Proof is shown in Math 426 or 427.

∗ Since the sample mean of a Cauchy random variable is a poor estimator of θ, we use the sample median instead.

∗ Since the sample mean of a Cauchy random variable is a poor estimator of θ, we use the sample median instead.

Homework C0.2.1: Let X ∼ N(μ = 500, σ = 200). Let U be a uniform random

variable with endpoints 50 and 60. Let Y ∼ Cauchy( location = 500, scale = 200).

Let X¯ be the sample mean of 100 independent realizations of X. Let U¯ be the sample mean of 100 independent realizations of U. Let Y¯ be the sample mean of 100 independent realizations of Y. Let Y˜ be the sample median of 100 independent observations of Y. Use R for all graphs below, and show both your source code and output. CLEARLY LABEL THE VARIOUS PARTS (a), (b), (c), etc.

(a) Graph the pdf of X.

(b) Graph the pdf of U.

(c) Graph the pdf of Y.

(d) What distribution (i.e., the shape, location, and scale) does X¯ have? (There is no need to use R for this part.)

(e) Graph the pdf of X¯.

After completing part (e),

sample 10,000 independent realizations of X¯.

(f) Compute the sample mean and sample standard deviation of your 10,000 values of X¯.

(g) Graph your 10,000 values of X¯ in a histogram.

(h) Are your results from parts (f) and (g) consistent with your answer from part (d)? Explain.

Next, sample 10,000 independent realizations of U¯.

(i) Graph your 10,000 values of U¯ in a histogram.

(j) What is the approximate shape of the distribution of U¯?

Next, sample 10,000 independent realizations of Y¯.

(k) Graph your 10,000 values of Y¯ in a histogram.

(l) Graph your 10,000 values of Y¯ in a truncated histogram.

(m) What distribution (i.e., the shape, location, and scale) does Y¯ have? (There is no need to use R for this part.)

(n) When trying to estimate the population median (i.e., location parameter) of a Cauchy distribution, which is more informative: one observation from the Cauchy