Docsity

Assignment 2 di Applied Linear Models, Guide, Progetti e Ricerche di Modelli Stocastici E Analisi Dei Dati

Toggle sidebar
bg1
Assignement 2 - Simple linear regression
Sofia Di Girolamo
2020/2021
Alcohol Consumption in Russia from 1998 to 2016
For this assignment, I chose a dataset, elaborated by UIISS - Unified interdepartmental information and
statistical system, describing alcohol consumption in Russia during 1998-2016.
a. Least squares estimation
Given the data collected, I chose to fit a linear regression model with the data using the method of least
squares. I consider a linear model, where the response variable yrepresents the average number of litres of
wine sold in Russia from 1998 to 2016 coded as wine, and the predictor variable xrepresents the number of
litres vodka sold in Russia in the same period, coded as vodka. Fitting this model, I wanted to reach one of
the goals of this analysis: understanding how wine sells have been influenced by vodka sells.
alcohol <- read.csv("/Users/sofiamonicadigirolamo/documents/russia_alcohol.csv",header=T)
ols <- lm(wine ~ vodka, data=alcohol)
summary(ols)
##
## Call:
## lm(formula = wine ~ vodka, data = alcohol)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.5181 -2.0970 -0.0645 1.6656 12.1222
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.81496 0.17297 22.06 <2e-16 ***
## vodka 0.15322 0.01342 11.42 <2e-16 ***
## ---
## Signif. codes: 0 '***'0.001 '**'0.01 '*'0.05 '.'0.1 ' ' 1
##
## Residual standard error: 2.703 on 1550 degrees of freedom
## (63 observations deleted due to missingness)
## Multiple R-squared: 0.0776, Adjusted R-squared: 0.07701
## F-statistic: 130.4 on 1 and 1550 DF, p-value: < 2.2e-16
The model fits well the data: all the parameters estimated are statistically significant and also p-value related
to the F-test (< 2.2e-16) suggests this statement. Moreover, the R-squared related to the model is quite low
(=0.08).
1
pf3
pf4
pf5

Anteprima parziale del testo

Scarica Assignment 2 di Applied Linear Models e più Guide, Progetti e Ricerche in PDF di Modelli Stocastici E Analisi Dei Dati solo su Docsity!

Assignement 2 - Simple linear regression

Sofia Di Girolamo

Alcohol Consumption in Russia from 1998 to 2016

For this assignment, I chose a dataset, elaborated by UIISS - Unified interdepartmental information and statistical system, describing alcohol consumption in Russia during 1998-2016.

a. Least squares estimation

Given the data collected, I chose to fit a linear regression model with the data using the method of least squares. I consider a linear model, where the response variable y represents the average number of litres of wine sold in Russia from 1998 to 2016 coded as wine , and the predictor variable x represents the number of litres vodka sold in Russia in the same period, coded as vodka. Fitting this model, I wanted to reach one of the goals of this analysis: understanding how wine sells have been influenced by vodka sells. alcohol <- read.csv("/Users/sofiamonicadigirolamo/documents/russia_alcohol.csv",header=T) ols <- lm(wine ~ vodka, data=alcohol) summary(ols)

Call:

lm(formula = wine ~ vodka, data = alcohol)

Residuals:

Min 1Q Median 3Q Max

-5.5181 -2.0970 -0.0645 1.6656 12.

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 3.81496 0.17297 22.06 <2e-16 ***

vodka 0.15322 0.01342 11.42 <2e-16 ***

---

Signif. codes: 0 '' 0.001 '' 0.01 '' 0.05 '.' 0.1 ' ' 1

Residual standard error: 2.703 on 1550 degrees of freedom

(63 observations deleted due to missingness)

Multiple R-squared: 0.0776, Adjusted R-squared: 0.

F-statistic: 130.4 on 1 and 1550 DF, p-value: < 2.2e-

The model fits well the data: all the parameters estimated are statistically significant and also p-value related to the F-test (< 2.2e-16) suggests this statement. Moreover, the R-squared related to the model is quite low (=0.08).

b. Graphing the data with the fitted line

I graphed the data with a scatterplot, then I completed it adding the fitted line.

plot(alcohol$vodka, alcohol$wine, type="p", col="pink", xlab= "Avg number of litres of vodka sold", ylab= "Number of litres of wine sold", pch=1)

abline(ols, lw=2, col="green")

Avg number of litres of vodka sold

Number of litres of wine sold

The fitted line is y = 3.81 + 0.15 * x.

It’s easy to observe the pendency of the fitted line: it is definitely equal to the estimated parameter Beta.

c. Interpreting the estimated parameters and their uncertainties

summ <- summary(ols)

summ

Call:

lm(formula = wine ~ vodka, data = alcohol)

Residuals:

Min 1Q Median 3Q Max

-5.5181 -2.0970 -0.0645 1.6656 12.

Coefficients:

Estimate Std. Error t value Pr(>|t|)

(Intercept) 3.81496 0.17297 22.06 <2e-16 ***

vodka 0.15322 0.01342 11.42 <2e-16 ***

y2_response <- sum(bet0+bet1*5.19)

y2_response

[1] 4.

f. Bayesian approach

I tried to fit the model also with Bayesian approach of regression.

library("rstanarm")

Bayes <- stan_glm(wine ~ vodka, data = alcohol, refresh = 0) print(Bayes)

stan_glm

family: gaussian [identity]

formula: wine ~ vodka

observations: 1552

predictors: 2

------

Median MAD_SD

(Intercept) 3.8 0.

vodka 0.2 0.

Auxiliary parameter(s):

Median MAD_SD

sigma 2.7 0.

------

* For help interpreting the printed output see ?print.stanreg

* For info on the priors used see ?prior_summary.stanreg

Using the Bayesian approach, I obtained a model with the same values of the parameters estimated with the method of last square. With this approach, in fact, the intercept Beta0 results 3.8 and the slope Beta1 is equal to 0.2 (approximately the same value estimated with OLS). The difference between this approach and the method of least squares consists in the interpretation of the estimated parameters:

  1. Beta0 = 3.8. It can be interpreted as the probability at 95% that the parameter is equal to the estimated value of the same one.
  2. Beta1 = 0.2. It can be interpreted as the probability at 95% that the parameter is equal to the estimated value of the same one.

The posterior 95% credible interval of the model parameters can be obtained as:

posterior_interval(Bayes)

5% 95%

(Intercept) 3.5227911 4.

vodka 0.1314401 0.

sigma 2.6242691 2.

Moreover, I represented the histograms of the posterior simulation for the intercept Beta0 , the slope Beta and the residual standard error of the fitted model.

hist(beta0_sims, xlab=expression(beta[0]), ylab="", main="", col="yellow") abline(v = median(summ$coefficients[1,1]) , lwd = 2, col="green")

hist(beta1_sims, xlab=expression(beta[1]), ylab="", main="", col="blue") abline(v=median(summ$coefficients[2,1]),lwd = 2, col="purple")

stan_glm

family: gaussian [identity]

formula: wine ~ vodka

observations: 1552

predictors: 2

------

Median MAD_SD

(Intercept) 3.8 0.

vodka 0.2 0.

Auxiliary parameter(s):

Median MAD_SD

sigma 2.7 0.

------

* For help interpreting the printed output see ?print.stanreg

* For info on the priors used see ?prior_summary.stanreg

This inferences are identical to the earlier results with the prior.

References

Kaggle UIISS - Unified interdepartmental information and statistical system