You are on page 1of 69

Lecture 7:

Statistical
Inference

Assoc. Prof.
Amany E. Aly
Lecture 7: Statistical Inference
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations Assoc. Prof. Amany E. Aly
Department of Mathematics, Faculty of Science,
Helwan University, Ain Helwan, Cairo, Egypt.

20 / 3 / 2023

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 1 / 29
Chapter Objectives

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 2 / 29
Presentation Outline

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
Theoretical
Distributions of
1 Chapter Objectives
Observations
Simulations Theoretical Distributions of Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 3 / 29
Chapter Objectives

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
After completing this chapter, you should be able to:
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 4 / 29
Chapter Objectives

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
After completing this chapter, you should be able to:
Objectives
Theoretical 1 Define key terms that are associated with inferential statistics.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 4 / 29
Chapter Objectives

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
After completing this chapter, you should be able to:
Objectives
Theoretical 1 Define key terms that are associated with inferential statistics.
Distributions of
Observations
Simulations
2 Recognize the variables of the ”cars.csv” data frame.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 4 / 29
Chapter Objectives

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
After completing this chapter, you should be able to:
Objectives
Theoretical 1 Define key terms that are associated with inferential statistics.
Distributions of
Observations
Simulations
2 Recognize the variables of the ”cars.csv” data frame.

3 Revise concepts related to random variables, the sampling dis-

tribution and the Central Limit Theorem.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 4 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter The following link contains the adopted reference and all required
Objectives
Theoretical
Distributions of
data:
Observations
Simulations

http : //pluto.huji.ac.il/ ∼ msby/StatT hink/

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 5 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
1 Statistical inference is applied to data in order to address spe-
Objectives
Theoretical cific research question.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 6 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
1 Statistical inference is applied to data in order to address spe-
Objectives
Theoretical cific research question.
Distributions of
Observations
Simulations 2 We will demonstrate different inferential procedures using a
specific data set with the aim of making the discussion of the
different procedures more concrete.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 6 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
Example 1
Chapter
Objectives
Theoretical
read the content of the CSV file into an R data frame and produce
Distributions of
Observations
Simulations
a brief summary.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 7 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
Example 1
Chapter
Objectives
Theoretical
read the content of the CSV file into an R data frame and produce
Distributions of
Observations
Simulations
a brief summary.
> cars < − read.csv(”cars.csv”)
> summary(cars)

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 7 / 29
Theoretical Distributions of Observations

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 8 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
1 Binomial:
Chapter a The parameters that determine the distribution are n, the number of observations,
Objectives
Theoretical and p, the probability of obtaining the particular outcome in each observation.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 9 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
1 Binomial:
Chapter a The parameters that determine the distribution are n, the number of observations,
Objectives
Theoretical and p, the probability of obtaining the particular outcome in each observation.
Distributions of
Observations b The expression Binomial(n, p) is used to mark the Binomial distribution.
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 9 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
1 Binomial:
Chapter a The parameters that determine the distribution are n, the number of observations,
Objectives
Theoretical and p, the probability of obtaining the particular outcome in each observation.
Distributions of
Observations b The expression Binomial(n, p) is used to mark the Binomial distribution.
Simulations
c The functions dbinom, pbinom, and qbinom may be used in order to compute
the probability, the cumulative probability, and the percentiles, respectively.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 9 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
1 Binomial:
Chapter a The parameters that determine the distribution are n, the number of observations,
Objectives
Theoretical and p, the probability of obtaining the particular outcome in each observation.
Distributions of
Observations b The expression Binomial(n, p) is used to mark the Binomial distribution.
Simulations
c The functions dbinom, pbinom, and qbinom may be used in order to compute
the probability, the cumulative probability, and the percentiles, respectively.
d The function rbinom can be used in order to simulate a random sample from this
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 9 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
2 Poisson:
Chapter a The parameter that determines the distribution is the expectation λ.
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 10 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
2 Poisson:
Chapter a The parameter that determines the distribution is the expectation λ.
Objectives
Theoretical b The expression P oisson(λ) is used to mark the Poisson distribution.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 10 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
2 Poisson:
Chapter a The parameter that determines the distribution is the expectation λ.
Objectives
Theoretical b The expression P oisson(λ) is used to mark the Poisson distribution.
Distributions of
Observations c The functions dpois, ppois, and qpois may be used in order to compute the
Simulations
probability, the cumulative probability, and the percentiles, respectively, for the
Poisson distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 10 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
2 Poisson:
Chapter a The parameter that determines the distribution is the expectation λ.
Objectives
Theoretical b The expression P oisson(λ) is used to mark the Poisson distribution.
Distributions of
Observations c The functions dpois, ppois, and qpois may be used in order to compute the
Simulations
probability, the cumulative probability, and the percentiles, respectively, for the
Poisson distribution.
d The function rpois can be used in order to simulate a random sample from this
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 10 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
3 Uniform:
Chapter a The parameters that determine the distribution are a and b, the two end points
Objectives
Theoretical of the interval.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 11 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
3 Uniform:
Chapter a The parameters that determine the distribution are a and b, the two end points
Objectives
Theoretical of the interval.
Distributions of
Observations b The expression U nif orm(a, b) is used to identify the Uniform distribution.
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 11 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
3 Uniform:
Chapter a The parameters that determine the distribution are a and b, the two end points
Objectives
Theoretical of the interval.
Distributions of
Observations b The expression U nif orm(a, b) is used to identify the Uniform distribution.
Simulations
c The functions dunif , punif , and qunif may be used in order to compute the
density, the cumulative probability, and the percentiles for the Uniform distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 11 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
3 Uniform:
Chapter a The parameters that determine the distribution are a and b, the two end points
Objectives
Theoretical of the interval.
Distributions of
Observations b The expression U nif orm(a, b) is used to identify the Uniform distribution.
Simulations
c The functions dunif , punif , and qunif may be used in order to compute the
density, the cumulative probability, and the percentiles for the Uniform distribution.
d The function runif can be used in order to simulate a random sample from this
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 11 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 Exponential:
Chapter a The parameter that determines the distribution is the rate λ.
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 12 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 Exponential:
Chapter a The parameter that determines the distribution is the rate λ.
Objectives
Theoretical b The expression Exponential(λ) is used to identify the Exponential distribution.
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 12 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 Exponential:
Chapter a The parameter that determines the distribution is the rate λ.
Objectives
Theoretical b The expression Exponential(λ) is used to identify the Exponential distribution.
Distributions of
Observations c The functions dexp, pexp, and qexp may be used in order to compute the density,
Simulations
the cumulative probability, and the percentiles, respectively, for the Exponential
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 12 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 Exponential:
Chapter a The parameter that determines the distribution is the rate λ.
Objectives
Theoretical b The expression Exponential(λ) is used to identify the Exponential distribution.
Distributions of
Observations c The functions dexp, pexp, and qexp may be used in order to compute the density,
Simulations
the cumulative probability, and the percentiles, respectively, for the Exponential
distribution.
d The function rexp can be used in order to simulate a random sample from this
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 12 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
5 Normal:
Chapter a The parameters that determine the distribution are the expectation µ and the
Objectives
Theoretical variance σ 2 .
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 13 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
5 Normal:
Chapter a The parameters that determine the distribution are the expectation µ and the
Objectives
Theoretical variance σ 2 .
Distributions of
Observations b The expression N ormal(µ, σ 2 ) is used to mark the Normal distribution.
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 13 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
5 Normal:
Chapter a The parameters that determine the distribution are the expectation µ and the
Objectives
Theoretical variance σ 2 .
Distributions of
Observations b The expression N ormal(µ, σ 2 ) is used to mark the Normal distribution.
Simulations
c The functions dnorm, pnorm, and qnorm may be used in order to compute the
density, the cumulative probability, and the percentiles for the Normal distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 13 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
5 Normal:
Chapter a The parameters that determine the distribution are the expectation µ and the
Objectives
Theoretical variance σ 2 .
Distributions of
Observations b The expression N ormal(µ, σ 2 ) is used to mark the Normal distribution.
Simulations
c The functions dnorm, pnorm, and qnorm may be used in order to compute the
density, the cumulative probability, and the percentiles for the Normal distribution.
d The function rnorm can be used in order to simulate a random sample from this
distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 13 / 29
Simulations

Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
One of the most problems of statistical inference is using the Nor-
Objectives
Theoretical
Distributions of
mal approximation for the sampling distribution of the statistic.
Observations
Simulations However, every now and then we may want to check the validity
of this approximation in order to reassure ourselves of its appro-
priateness.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 14 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives Example 2
Theoretical
Distributions of
Observations
Simulations
Compute a simulation for the sample size of n = 201 and for
exponential distribution with parameter equal to λ = 1/12000.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 15 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly > X.bar < − rep(0, 105 )
Chapter > f or(i in 1 : 105 )
Objectives
Theoretical
Distributions of
+{
Observations
Simulations +X < − rexp(201, 1/12000)
+X.bar[i] < − mean(X)
+}
> mean(abs(X.bar − 12000) <= 1.96 ∗ 0.0705 ∗ 12000)

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 16 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly The expression for generating a sample is rexp(201, 1/12000).
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 17 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly The expression for generating a sample is rexp(201, 1/12000).
Chapter In the case where the simulated averages are stored in the
Objectives
Theoretical
Distributions of sequence X.bar then we may use the expression
Observations
Simulations
mean(abs(X.bar − 12000) <= 1.96 ∗ 0.0705 ∗ 12000).

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 17 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly The expression for generating a sample is rexp(201, 1/12000).
Chapter In the case where the simulated averages are stored in the
Objectives
Theoretical
Distributions of sequence X.bar then we may use the expression
Observations
Simulations
mean(abs(X.bar − 12000) <= 1.96 ∗ 0.0705 ∗ 12000).
In order to compute the relative frequency for the uniform
distribution U nif orm(3; 7), with sample size n = 100, use
the expression runif (100, 3, 7).

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 17 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
Example 3
Chapter
Objectives
Theoretical
Carry out the simulation that produces an approximation of
Distributions of
Observations
Simulations the central region that contains 95% of the sampling distri-
bution of the mid-range statistic for the Uniform distribution,
U nif orm(3; 7):

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 18 / 29
Lecture 7:
Statistical
Inference
> mid.range < − rep(0, 105 )
Assoc. Prof.
Amany E. Aly
> f or(i in1 : 105 )
Chapter
Objectives
+{
Theoretical
Distributions of
Observations
+X < − runif (100, 3, 7)
+mid.range[i] < − (max(X) + min(X))/2
Simulations

+}
> quantile(mid.range, c(0.025, 0.975))
2.5% 97.5%
4.941680 5.059004

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 19 / 29
Lecture 7:
Statistical
Inference 1 Observe that (approximately) 95% of the sampling distribution
Assoc. Prof.
Amany E. Aly of the statistic are in the range [4.941680, 5.059004].
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 20 / 29
Lecture 7:
Statistical
Inference 1 Observe that (approximately) 95% of the sampling distribution
Assoc. Prof.
Amany E. Aly of the statistic are in the range [4.941680, 5.059004].
Chapter
Objectives
2 If the sample is stored in an object by the name X then
Theoretical
Distributions of
Observations
one may compute the mid-range statistic with the expression
Simulations
(max(X) + min(X))/2.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 20 / 29
Lecture 7:
Statistical
Inference 1 Observe that (approximately) 95% of the sampling distribution
Assoc. Prof.
Amany E. Aly of the statistic are in the range [4.941680, 5.059004].
Chapter
Objectives
2 If the sample is stored in an object by the name X then
Theoretical
Distributions of
Observations
one may compute the mid-range statistic with the expression
Simulations
(max(X) + min(X))/2.
3 If the simulated values of the statistic are stored in a sequence
by the name mid.range then the 0.025−percentile and the
0.975−percentile of the sequence can be computed with the
expression quantile(mid.range, c(0.025, 0.975)).
Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture
Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 20 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
Simulations can be used in order to compute the expectation,
Chapter
Objectives the standard deviation or any other numerical summary of the
Theoretical
Distributions of
Observations sampling distribution of a statistic.
Simulations
All one needs to do is compute the required summary for the
simulated sequence of statistic values and hence obtain an ap-
proximation of the required summary.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 21 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Example 4
Amany E. Aly
Obtain the expectation and the standard deviation of the
Chapter
Objectives mid-range statistic of a sample of 100 observations from the
Theoretical
Distributions of
Observations
Simulations
U nif orm(3, 7) distribution.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 22 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Example 4
Amany E. Aly
Obtain the expectation and the standard deviation of the
Chapter
Objectives mid-range statistic of a sample of 100 observations from the
Theoretical
Distributions of
Observations
Simulations
U nif orm(3, 7) distribution.

> mean(mid.range)
[1]5.000168
> sd(mid.range)
[1] 0.02767719

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 22 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
The expectation of the statistic is obtained by the application
Theoretical
Distributions of
Observations
of the function mean to the sequence.
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 23 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
The expectation of the statistic is obtained by the application
Theoretical
Distributions of
Observations
of the function mean to the sequence.
Simulations

The standard deviation is obtained by the application of the


function sd.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 23 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly

Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.

Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives 3 What is the sample average of the change in score between the patient’s rating before the
Theoretical
Distributions of application of the device and the rating after the application?
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives 3 What is the sample average of the change in score between the patient’s rating before the
Theoretical
Distributions of application of the device and the rating after the application?
Observations
Simulations
4 Is the variable active a factor or a numeric variable?

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives 3 What is the sample average of the change in score between the patient’s rating before the
Theoretical
Distributions of application of the device and the rating after the application?
Observations
Simulations
4 Is the variable active a factor or a numeric variable?
5 Compute the average value of the variable change for the patients that received and active
magnet and average value for those that received an inactive placebo.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives 3 What is the sample average of the change in score between the patient’s rating before the
Theoretical
Distributions of application of the device and the rating after the application?
Observations
Simulations
4 Is the variable active a factor or a numeric variable?
5 Compute the average value of the variable change for the patients that received and active
magnet and average value for those that received an inactive placebo.
6 Compute the sample standard deviation of the variable change for the patients that received
and active magnet and the sample standard deviation for those that received an inactive
placebo.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7: Example 5
Statistical
Inference The data for the 50 patients is stored in file magnets.csv.
Assoc. Prof.
Amany E. Aly 1 Read the content of the file into an R data frame.
2 Produce a summary of the content of the data frame.
Chapter
Objectives 3 What is the sample average of the change in score between the patient’s rating before the
Theoretical
Distributions of application of the device and the rating after the application?
Observations
Simulations
4 Is the variable active a factor or a numeric variable?
5 Compute the average value of the variable change for the patients that received and active
magnet and average value for those that received an inactive placebo.
6 Compute the sample standard deviation of the variable change for the patients that received
and active magnet and the sample standard deviation for those that received an inactive
placebo.
7 Produce a boxplot of the variable change for the patients that received and active magnet
and for patients that received an inactive placebo. What is the number of outliers in each
subsequence?
Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture
Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 24 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly Hint:
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 25 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly Hint:
Chapter
Objectives Notice that the first 29 patients received an active magnet and
Theoretical
Distributions of
Observations
the last 21 patients received an inactive placebo.
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 25 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly Hint:
Chapter
Objectives Notice that the first 29 patients received an active magnet and
Theoretical
Distributions of
Observations
the last 21 patients received an inactive placebo.
Simulations

The subsequence of the first 29 values of the given variables


can be obtained via the expression change[1 : 29] and the last
21 values are obtained via the expression change[30 : 50].

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 25 / 29
Lecture 7:
Statistical
Inference
Solution:
Assoc. Prof.
Amany E. Aly
1 > magnets < − read.csv(”magnets.csv”)
Chapter
Objectives > summary(magnets)
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 26 / 29
Lecture 7:
Statistical
Inference
Solution:
Assoc. Prof.
Amany E. Aly
1 > magnets < − read.csv(”magnets.csv”)
Chapter
Objectives > summary(magnets)
Theoretical
Distributions of
Observations
Simulations
2 The variable active is a factor.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 26 / 29
Lecture 7:
Statistical
Inference
Solution:
Assoc. Prof.
Amany E. Aly
1 > magnets < − read.csv(”magnets.csv”)
Chapter
Objectives > summary(magnets)
Theoretical
Distributions of
Observations
Simulations
2 The variable active is a factor.
3 > mean(magnets$change[1 : 29])
[1] 5.241379
> mean(magnets$change[30 : 50])
[1] 1.095238

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 26 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 > sd(magnets$change[1 : 29])
Chapter
Objectives [1] 3.236568
Theoretical
Distributions of
Observations > sd(magnets$change[30 : 50])
Simulations
[1] 1.578124

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 27 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly
4 > sd(magnets$change[1 : 29])
Chapter
Objectives [1] 3.236568
Theoretical
Distributions of
Observations > sd(magnets$change[30 : 50])
Simulations
[1] 1.578124
5 > boxplot(magnets$change[1 : 29])
> boxplot(magnets$change[30 : 50])

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 27 / 29
Lecture 7:
Statistical 5-a The first box-plot correspond to the sub-sequence of the pa-
Inference

Assoc. Prof. tients that received an active magnet. There are no outliers
Amany E. Aly
in this plot.
Chapter
Objectives
Theoretical
Distributions of
Observations
Simulations

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 28 / 29
Lecture 7:
Statistical 5-a The first box-plot correspond to the sub-sequence of the pa-
Inference

Assoc. Prof. tients that received an active magnet. There are no outliers
Amany E. Aly
in this plot.
Chapter
Objectives
Theoretical
5-b The second box-plot correspond to the sub-sequence of the
Distributions of
Observations
Simulations
patients that received aa inactive placebo. Three values, the
values 3, 4, and 5 are associated with outliers.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 28 / 29
Lecture 7:
Statistical 5-a The first box-plot correspond to the sub-sequence of the pa-
Inference

Assoc. Prof. tients that received an active magnet. There are no outliers
Amany E. Aly
in this plot.
Chapter
Objectives
Theoretical
5-b The second box-plot correspond to the sub-sequence of the
Distributions of
Observations
Simulations
patients that received aa inactive placebo. Three values, the
values 3, 4, and 5 are associated with outliers.
5-c To find the total number of observations that receive these
values:
> table(magnets$change[30 : 50])
0 1 2 3 4 5
11 5 1 1 2 1
Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture
Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 28 / 29
Lecture 7:
Statistical
Inference

Assoc. Prof.
Amany E. Aly

Chapter
Objectives
Theoretical
Distributions of
H.W.
Observations
Simulations
Solve Question 9.2. page 155.

Assoc. Prof. Amany E. Aly ( Department of Mathematics, Faculty ofLecture


Science,7: Helwan
Statistical
University,
InferenceAin Helwan, Cairo, Egypt.) 20 / 3 / 2023 29 / 29

You might also like