自己写的答案,希望各位多加批评指正
第一题
- The folder pyth contains outcome y and inputs x1, x2 for 40 data points, with a further 20 points with the inputs but no observed outcome. Save the file to your working directory and read it into R using the read.table() function.
(a) Use R to fit a linear regression model predicting y from x1, x2, using the first 40 data points in the file. Summarize the inferences and check the fit of your model.
(b) Display the estimated model graphically as in Figure 3.2.
(c ) Make a residual plot for this model. Do the assumptions appear to be met?
(d) Make predictions for the remaining 20 data points in the file. How confident do you feel about these predictions?
Gelman老师的数据已经找不到了,所以就还是用下午的数据吧:简单回归模型
第二题
- Suppose that, for a certain population, we can predict log earnings from log height as follows:
• A person who is 66 inches tall is predicted to have earnings of $30,000.
• Every increase of 1% in height corresponds to a predicted increase of 0.8% in earnings.
• The earnings of approximately 95% of people fall within a factor of 1.1 of predicted values.
(a) Give the equation of the regression line and the residual standard deviation of the regression.
(b) Suppose the standard deviation of log heights is 5% in this population. What, then, is the R2 of the regression model described here?
(a)
回 归 方 程 : l o g ( e a r n i n g s ) = α + 0.8 l o g ( h e i g h t ) + μ 回归方程:log(earnings)=\alpha + 0.8log(height)+\mu 回归方程:log(earnings)=α+0.8log(height)+μ
将 e a r n i n g = 30000 , h e i g h t = 66 带 入 上 述 方 程 , 得 α = 6.957229 将earning=30000, height=66带入上述方程,得\alpha=6.957229 将earning=30000,height=66带入上述方程,得α=6.957229
#计算\alpha的值
a <- log