04/13/2025

Intro

Statistical analysis is the process of gathering and processing large amounts of data in an attempt to uncover patterns or trends between various variables in a data set. Various statistical methods are commonly used to better understand the relationship between the sample data and the true larger population.

Simple Linear Regression

Simple linear regression is used to predict and model the relationship between two variables (one independent and another dependent). This method tries to find the best fitted linear model that can represent the relationship between the two variables with the data available within a certain confidence interval.

Simple Linear Regression Formula

The generic formula for simple linear regression is: \[\hat{y}=\beta_0+\beta_1(x)+\epsilon\]

Where \(\hat{y}\) is the dependent variable, x is the independent variable, \(\beta_0\) is the intercept, \(\beta_1\) is the slope, and \(\epsilon\) is the error term which represents the difference between the predicted value from the regression model and the true population’s value of the dependent variable.

Simple Linear Regression Ex.1

This is an example of a simple linear regression using the cars data set in R with a 95% confidence interval:

Simple Linear Regression Ex.2

Here is another example of simple linear regression using the Mtcars data set in R:

Point Estimation

Point estimation is the practice of using sample statistics to estimate a larger population’s parameter. Some common sample statistics that are used to estimate population parameters are:

  • Sample Mean \[\bar{x}=\displaystyle\frac{1}{n}\sum_{i=1}^n(x_i)\]
  • Sample Standard Deviation \[s=\displaystyle\sqrt{\sum\frac{(x_i-\bar{x})^2}{n-1}}\]
  • Sample Variance \[s^2=\displaystyle\frac{\sum(x_i-\bar{x})^2}{(n-1)}\]

Point Estimation Ex.1

We can demonstrate point estimation by taking the Diamonds data set in R and calculating the mean price per carat. This helps us estimate the true average price of the larger population, within a reason of error.

Point Estimation Ex.2

Here is another example using the Airquality data set in R to show the average temperature from of the sample per month to estimate the true average temperature each month from May to September.

Multivariable Analysis

R is a very powerful tool when conducting statistical analysis, you can create very intricate models and plots to represent the relationships between various variables in a data set. Below is an example of a plot_ly plot in R that represents four different variables from the Mtcars data set (Weight, Horsepower, MPG, and Displacement).

Code Ex.

Here is the code in R that was used to produce the last slide:

mtcars_3d_plot = plot_ly(mtcars,
                       x = ~wt,
                       y = ~disp,
                       z = ~mpg,
                       color = ~hp,
                       type = "scatter3d",
                       mode = "markers",
                       marker = list(size = 8,
                                   line = list(color = 'black',
                                               width = 4)))%>%
layout(title = "MPG vs. (Weight & Displacement)",
       scene = list(xaxis = list(title = "Weight"),
                  yaxis = list(title = "Displacement"),
                  zaxis = list(title = "Miles Per Gallon")))

mtcars_3d_plot

Conclusion

These tools and methods are extremely helpful when analyzing large sets of data. Simple linear regression is the starting point to more complex analysis, which then leads into the concept of point estimation, using sample data to make inferences of the larger population’s parameters. Finally, R can be a very powerful tool in statistics when handling and analyzing large sets of data, becoming more familiar with R will give you the ability to do more complex statistical models in and analysis.