Overview of Inference

What is statistical inference?

Statistical inference provides methods for drawing conclusions about a population from sample data.

Overview of Inference

There are two prominent techniques involved in Statistical Inference

  • Confidence Intervals
  • Hypothesis Tests

We will talking about confidence intervals today.

Statistical Confidence

Here we have to involve a concept: CONFIDENCE LEVEL.

Confidence Level, or C, is the overall capture rate if the method is used many times.

If we want to call it “CONFIDENCE”, we need to reach 95%, which indicate in previous

*The Green and Blue parts together are 95%.

Confidence Interval Formula

To get the confidence interval, we need apply this formula

\[ \bar{x} \pm z * \frac{\sigma}{\sqrt{n}} \]

In this formula, \(\bar{x}\) represent the sample mean that we get from all Simple Random Sample

We need convert all these sample mean \(\bar{x}\) in Normal distribution \(X \sim \text{Normal}(\mu, \sigma)\)

Confidence Interval Calculation

We pick our simple random sample with 16 observations from Normal population with mean \(\mu\) and set standard deviation \(\sigma = 20\). We get a mean of random normal distribution \(\mu = 240.79\).

Also, we can use this formula to calculate number of observations we have

\[ n = \left(\frac{{z \cdot \sigma}}{m}\right)^2 \]

Confidence Interval Calculation

  • Continued from previous page

Then we plug value of \(\bar{x} = 240.79\) and number of observation n=16, standard deviation\(\sigma = 20\) in to the equation

\[ \bar{x} \pm z * \frac{\sigma}{\sqrt{n}} \] We can get \[ 240.79 \pm 1.96 * \frac{20}{\sqrt{16}} = (230.99, 250.59) \] This is our confidence interval.

Simple Example with Confidence band

There are several ways to plot confidence interval in ggplot

xAxis <- 1:200 
yAxis <- rnorm(200) + xAxis / 10 
lowBand <- yAxis + rnorm(200, - 1.5, 0.1) 
highBand <- yAxis + rnorm(200, + 1.5, 0.1)
sample_data <- data.frame(xAxis, yAxis, lowBand, highBand)

ggplot(sample_data, aes(xAxis, yAxis)) +    
          geom_point()+ 
  geom_ribbon(aes(ymin = lowBand, ymax = highBand),  
                      alpha = 0.2, fill="green", color="green")

Simple Example with Confidence band

Here are the explanation about those variables in previous page:

xAxis: Sequence from 1 to 200, representing the x-axis values.

yAxis: Normally distributed random values with a slight upward trend (xAxis / 10), representing the main data points.

lowBand and highBand:

Calculated as yAxis values plus random noise, centered around -1.5 and +1.5, respectively. These represent the lower and upper boundaries for a band around the yAxis values.

Simple Example with Confidence band

This is the plot show with confident band

Plotly for Confidence Interval

We will use the internal data “mtcars” as a simple example to express Confidence Interval in Plotly:

From this plot, the light blue band is confidence interval for each value

Confidence Interval with Regrassion

As previous page, we use “mtcars” for linear regression, with confidence interval