\documentclass[12pt]{article}

\usepackage{Math203}

\usepackage{amsmath,amssymb}
\usepackage{hyperref}
\usepackage{color}
\usepackage{xcolor}
\usepackage{enumitem}

\pagestyle{plain}

\renewcommand{\labelenumi}{\arabic{enumi}.}
\renewcommand{\labelenumii}{\arabic{enumi}.\arabic{enumii}}
\renewcommand{\labelenumiii}{\arabic{enumi}.\arabic{enumii}.\arabic{enumiii}}

\setlength{\topmargin}{-0.75 in} \setlength{\textheight}{9.5 in}

\parindent0in

\newenvironment{packed_enum}{
\begin{enumerate}
  \setlength{\itemsep}{12pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
  \setlength{\topsep}{0pt}
}{\end{enumerate}}

\renewcommand{\labelitemii}{$\blacktriangleright$}

\def\ctitle{Math 203: Principles of Statistics 1}
\def\ttitle{Fall 2024}
\def\stitle{Populations, Experimental Units, Samples}

\makeatletter
\def\@maketitle{%
  \newpage
  \null
  \begin{center}%
    {\textsclarge{\ctitle} \par}%
    \medskip
    {\textsclarge{\ttitle} \par}%
    \medskip
    {\textsc{\stitle} \par}
  \end{center}%
  \par
  \vskip 1.5em}
\makeatother

\begin{document}

<<funcs,echo=FALSE>>=
myrnd <- function(x,d) {formatC(x, format="f", digits=d)}
library(shape)
library(diagram)
@

\maketitle

\begin{enumerate}[label=\arabic*.]

\item \textbf{Experimental units:}

\begin{itemize}
  \item the `objects' or `things' on which we will be making measurements ?
  \item we identify the experimental units \textbf{before} we actually take any measurements;

\end{itemize}

\item \textbf{Population:}

\begin{itemize}
  \item the entire collection of experimental units;
  \item could be a finite collection, or could be large enough to be regarded as infinite.
\end{itemize}

\item \textbf{Sample:}

\begin{itemize}
  \item the collection of \textbf{actual} experimental units on which we \textbf{do} make measurements;
  \item `the sample' is also used to refer to the recorded measurements themselves;
  \item we are only able to take a \textbf{finite} sample;
  \item we will usually need to make some assumptions about \textbf{how} the sample is collected.
\end{itemize}

\end{enumerate}
In the following plots we have a reasonably large population of size $N=2500$ where the experimental units are represented using a green circle.

\bigskip

Note: here the population is large but finite, but sometimes we can conceptualize the population as infinite (if we can imagine collecting data indefinitely on different experimental units), or to be so large we can treat it as infinite.


<<chunk1,fig.height=8, fig.width=8, echo=FALSE>>=
colorBlindBlack8  <- c("#000000", "#E69F00", "#56B4E9", "#009E73",
                       "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
colorBlindBlack8 <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
colorBlindBlack8<-palette.colors(8,'R4')

scol<-colorBlindBlack8[2]
col1<-colorBlindBlack8[3]
col2<-colorBlindBlack8[4]
set.seed(191)
x<-y<-seq(1,50,by=1)
xy<-expand.grid(x,y)
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
title('The population')
@

The population is the entire collection of experimental units on which we could take measurements to study the variable of interest.

\medskip

The population comprises experimental units that (with respect to the variable of interest) are believed to be comparable.  Here the population is large, but finite.


<<chunk2,fig.height=8, fig.width=8, echo=FALSE>>=
z<-sample(1:nrow(xy),rep=F,size=100)
zr<-z
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
points(xy[z,1],xy[z,2],pch=21,bg=scol,col=scol,cex=1.2)
title('The sample')
@

In the sample of size $n=100$, we select a collection of the experimental units and make the measurements.

\medskip

Here, the sample comprises measurements on typical experimental units; the sampled units are representative of units in the population.

<<chunk3,fig.height=8, fig.width=8, echo=FALSE>>=
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[z,1],xy[z,2],pch=21,bg=scol,col=scol,cex=1.2)
title('The sample')
@

Sometimes, we start by collecting the sample, and considering what population it is representative of.

\pagebreak

If we were able to make measurements on the \textbf{entire} population, we would know with certainty all of the characteristics of the population.

<<chunk4,fig.height=4.75, fig.width=8, echo=FALSE>>=
par(mar=c(4,3,3,2))
Z<-rnorm(nrow(xy),10,4)
hist(Z,nclass=50,main='Measurements on entire population',xlab='x',xlim=range(Z));box()
@

We might wish to report the population mean: in this case it is $\mu=\Sexpr{myrnd(mean(Z),3)}$.

<<chunk5,fig.height=4.75, fig.width=8, echo=FALSE>>=
par(mar=c(4,3,3,2))
hist(Z[z],nclass=50,main='Measurements on sample',xlab='x',xlim=range(Z));box()
@
In the sample, we only see a subset of the measured values. The sample mean is $\overline{x}=\Sexpr{myrnd(mean(Z[z]),3)}$


\pagebreak
If we could ultimately collect measurements from \textbf{all} experimental units, then we see that the sample mean will `converge' to the population mean; in the next plot, the running sample means from five studies that eventually collect data from all experimental units are plotted.

<<chunk5a,fig.height=6, fig.width=8, echo=FALSE>>=
N<-nrow(xy)
par(mar=c(5,5,3,2))
plot(1:N, cumsum(Z)/c(1:N), type='l', xlab='Sample size', ylab='Sample mean',ylim=range(5,15))
lines(1:N, cumsum(Z[sample(1:N,size=N)])/c(1:N))
lines(1:N, cumsum(Z[sample(1:N,size=N)])/c(1:N))
lines(1:N, cumsum(Z[sample(1:N,size=N)])/c(1:N))
lines(1:N, cumsum(Z[sample(1:N,size=N)])/c(1:N))
@

Ultimately, we see that all five studies yield $\overline{x}= \mu$, when the sample size $n$ reaches the population size $N$.

\pagebreak

<<chunk6,fig.height=8, fig.width=8, echo=FALSE>>=
z<-c(1:nrow(xy))[xy[,1]<=10 & xy[,2] <=10]
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
points(xy[z,1],xy[z,2],pch=21,bg=scol,col=scol,cex=1.2)
title('Another sample')
@

In this case, the sample is still representative of the population.  Here, the sample mean is $\overline{x}=\Sexpr{myrnd(mean(Z[z]),3)}$.

\pagebreak

<<chunk7,fig.height=8, fig.width=8, echo=FALSE>>=
z<-c(1:nrow(xy))[xy[,1]<=25]
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
points(xy[z,1],xy[z,2],pch=21,bg=col2,col=col2,cex=1.2)
title('Two populations')
@

Here there are two large populations that have different characteristics.  Suppose the population means are $\Sexpr{myrnd(mean(Z[z])+5,3)}$ (for the blue circles) and $\Sexpr{myrnd(mean(Z[-z]),3)}$ (for the green circles).

\pagebreak

<<chunk8,fig.height=8, fig.width=8, echo=FALSE>>=
z<-c(1:nrow(xy))[xy[,1]<=25]
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
points(xy[z,1],xy[z,2],pch=21,bg=col2,col=col2,cex=1.2)
zs<-c(1:nrow(xy))[xy[,1]<=10 & xy[,2] <=10]
points(xy[zs,1],xy[zs,2],pch=21,bg=scol,col=scol,cex=1.2)
title('Sample from one of the populations')
@

Here the sample is representative of the blue population:  the sample mean is $\overline{x}=\Sexpr{myrnd(mean(Z[zs])+5,3)}$.

\pagebreak

<<chunk9,fig.height=8, fig.width=8, echo=FALSE>>=
z<-c(1:nrow(xy))[xy[,1]<=25]
par(pty='s',mar=c(2,2,2,2))
plot(xy[,1],xy[,2],type='n',xlim=range(0,50),ylim=range(0,50),axes=FALSE,xlab='',ylab='')
points(xy[,1],xy[,2],pch=21,col=col1,bg=col1,cex=1.2)
points(xy[z,1],xy[z,2],pch=21,bg=col2,col=col2,cex=1.2)
points(xy[zr,1],xy[zr,2],pch=21,bg=scol,col=scol,cex=1.2)
title('Sample from the combined populations')
Z1<-Z
Z1[z]<-Z1[z]+5
@

Here the sample is not representative of either population:  the sample mean is $\overline{x}=\Sexpr{myrnd(mean(Z1[zr]),3)}$

\end{document} 