接之前的简单线性回归文章:regression | p-value | Simple (bivariate) linear model | 线性回归 | 多重检验 | FDR | BH | R代码

再读ISL

R代码层面的能力:

1. 会用简单的一元线性回归,拟合、解读结果、绘图;

2. 能给出系数的置信区间;

3. 预测新的结果,并给出预测结果的置信区间;

4. 模型基本假设的检验,残基、正态性等;

--------

5. 多重线性回归的拟合,结果的解读,哪些变量无关;

6. variance inflation factors检测;

7. 代码层面从模型中去掉无关变量;

8. 引入interaction项;

9. 自变量的非线性转换;

10. 定性变量的回归;dummy variables


multiple要注意区分,是multiple linear regression,还是multiple testing。

前者是说线性回归的变量有多个,后者是说要做多个线性回归,也就是多个检验。


P133,这是第二次作业,考察多重线性回归。这个youtube频道真是精品,用R做统计。这里是R代码的总结

连续变量和类别型变量总要分开讨论;

多重线性回归可以写成矩阵形式的一元一次回归;相当于把多变量当成列向量压缩一下;矩阵有着非常优美的简单的计算法则,大大简化了计算的复杂度;

在建多重线性回归模型时我们会遇到很多问题:

  • 选哪些变量建模,一元的很简单,可以判断有无显著性,多元就复杂了,我们收集的很多变量可能和因变量之间没有关系,必须过滤;
  • 哪些变量之间有相关性,必须把相关性考虑进模型;
  • 如何检测是否存在多次的关系?

ANOVA;partition variability into different parts with different explanations that add up to a total that is related to overall variance.

If the null hypothesis is true, then the Model SS should be just random variation, so that both the Model MS and Residual MS become estimates of the same variance, so the ratio will be around 1. However, if the null is false, the ratio should be large.
So this explains why our test statistic is: F=Model MS/Residual MS

多重线性回归ANOVA分析会有一个总的F统计下的p-value,如果这个都不显著,那就没有必要继续往下做了。

显著了那就继续往下做:如何选出最合适的变量呢?

有两种方法:

  • forwards stepwise regression,就是不断的往里面加变量,使得t statistic最显著;缺点很明显:1.多次检验,会加入过多变量;2.找不出复杂搭配的模型,因为是一个一个添加的;
  • backward stepwise regression,全部引入,然后一个一个的减;缺点:1.共线性;
  • mixed stepwise

Diagnostics方法,如何确定我们的基本假设是对的,假设都不对,建模就是扯淡;(Checking Linear Regression Assumptions in R | R Tutorial 5.2 | MarinStatsLectures,讲得比较透彻)

  • residuals
  • influence or leverage

我们一开始会检验各个变量之间的相关性,看一下大致的拟合情况。

用R的话,一般我们都是先构建full model,然后构建全部的reduced models,然后用ANOVA来检验,reduced model的RSS是否显著降低了,如果没有那么说明full model并没有比这个reduced model好,那我们就可以否定full model,选用这个reduced model。这也是符合Occam's razor法则的。

Assignment 2
Use the dataset below (which is tab delimited) on different brands of cigarettes – you
want to predict CO (Carbon Monoxide output) given the other variables.
1. Fit all seven possible linear models with CO as the dependent variable (i.e. with
all possible sets of independent variables except for no independent variables) and
summarise the results in a table.
2. Identify what you think is the best model for predicting CO and explain why you
think it is good.
3. Include a summary of diagnostic checks that you try for your best model (please
do at least one check).
# save to file: data.txt
Tar Nictn Wt CO
14.1 0.86 0.9853 13.6
16 1.06 1.0938 16.6
29.8 2.03 1.165 23.5
8 0.67 0.928 10.2
4.1 0.4 0.9462 5.4
15 1.04 0.8885 15
8.8 0.76 1.0267 9
12.4 0.95 0.9225 12.3
16.6 1.12 0.9372 16.3
14.9 1.02 0.8858 15.4
13.7 1.01 0.9643 13
15.1 0.9 0.9316 14.4
7.8 0.57 0.9705 10
11.4 0.78 1.124 10.2
9 0.74 0.8517 9.5
1 0.13 0.7851 1.5
17 1.26 0.9186 18.5
12.8 1.08 1.0395 12.6
15.8 0.96 0.9573 17.5
4.5 0.42 0.9106 4.9
14.5 1.01 1.007 15.9
7.3 0.61 0.9806 8.5
8.6 0.69 0.9693 10.6
15.2 1.02 0.9496 13.9
12 0.82 1.1184 14.9

三个自变量,所有多重线性回归有7中可能的模型。

解释哪一个模型最好。

diagnostic checks。

答案:

最极端的那个不是outlier,这个残基的随着Y在变,所以这个拟合关系不是线性的。下面的q-q plot也确认了这点。

需要用非线性的模型来拟合CO和Tar,参见R语言非线性回归入门

最新文章

  1. 总结JS 常用函数
  2. 关于Java中计算日期差值不准确问题
  3. ASP.NET MVC 学习6、学习使用Code First Migrations功能,把Model的更新同步到DB中
  4. jquery提示气泡
  5. Codeforces 611D New Year and Ancient Prophecy dp+字符串比较
  6. pymssql 安装测试
  7. Content Providers
  8. 子类化窗口控件的窗口过程(系统级替换,与直接替换控件的WndProc方法不是一回事)
  9. C#中的委托是什么?
  10. C# Base64解码 二进制输出
  11. php dependency innjection
  12. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)
  13. javascript基础 之 jQuery教程
  14. React组件和生命周期简介
  15. java 常用工具整理
  16. JAVA关键字及作用
  17. javascipt继承机制(from阮一峰)
  18. 背水一战 Windows 10 (114) - 后台任务: 后台任务的 Demo(与 app 不同进程), 后台任务的 Demo(与 app 相同进程)
  19. 莫烦theano学习自修第五天【定义神经层】
  20. 节流(Throttling)和去抖(Debouncing)详解

热门文章

  1. selenium处理元素定位到了点击无效问题
  2. linux----------yum一些安装命令汇总
  3. ubuntu16.04 backup and restore
  4. [CentOS] rsync同步目录进行备份文件
  5. 《ASP.NET Core In Action》读书笔记系列,这是一个手把手的从零开始的教学系列目录
  6. centos7 安装 redis-4.0.9
  7. hibernate 调用存储过程返回参数
  8. IP通信基础学习第六周(下)
  9. Linux直播推流
  10. javascript实现继承的三种方式