#linear regression with & with out interception #1 WITH interception table 13
library(wooldridge)
library(rmarkdown)
data("fertil1")
paged_table(fertil1)
require(dplyr)
## Zorunlu paket yükleniyor: dplyr
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
fertil1 %>%
group_by(year) %>%
summarise(mean(kids))
## # A tibble: 7 × 2
## year `mean(kids)`
## <int> <dbl>
## 1 72 3.03
## 2 74 3.21
## 3 76 2.80
## 4 78 2.80
## 5 80 2.82
## 6 82 2.40
## 7 84 2.24
max(fertil1)
## [1] 2916
fertil1 %>%
group_by(year) %>%
summarise(mean(kids), sd(kids))
## # A tibble: 7 × 3
## year `mean(kids)` `sd(kids)`
## <int> <dbl> <dbl>
## 1 72 3.03 1.83
## 2 74 3.21 1.50
## 3 76 2.80 1.66
## 4 78 2.80 1.58
## 5 80 2.82 1.58
## 6 82 2.40 1.70
## 7 84 2.24 1.51
fertil1 %>%
group_by(year) %>%
summarise(across(everything(),mean))
## # A tibble: 7 × 27
## year educ meduc feduc age kids black east northcen west farm othru…¹
## <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 72 12.2 8.33 8.90 44.9 3.03 0.0833 0.333 0.231 0.128 0.173 0.0833
## 2 74 12.3 8.94 9.29 44.1 3.21 0.0578 0.237 0.353 0.110 0.208 0.110
## 3 76 12.2 8.25 8.99 43.5 2.80 0.0461 0.263 0.316 0.0855 0.237 0.112
## 4 78 12.6 9.07 9.80 43.4 2.80 0.0490 0.273 0.329 0.105 0.203 0.112
## 5 80 12.9 9.40 9.95 43.7 2.82 0.0704 0.141 0.394 0.155 0.218 0.106
## 6 82 13.2 9.56 10.2 43.2 2.40 0.199 0.231 0.290 0.0806 0.167 0.118
## 7 84 13.3 10.2 10.7 41.8 2.24 0.0678 0.260 0.333 0.102 0.192 0.0734
## # … with 15 more variables: town <dbl>, smcity <dbl>, y74 <dbl>, y76 <dbl>,
## # y78 <dbl>, y80 <dbl>, y82 <dbl>, y84 <dbl>, agesq <dbl>, y74educ <dbl>,
## # y76educ <dbl>, y78educ <dbl>, y80educ <dbl>, y82educ <dbl>, y84educ <dbl>,
## # and abbreviated variable name ¹othrural
summary(lm(formula = kids ~ educ + age + kids + black + east + west + farm + othrural + town + smcity + northcen + y74 + y76 + y78 + y80 + y82 + y84, data = fertil1))
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on the
## right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 3 in
## model.matrix: no columns are assigned
##
## Call:
## lm(formula = kids ~ educ + age + kids + black + east + west +
## farm + othrural + town + smcity + northcen + y74 + y76 +
## y78 + y80 + y82 + y84, data = fertil1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.3513 -1.0528 -0.0532 1.0103 4.7589
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.445625 0.472469 7.293 5.75e-13 ***
## educ -0.131316 0.018437 -7.122 1.90e-12 ***
## age 0.019556 0.008143 2.402 0.016488 *
## black 1.051224 0.174403 6.028 2.26e-09 ***
## east 0.220476 0.133545 1.651 0.099031 .
## west 0.170869 0.167712 1.019 0.308509
## farm -0.053842 0.148032 -0.364 0.716138
## othrural -0.160079 0.176445 -0.907 0.364471
## town 0.088927 0.125238 0.710 0.477810
## smcity 0.227803 0.161156 1.414 0.157771
## northcen 0.350287 0.121539 2.882 0.004026 **
## y74 0.239607 0.173532 1.381 0.167629
## y76 -0.141232 0.179678 -0.786 0.432018
## y78 -0.107941 0.182413 -0.592 0.554146
## y80 -0.090874 0.183740 -0.495 0.620995
## y82 -0.553466 0.173220 -3.195 0.001437 **
## y84 -0.589178 0.175109 -3.365 0.000793 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.564 on 1112 degrees of freedom
## Multiple R-squared: 0.1187, Adjusted R-squared: 0.106
## F-statistic: 9.363 on 16 and 1112 DF, p-value: < 2.2e-16
fertil1 %>%
group_by(year) %>%
plot(fertil1)
#2 linear regression WITHOUT intercept
#we can do linear regression without intercept in 3 different way
summary(lm(formula = kids ~ 0 + educ + age + kids + black + east + west + farm + othrural + town + smcity + northcen + y74 + y76 + y78 + y80 + y82 + y84, data = fertil1))
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on the
## right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 3 in
## model.matrix: no columns are assigned
##
## Call:
## lm(formula = kids ~ 0 + educ + age + kids + black + east + west +
## farm + othrural + town + smcity + northcen + y74 + y76 +
## y78 + y80 + y82 + y84, data = fertil1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.9406 -1.0116 -0.0284 1.0615 4.8716
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## educ -0.059614 0.015958 -3.736 0.000197 ***
## age 0.067067 0.004998 13.417 < 2e-16 ***
## black 1.159675 0.177795 6.523 1.05e-10 ***
## east 0.349080 0.135444 2.577 0.010085 *
## west 0.306814 0.170536 1.799 0.072270 .
## farm 0.128938 0.149276 0.864 0.387907
## othrural 0.087305 0.177166 0.493 0.622261
## town 0.217314 0.126868 1.713 0.087006 .
## smcity 0.352197 0.163964 2.148 0.031928 *
## northcen 0.438681 0.123736 3.545 0.000408 ***
## y74 0.508975 0.173485 2.934 0.003417 **
## y76 0.153246 0.179139 0.855 0.392483
## y78 0.161320 0.182778 0.883 0.377641
## y80 0.151723 0.184892 0.821 0.412048
## y82 -0.309474 0.173897 -1.780 0.075407 .
## y84 -0.279759 0.173829 -1.609 0.107814
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.6 on 1113 degrees of freedom
## Multiple R-squared: 0.754, Adjusted R-squared: 0.7504
## F-statistic: 213.2 on 16 and 1113 DF, p-value: < 2.2e-16
#way 2
summary(lm(formula = kids ~ educ + age + kids + black + east + west + farm + othrural + town + smcity + northcen + y74 + y76 + y78 + y80 + y82 + y84 -1, data = fertil1))
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on the
## right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 3 in
## model.matrix: no columns are assigned
##
## Call:
## lm(formula = kids ~ educ + age + kids + black + east + west +
## farm + othrural + town + smcity + northcen + y74 + y76 +
## y78 + y80 + y82 + y84 - 1, data = fertil1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.9406 -1.0116 -0.0284 1.0615 4.8716
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## educ -0.059614 0.015958 -3.736 0.000197 ***
## age 0.067067 0.004998 13.417 < 2e-16 ***
## black 1.159675 0.177795 6.523 1.05e-10 ***
## east 0.349080 0.135444 2.577 0.010085 *
## west 0.306814 0.170536 1.799 0.072270 .
## farm 0.128938 0.149276 0.864 0.387907
## othrural 0.087305 0.177166 0.493 0.622261
## town 0.217314 0.126868 1.713 0.087006 .
## smcity 0.352197 0.163964 2.148 0.031928 *
## northcen 0.438681 0.123736 3.545 0.000408 ***
## y74 0.508975 0.173485 2.934 0.003417 **
## y76 0.153246 0.179139 0.855 0.392483
## y78 0.161320 0.182778 0.883 0.377641
## y80 0.151723 0.184892 0.821 0.412048
## y82 -0.309474 0.173897 -1.780 0.075407 .
## y84 -0.279759 0.173829 -1.609 0.107814
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.6 on 1113 degrees of freedom
## Multiple R-squared: 0.754, Adjusted R-squared: 0.7504
## F-statistic: 213.2 on 16 and 1113 DF, p-value: < 2.2e-16
summary(lm(formula = kids ~ educ + age + kids + black + east + west + farm + othrural + town + smcity + northcen + y74 + y76 + y78 + y80 + y82 + y84 + 0, data = fertil1))
## Warning in model.matrix.default(mt, mf, contrasts): the response appeared on the
## right-hand side and was dropped
## Warning in model.matrix.default(mt, mf, contrasts): problem with term 3 in
## model.matrix: no columns are assigned
##
## Call:
## lm(formula = kids ~ educ + age + kids + black + east + west +
## farm + othrural + town + smcity + northcen + y74 + y76 +
## y78 + y80 + y82 + y84 + 0, data = fertil1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.9406 -1.0116 -0.0284 1.0615 4.8716
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## educ -0.059614 0.015958 -3.736 0.000197 ***
## age 0.067067 0.004998 13.417 < 2e-16 ***
## black 1.159675 0.177795 6.523 1.05e-10 ***
## east 0.349080 0.135444 2.577 0.010085 *
## west 0.306814 0.170536 1.799 0.072270 .
## farm 0.128938 0.149276 0.864 0.387907
## othrural 0.087305 0.177166 0.493 0.622261
## town 0.217314 0.126868 1.713 0.087006 .
## smcity 0.352197 0.163964 2.148 0.031928 *
## northcen 0.438681 0.123736 3.545 0.000408 ***
## y74 0.508975 0.173485 2.934 0.003417 **
## y76 0.153246 0.179139 0.855 0.392483
## y78 0.161320 0.182778 0.883 0.377641
## y80 0.151723 0.184892 0.821 0.412048
## y82 -0.309474 0.173897 -1.780 0.075407 .
## y84 -0.279759 0.173829 -1.609 0.107814
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.6 on 1113 degrees of freedom
## Multiple R-squared: 0.754, Adjusted R-squared: 0.7504
## F-statistic: 213.2 on 16 and 1113 DF, p-value: < 2.2e-16