library(readr)
income_data <- read_csv("income.data.csv")
## New names:
## Rows: 498 Columns: 3
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," dbl
## (3): ...1, income, happiness
## ℹ Use `spec()` to retrieve the full column specification for this data. ℹ
## Specify the column types or set `show_col_types = FALSE` to quiet this message.
## • `` -> `...1`
#View(income_data)
cor(income_data$happiness, income_data$income)
## [1] 0.8656337
Simple_Regression = lm( income_data$income ~ income_data$happiness)
summary(Simple_Regression)
##
## Call:
## lm(formula = income_data$income ~ income_data$happiness)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.94796 -0.57730 0.02277 0.55661 2.23185
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.90533 0.10039 9.018 <2e-16 ***
## income_data$happiness 1.04973 0.02726 38.505 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8708 on 496 degrees of freedom
## Multiple R-squared: 0.7493, Adjusted R-squared: 0.7488
## F-statistic: 1483 on 1 and 496 DF, p-value: < 2.2e-16
plot(income_data$happiness, income_data$income)
abline(Simple_Regression, col = "red", lwd = 2 )
Espera-se que a cada ponto em felicidade aumente-se em média 1.04973 na renda
anova(Simple_Regression)
## Analysis of Variance Table
##
## Response: income_data$income
## Df Sum Sq Mean Sq F value Pr(>F)
## income_data$happiness 1 1124.32 1124.32 1482.6 < 2.2e-16 ***
## Residuals 496 376.13 0.76
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qf(0.95, 1,496)
## [1] 3.860275
Como o Fcalculado é substânciamente maior que o Ftabelado, nós rejeitamos a hipotése nula, que o modelo não é significativo para a explicação dos dados