Stat 23 Lecture Notes
Stat 23 Lecture Notes
1. Definition of Statistics The building blocks of statistical science are data. Specific
characteristics (e.g., age, height, and weight) that we want to
• In its plural sense, it refers to the data itself or to some assess for a certain population are referred to as variables.
numerical computations derived from a set of data that are Variables may be categorized further as qualitative and
systematically collected and analyzed. • In its singular sense, it quantitative variables.
refers to the scientific discipline consisting of the theory and
methods for processing collections of quantitative and Qualitative variables – These are variables that yield
qualitative data useful when making decisions in the face of observations by which individuals can be categorized according
uncertainty. to some characteristic or quality.
Universe – is the set of all entities under study, that is, the
collection of things or observational units under study. • Identity – the property that enables a person to
Variable – is a characteristic observed or measured on every distinguish one number from the other. They are
unit of the universe. recognized by the shapes of the way they are written.
Population - is the set of all possible values of the variable.
• Order – the property that numbers of observations are
Sample – is a subset of the population.
arranged in a sequence. For any integers A,B,A,B, we
Parameters – are numerical measures that describe the
can determine whether A>BA>B, A=BA=B, or B<AB<A.
population or universe of interest.
Statistics – are numerical measures of a sample. • Additivity – the property that allows us to add two or
Frame – a listing of all the elements in a population. more numbers. For any real numbers A,B,CA,B,C,
Census – the process in which information is gathered for all and DD, because of the equality of scale, we can
units in the population. determine if A−B=C−D,A−B>C−D.A−B=C−D,A−B>C−D.
• Absolute zero property means that there is a level at
which there is nothing of the characteristic being
TheRStudio
measured. • RStudio is an integrated development environment (IDE) for
R. It includes a console, syntax-highlighting editor that
• Nominal scale – the lowest level of measurement and is most supports direct code execution, as well as tools for plotting,
often used with variables that are qualitative in nature, rather history, debugging and workspace management.
than quantitative. • RStudio is available in open source and commercial editions
and runs on the desktop (Windows, Mac, and Linux).
- Examples: gender, eye color, smoking status and n • You can download the latest version of RStudio
ationality. at https://www.rstudio.com/products/rstudio/
- Data in the nominal scale possess only the property of identity. CurrentandchangingWorkingDirectoryinR
Thus, numbers or observations are only used to classify. For
example, in the variable gender, if 1 is assign to male and 2 is getwd()
for female, it does not necessarily mean that female is better ## [1] "D:/SY2223 1st sem/Stat23"
than male.
setwd("D:/DOST")
• Ordinal scale – data in this case possesses the property of
identity and order. getwd()
## [1] "D:/DOST"
• can rank-order the objects as to whether they possess
more, less or the same amount of the variables being
measured. Thus, we can determine setwd("D:/Extension Valencia District/Presentation")
whether A>B,A>B, or A=B,A=B, or A<B.A<B.
• We still cannot determine how much greater or dir() # Show the files in your working directory
less AA is less than BB in the attribute being
measured.
## [1] "Lecture1.html" "Lecture1.Rmd"
• Examples: level of educational attainment, military
ranks. "R-Presentation.Rmd"
• Interval scale – Data in this level possesses the properties of ## [4] "R Presentation.Rmd" "rsconnect"
identity, order and additivity but do not have the absolute zero
property.
- Examples: Celsius scale measurement of temperature StatisticsandProbabilityLessonswithR
and intelligence score.
*Lesson: Mean and Variance of a Random Variable
• Ratio scale – Data at this level possesses the properties of
identity, order, equality of scale and absolute zero. - Examples:
weight and height of persons. Question: What is the expected number of heads in tossing
a coin twice?
Introduction on the Use of R Program x<-c(0, 1, 2)
p<-c(.25, .5, .25)
Objectives coin<-rbind(x, p)
• Provide History and Overview of R
xbar<-sum(x*p)
xbar
• Guide in the installation of R and RStudio
## [1] 1
• Show Working/Changing Directory in R
• Incorporate the use of f R in some Statistics and Probability
Lessons Question: What is variance number of headsin tossing a
• Introduce basic commands in R coin twice?
• Introduce R Script and R Markdown x<-c(0, 1, 2)
• Install some R packages p<-c(.25, .5, .25)
• Illustrate: generate R data, data in R, and Export Excel Data in coin<-rbind(x, p)
R xbar<-sum(x*p)
xbarobs<-c(1, 1, 1)
History and Overview of R variance<-sum(p*(x-xbarobs)^2)
• R is an independent open-source implementation of a variance
statistical analysis system developed by Ross Ihaka and ## [1] 0.5
Robert Gentleman at the University of Auckland in 1995.
• R can be used both as a programming language, and as a
piece of software. It can be used for data manipulation, *Lesson: Binomial Probability Distribution
calculation, and graphical display.
• One of the biggest advantages of R is that it can be Question: You flip a fair coin 5 times, what is the
distributed for free. probability of getting 4 or 5 heads?
• R is freely downloaded on the internet bn4<-dbinom(4, 5, 0.5)
bn5<-dbinom(5, 5, 0.5)
The R Installation bntotal<-bn4+bn5
• Obtain a copy of an R language installer from a dependable bntotal
source or directly from the Internet. The URL ## [1] 0.1875
is http://cran.r-project.org/
• The latest version of R is 4.0.5
Or using the pbinom function:
• Once the installation is done, start R by clicking the Desktop
icon for R
bntotalalt<-1-pbinom(3, 5, .5)
TheRConsole bntotalalt
• Along the top of the window is a limited set of menus, which ## [1] 0.1875
can be used for various tasks including opening, loading, and
saving script windows, loading and saving your workspace,
and installing packages. *Lesson: Normal Distribution
• When you open an R session (i.e. start the R program), the R
console opens and you are presented with a screen like this: Question: Suppose that diastolic blood pressures (DBPs)
from men aged 30-44 are normally distributed with a
mean of 85mmHg and a standard deviation of 10 mmHg.
What is the probability that a random 30–44-year-old has o Make the statistical decision:
a DBP less than 80? ▪ If decision rule is based on
region of rejection: Check if test
pnorm(80,mean=85,sd=10,lower.tail = TRUE) statistic falls in the region of
rejection. If yes, reject the null
## [1] 0.3085375 hypothesis.
▪ If decision rule is based on p-
Question: Brain volume for adult men is normally value: Determine the p-value. If
distributed with a mean of about 1,100 cc with a standard the p-value is less than or equal
deviation of 70 cc. What brain volume represents the 95th to reject the null hypothesis.
percentile? o Interpret results.
## [1] 1111.514 In this module, we’ll learn about the deference between a population
and a sample and why probability is the foundation for statistics and
data science. At the end of this Module, students should be able to:
*Estimation and Hypothesis Testing
➢ Explain why probability theory is relevant to statistics and data
Question: In a population of interest, a sample of 9 men
yielded a sample average brain volume of 1,100cc and a science.
standard deviation of 30cc. What is a 95% Student’s T ➢ Describe what it means to predict the outcome of an experiment
confidence interval for the mean brain volume in this new
population? and organize the outcomes into sample spaces.
n<-9 ➢ Calculate probabilities of events using the Axioms of Probability.
mu<-1100 ➢ Understand permutations and combinations and be able to
st.dev<-30 calculate probabilities when each simple event is equally likely
quantile = 0.975 # is 95% with 2.5% on both sides of the range
What is Statistics?
conf= mu + c(-1, 1) * qt(quantile, df=n-1) * st.dev/sqrt(n)
Statistics is the science of using data effectively to gain
conf
new knowledge. We need data to learn something new. We
## [1] 1076.94 1123.06 need to collect and analyze the data ethically.
AXIOMS OF PROBABILITY If B is the event that it takes at least 3 flips to obtain a tail,
Probability Theory: Foundation for Data Science with find P(B).
Anne Dougherly Bc , the complement of B, is the event that you obtain a tail
on the first or second flip.
P(Bc ) = P({1, 01})=1/2+1/4=3/4
Learning Goals
We also note:
In this module, we’ll learn about the difference between a P(S) = P(B [ Bc ) = P(B) + P(Bc ) = 1. So,
population and a sample and why probability is the P(B)=1 P(Bc )=1 3/4=1/4
foundation for statistics and data science. We’ll also begin Consequences of the Axioms
our study of the foundations of probability.
If A and B are two events contained in the same sample
➢ Explain why probability theory is relevant to statistics space S,
and data science.
➢ A \ Ac =; and A [ Ac = S so, 1 = P(S) = P(A [ Ac ) = P(A) +
P(Ac ) which implies P(Ac )=1 P(A)
➢ If A \ B = ;, then P(A \ B) = 0.
➢ P(A [ B) = P(A) + P(B) P(A \ B) Examples
These three consequences will help us calculate many Experiement: Roll a six-sided dice twice.
probabilities.
S = {(i, j) | i, j 2 {1, 2, 3, 4, 5, 6}}, |S| = 36 and each of the 36
Example 2 outcomes of S is equally likely.
Return to our car example: Recall a randomly selected car is ➢ Let A be the event of rolling a 1 on the first roll.
inspected for three defects. The sample space is P(A) =
➢ Let B be the event that the sum of the two rolls is 8.
S = {000, 100, 010, 001, 110, 101, 011, 111}. Consider the P(B) =
three events: ➢ Let C be the event that the value of the second roll is two
➢ A is the event defect 1 is present, A = {100, 110, 101, more than the first roll.
111} P(C) =
➢ B is the event defect 2 is present, B = {010, 110, 011,
Permutations
111}
➢ C is the event defect 3 is present, C = {001, 011, 101, Any ordered sequence of k objects taken from a set of n
111} distinct objects is called a permutation of size k. Notation:
Pk,n.
Example 2 continued
Example: Suppose an organization has 60 members. One
Suppose over many days, data is collected, and it is found person is selected at random to be the president, another
that 20% of the cars have defect 1, 25% have defect 2, and person is selected as the vice-president, and a third is
30% have defect 3. Further, 5% have defects 1 and 2, 7.5% selected as the treasurer. How many ways can this be done?
have defects 2 and 3, 6% have defects 1 and 3, and 1.5% (This would be the cardinality of the sample space.)
have all three.
Definition: n! = n(n 1)(n 2)··· 3 · 2 · 1 for any positive
Example 2 continued integer n. By definition, we take 0! = 1.
Calculate the probability of each of the following events for Combinations
the randomly selected car:
Given n distinct objects, any unordered subset of size k of
➢ defect 1 did not occur the objects is called a combination. Notation: Ck,n
➢ at least one defect occurs
➢ no defect occurs Example: Suppose we have 60 people and want to choose a
➢ defects 1 and 3 occur but 2 does not. 3person team (order is not important). How many
combinations are possible?
Example – continued
COUNTING: PERMUTATIONS AND
COMBINATIONS
this represents the number of combinations of size k chosen
Probability Theory: Foundation for Data Science with from n distinct objects.
Anne Dougherly
Example - continued
Learning Goals for Module 1
Example: Suppose we have the same 60 people, 35 are
In this module, we’ll learn about the difference between a female and 25 are male. We need to select a committee of
population and a sample and why probability is the 11 people.
foundation for statistics and data science. At the end of this
Module, students should be able to: ➢ How many ways can such a committee be formed?
➢ What is the probability that a randomly selected
➢ Explain why probability theory is relevant to statistics committee will contain at least 5 men and at least 5
and data science. women? (Assume each committee is equally likely.)
➢ Describe what it means to predict the outcome of an
experiment and organize the outcomes into sample Example: A city has bought 20 buses. Shortly after being put
spaces. into service, some of them develop cracks in the frame. The
➢ Calculate probabilities of events using the Axioms of buses are inspected and 8 have visible cracks.
Probability.
➢ How many ways can the city select a sample of 5 for
➢ Understand permutations and combinations and
thorough inspection? (Assume each bus is equally likely
be able to calculate probabilities when each simple
to be chosen.)
event is equally likely.
➢ If 5 buses are chosen at random, find the probability
Counting that exactly 4 have cracks.
➢ If 5 buses are chosen at random, find the probability
Recall that the goal of probability is to assign some number, that at least 4 have cracks.
P(A), called the probability of event A, which will give a
precise measure to the chance that A will occur. If a sample
space, S, has N single events, and if each of these events is
equally likely to occur, then we need only count the number
of events to find the probability.