Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

r code error i am working on 1(c) i downloaded the caret package to preform a k factor cross validation on model1 after removing NA

r code error
i am working on 1(c) i downloaded the caret package to preform a k factor cross validation on model1 after removing NA but when i try to print it is says error in data frame undefined column selected , do you know why that is ,how do i correct it ?
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
A corporation's earnings in a given year is its income minus its expenses. Our data set for this homework looks at the relationship between US stock prices, the earnings of the corporations, and the returns on investment in stocks, with returns counting both changes in stock price and dividends paid to stock holders. Specifically, our data contains the following variables: - Date, with fractions of a year indicating months - Price of an index of US stocks (inflation-adjusted) - Earnings per share (also inflation-adjusted); - Earnings_10MA_back, a ten-year moving average of earnings, looking backwards from the current date; - Return_cumul, cumulative return of investing in the stock index, from the beginning; - Return_10_fwd, the average rate of return over the next 10 years from the current date. Note: in all following questions, "Returns" will refer to Return_10_fwd. 1. (9pts) Linear models (a) (2 pt) Run four linear regressions for the returns: on Price; on Earnings; on both Price and Earnings; and on both variables and their interaction. Report coefficients and standard errors. (b) (2 pt) Find in-sample R2 for these four models. Can their R2 's be meaningfully compared? If so, which model is preferred by R2 ? (c) (5pts) Use five-fold cross-validation to estimate the generalization error of all four models. Can these be meaningfully compared? If so, which model is preferred by crossvalidation? \begin{tabular}{|l|l|l|l|l|l|} \hline Date & Price & Earnings & Earnings_10MA_back & Return_cumul & Return_10_fwd \\ \hline 1871 & 85.22 & 7.68 & NA & 1 & 0.13051268020414 \\ \hline 1871.08 & 83.81 & 7.45 & NA & 0.99 & 0.130649904966584 \\ \hline 1871.17 & 84.61 & 7.34 & NA & 1 & 0.131173993962994 \\ \hline 1871.25 & 90.29 & 7.62 & NA & 1.07 & 0.122559873143159 \\ \hline 1871.33 & 94.73 & 7.8 & NA & 1.13 & 0.122851712607348 \\ \hline 1871.42 & 95.43 & 7.92 & NA & 1.15 & 0.122737748077798 \\ \hline \end{tabular} 3 summary(model1) 4 model2=lm(hw3sReturn_10_fwd hw3SEarnings) 5 Summary (model2) 6 model3=Lm(hw3SReturn_10_fwd hw3SPrice+hw3SEarnings) 7 summary (model3) 8 model4=2m(hw3SReturn_10_fwd * hw3SPricethw3SEarningsthw3SPrice hw3SEarnings) 9 Summary (model4) 10 install. packages ("caret") 11 Library (caret) 12 ctrl=traincontrol (method="cv", number-5) 13 afterremove=na. omit (hw3) 14 modelxatrain(afterremovesReturn_10_fwd afterremovesprice, data=afterremove, method="lm", trContrtol=ct undefined columns selected . COTS, drop = FAL SE) : - print (mode7x) Ercor in print (modejx) : object "modelx" not found > model x-train (afterremovesteturn-10 fwd - afterremovesprtce, data-afterremove, method "7m", tr contrtol-ctr1) Etror in [. data, frame' (data, 0 , cols. drop - FaLSE): undefined columis selected A corporation's earnings in a given year is its income minus its expenses. Our data set for this homework looks at the relationship between US stock prices, the earnings of the corporations, and the returns on investment in stocks, with returns counting both changes in stock price and dividends paid to stock holders. Specifically, our data contains the following variables: - Date, with fractions of a year indicating months - Price of an index of US stocks (inflation-adjusted) - Earnings per share (also inflation-adjusted); - Earnings_10MA_back, a ten-year moving average of earnings, looking backwards from the current date; - Return_cumul, cumulative return of investing in the stock index, from the beginning; - Return_10_fwd, the average rate of return over the next 10 years from the current date. Note: in all following questions, "Returns" will refer to Return_10_fwd. 1. (9pts) Linear models (a) (2 pt) Run four linear regressions for the returns: on Price; on Earnings; on both Price and Earnings; and on both variables and their interaction. Report coefficients and standard errors. (b) (2 pt) Find in-sample R2 for these four models. Can their R2 's be meaningfully compared? If so, which model is preferred by R2 ? (c) (5pts) Use five-fold cross-validation to estimate the generalization error of all four models. Can these be meaningfully compared? If so, which model is preferred by crossvalidation? \begin{tabular}{|l|l|l|l|l|l|} \hline Date & Price & Earnings & Earnings_10MA_back & Return_cumul & Return_10_fwd \\ \hline 1871 & 85.22 & 7.68 & NA & 1 & 0.13051268020414 \\ \hline 1871.08 & 83.81 & 7.45 & NA & 0.99 & 0.130649904966584 \\ \hline 1871.17 & 84.61 & 7.34 & NA & 1 & 0.131173993962994 \\ \hline 1871.25 & 90.29 & 7.62 & NA & 1.07 & 0.122559873143159 \\ \hline 1871.33 & 94.73 & 7.8 & NA & 1.13 & 0.122851712607348 \\ \hline 1871.42 & 95.43 & 7.92 & NA & 1.15 & 0.122737748077798 \\ \hline \end{tabular} 3 summary(model1) 4 model2=lm(hw3sReturn_10_fwd hw3SEarnings) 5 Summary (model2) 6 model3=Lm(hw3SReturn_10_fwd hw3SPrice+hw3SEarnings) 7 summary (model3) 8 model4=2m(hw3SReturn_10_fwd * hw3SPricethw3SEarningsthw3SPrice hw3SEarnings) 9 Summary (model4) 10 install. packages ("caret") 11 Library (caret) 12 ctrl=traincontrol (method="cv", number-5) 13 afterremove=na. omit (hw3) 14 modelxatrain(afterremovesReturn_10_fwd afterremovesprice, data=afterremove, method="lm", trContrtol=ct undefined columns selected . COTS, drop = FAL SE) : - print (mode7x) Ercor in print (modejx) : object "modelx" not found > model x-train (afterremovesteturn-10 fwd - afterremovesprtce, data-afterremove, method "7m", tr contrtol-ctr1) Etror in [. data, frame' (data, 0 , cols. drop - FaLSE): undefined columis selected

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Access Audit Handbook An Inclusive Approach To Auditing Buildings

Authors: Centre For Accessible Environments

3rd Edition

1914124839, 978-1914124839

More Books

Students also viewed these Accounting questions

Question

b. Draw the corresponding probability histogram.

Answered: 1 week ago

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago