What is statistical inference?
Statistical inference provides methods for drawing conclusions about a population from sample data.
What is statistical inference?
Statistical inference provides methods for drawing conclusions about a population from sample data.
There are two prominent techniques involved in Statistical Inference
We will talking about confidence intervals today.
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%.
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)\)
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 \]
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.
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")
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.
This is the plot show with confident band
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
As previous page, we use “mtcars” for linear regression, with confidence interval