Question 1

Question 2

Once you have the dataset, decide what multivariate regression you want to run i.e. what is your y variable and what are your X variables? Since this is a multivariate regression, you need at least 2 independent variables (else you are running a bi-variate regression - regression between two variables). So for example, tell us income is my dependent variable, while age, experience, … are my independent variables.

I’ll examine the relationship between income, education level, and life expectancy. In this case, life expectancy would be the dependent variable, income and education level would be the independent variables.

Question 3

Now, first estimate the multivariate regression/linear relationship above with the “lm” command.s The syntax is very simple, and you will find many blogs on this - just find the relevant sections as regression is a large topic. (EG Subsection Multiple regression: biking, smoking, and heart disease may be helpful too). Do not worry too much about causality or interpretation of beta coefficients for this discussion.
## [1] "double"
## [1] "matrix" "array"
## # A tibble: 3 × 4
##   term          estimate std.error  p.value
##   <chr>            <dbl>     <dbl>    <dbl>
## 1 (Intercept) 65.9        1.24     1.05e-43
## 2 Income      -0.0000734  0.000330 8.25e- 1
## 3 `HS Grad`    0.100      0.0251   2.28e- 4
## [1] 0.3396703

Question 4

Now, confirm if you get the same coefficient point estimates (betas) with the matrix algebra formula that we discuss in class - inv(X’X) X’y You should get the same answer. If not, check if you specified the intercept term in your matrix X by adding a unit vector or not. LMR Section 2.6 can be useful if you get stuck (see the textbook folder in class Dropbox link). Or see the hint / OLS_matrixVSlm.pdf file, and you can recode for your dataset using OLS_matrixVSlm.Rmd file in W2 folder in class Dropbox folder.
##            Alabama  Alaska Arizona Arkansas California Colorado Connecticut
## int           1.00    1.00    1.00     1.00       1.00     1.00        1.00
## Population 3615.00  365.00 2212.00  2110.00   21198.00  2541.00     3100.00
## Income     3624.00 6315.00 4530.00  3378.00    5114.00  4884.00     5348.00
## Illiteracy    2.10    1.50    1.80     1.90       1.10     0.70        1.10
## Life Exp     69.05   69.31   70.55    70.66      71.71    72.06       72.48
## Murder       15.10   11.30    7.80    10.10      10.30     6.80        3.10
## HS Grad      41.30   66.70   58.10    39.90      62.60    63.90       56.00
## Frost        20.00  152.00   15.00    65.00      20.00   166.00      139.00
##            Delaware Florida Georgia Hawaii   Idaho Illinois Indiana    Iowa
## int            1.00    1.00    1.00    1.0    1.00     1.00    1.00    1.00
## Population   579.00 8277.00 4931.00  868.0  813.00 11197.00 5313.00 2861.00
## Income      4809.00 4815.00 4091.00 4963.0 4119.00  5107.00 4458.00 4628.00
## Illiteracy     0.90    1.30    2.00    1.9    0.60     0.90    0.70    0.50
## Life Exp      70.06   70.66   68.54   73.6   71.87    70.14   70.88   72.56
## Murder         6.20   10.70   13.90    6.2    5.30    10.30    7.10    2.30
## HS Grad       54.60   52.60   40.60   61.9   59.50    52.60   52.90   59.00
## Frost        103.00   11.00   60.00    0.0  126.00   127.00  122.00  140.00
##             Kansas Kentucky Louisiana   Maine Maryland Massachusetts Michigan
## int           1.00      1.0      1.00    1.00     1.00          1.00     1.00
## Population 2280.00   3387.0   3806.00 1058.00  4122.00       5814.00  9111.00
## Income     4669.00   3712.0   3545.00 3694.00  5299.00       4755.00  4751.00
## Illiteracy    0.60      1.6      2.80    0.70     0.90          1.10     0.90
## Life Exp     72.58     70.1     68.76   70.39    70.22         71.83    70.63
## Murder        4.50     10.6     13.20    2.70     8.50          3.30    11.10
## HS Grad      59.90     38.5     42.20   54.70    52.30         58.50    52.80
## Frost       114.00     95.0     12.00  161.00   101.00        103.00   125.00
##            Minnesota Mississippi Missouri Montana Nebraska  Nevada
## int             1.00        1.00     1.00    1.00      1.0    1.00
## Population   3921.00     2341.00  4767.00  746.00   1544.0  590.00
## Income       4675.00     3098.00  4254.00 4347.00   4508.0 5149.00
## Illiteracy      0.60        2.40     0.80    0.60      0.6    0.50
## Life Exp       72.96       68.09    70.69   70.56     72.6   69.03
## Murder          2.30       12.50     9.30    5.00      2.9   11.50
## HS Grad        57.60       41.00    48.80   59.20     59.3   65.20
## Frost         160.00       50.00   108.00  155.00    139.0  188.00
##            New Hampshire New Jersey New Mexico New York North Carolina
## int                 1.00       1.00       1.00     1.00           1.00
## Population        812.00    7333.00    1144.00 18076.00        5441.00
## Income           4281.00    5237.00    3601.00  4903.00        3875.00
## Illiteracy          0.70       1.10       2.20     1.40           1.80
## Life Exp           71.23      70.93      70.32    70.55          69.21
## Murder              3.30       5.20       9.70    10.90          11.10
## HS Grad            57.60      52.50      55.20    52.70          38.50
## Frost             174.00     115.00     120.00    82.00          80.00
##            North Dakota     Ohio Oklahoma  Oregon Pennsylvania Rhode Island
## int                1.00     1.00     1.00    1.00         1.00          1.0
## Population       637.00 10735.00  2715.00 2284.00     11860.00        931.0
## Income          5087.00  4561.00  3983.00 4660.00      4449.00       4558.0
## Illiteracy         0.80     0.80     1.10    0.60         1.00          1.3
## Life Exp          72.78    70.82    71.42   72.13        70.43         71.9
## Murder             1.40     7.40     6.40    4.20         6.10          2.4
## HS Grad           50.30    53.20    51.60   60.00        50.20         46.4
## Frost            186.00   124.00    82.00   44.00       126.00        127.0
##            South Carolina South Dakota Tennessee   Texas   Utah Vermont
## int                  1.00         1.00      1.00     1.0    1.0    1.00
## Population        2816.00       681.00   4173.00 12237.0 1203.0  472.00
## Income            3635.00      4167.00   3821.00  4188.0 4022.0 3907.00
## Illiteracy           2.30         0.50      1.70     2.2    0.6    0.60
## Life Exp            67.96        72.08     70.11    70.9   72.9   71.64
## Murder              11.60         1.70     11.00    12.2    4.5    5.50
## HS Grad             37.80        53.30     41.80    47.4   67.3   57.10
## Frost               65.00       172.00     70.00    35.0  137.0  168.00
##            Virginia Washington West Virginia Wisconsin Wyoming
## int            1.00       1.00          1.00      1.00    1.00
## Population  4981.00    3559.00       1799.00   4589.00  376.00
## Income      4701.00    4864.00       3617.00   4468.00 4566.00
## Illiteracy     1.40       0.60          1.40      0.70    0.60
## Life Exp      70.08      71.72         69.48     72.48   70.29
## Murder         9.50       4.30          6.70      3.00    6.90
## HS Grad       47.80      63.50         41.60     54.50   62.90
## Frost         85.00      32.00        100.00    149.00  173.00
##            [,1]
## int           0
## Population    0
## Income        0
## Illiteracy    0
## Life Exp      1
## Murder        0
## HS Grad       0
## Frost         0
##            our.results lm.results
## int                  0      70.94
## Population           0       0.00
## Income               0       0.00
## Illiteracy           0       0.03
## Life Exp             1      -0.30
## Murder               0       0.05
## HS Grad              0      -0.01
## Frost                0       0.00