Note: Looking at life satisfaction in cantril ladder from world happiness report 2019 which has data going up to 2018 so will link that with 2018 meat consumption data to form an initial regression. We only have meat consumption for 47 locations (and 4 of them are groups of countries not individuals) rather than the 136 we have happiness data for. And then going the other way there isn’t happiness data for ghana, paraguay, sudan, south africa. Once you filter down to countries where we have both meat consumption and a happiness value it’s only 38 data points.
#this is to set a working directory
setwd("C:\\Users\\melvo\\Documents\\CCMF\\Quantitive methods\\Coursework\\Meat and Happiness")
#this checks the working directory
getwd()
## [1] "C:/Users/melvo/Documents/CCMF/Quantitive methods/Coursework/Meat and Happiness"
#selecting your dataset
meaty <- read.csv("meathappy_plot2018.csv")
Here comes a graph!
library(ggplot2)
ggplot(meaty, aes(x = meat, y = happiness)) +
geom_smooth(method = "lm", se = FALSE) +
geom_point()+theme_minimal()+
xlab("Meat Consumption kg/cap")+ylab("Happiness Score") + ggtitle("Relationship between meat consumption and happiness 2018")
## `geom_smooth()` using formula 'y ~ x'
reg1=lm(happiness~meat,meaty)
summary(reg1)
##
## Call:
## lm(formula = happiness ~ meat, data = meaty)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.24027 -0.60669 0.03098 0.59906 1.21575
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.370357 0.196046 22.293 < 2e-16 ***
## meat 0.022984 0.003339 6.883 4.67e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6867 on 36 degrees of freedom
## Multiple R-squared: 0.5682, Adjusted R-squared: 0.5563
## F-statistic: 47.38 on 1 and 36 DF, p-value: 4.671e-08
library(ggplot2)
ggplot(meaty, aes(x = gdppc, y = happiness)) +
geom_smooth(method = "lm", se = FALSE) +
geom_point()+theme_minimal()+
xlab("GDP per capita USD")+ylab("Happiness Score") + ggtitle("Relationship between GDP per capita and happiness 2018")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 1 rows containing non-finite values (stat_smooth).
## Warning: Removed 1 rows containing missing values (geom_point).
reg2=lm(happiness~gdppc,meaty)
summary(reg2)
##
## Call:
## lm(formula = happiness ~ gdppc, data = meaty)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.4897 -0.4638 0.1210 0.5181 1.2324
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.888e+00 1.500e-01 32.58 < 2e-16 ***
## gdppc 4.441e-05 6.832e-06 6.50 1.7e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.6999 on 35 degrees of freedom
## (1 observation deleted due to missingness)
## Multiple R-squared: 0.5469, Adjusted R-squared: 0.534
## F-statistic: 42.25 on 1 and 35 DF, p-value: 1.704e-07