



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




For this assignment, I chose a dataset, elaborated by UIISS - Unified interdepartmental information and statistical system, describing alcohol consumption in Russia during 1998-2016.
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)
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).
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")
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.
summ <- summary(ols)
summ
y2_response <- sum(bet0+bet1*5.19)
y2_response
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)
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:
The posterior 95% credible interval of the model parameters can be obtained as:
posterior_interval(Bayes)
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")
This inferences are identical to the earlier results with the prior.
Kaggle UIISS - Unified interdepartmental information and statistical system