拓端tecdat|R语言对回归模型进行协方差分析
原文链接:http://tecdat.cn/?p=9529
原文出处:拓端数据部落公众号
目录
怎么做测试
协方差分析
拟合线的简单图解
模型的p值和R平方
检查模型的假设
具有三类和II型平方和的协方差示例分析
协方差分析
拟合线的简单图解
组合模型的p值和R平方
检查模型的假设
怎么做测试
具有两个类别和II型平方和的协方差示例的分析
本示例使用II型平方和 。参数估计值在R中的计算方式不同,
Data = read.table(textConnection(Input),header=TRUE)
plot(x = Data$Temp, y = Data$Pulse, col = Data$Species, pch = 16,xlab = "Temperature",ylab = "Pulse")legend('bottomright', legend = levels(Data$Species), col = 1:2, cex = 1, pch = 16)
协方差分析
Anova Table (Type II tests)Sum Sq Df F value Pr(>F) Temp 4376.1 1 1388.839 < 2.2e-16 ***Species 598.0 1 189.789 9.907e-14 ***Temp:Species 4.3 1 1.357 0.2542 ### Interaction is not significant, so the slope across groups### is not different. model.2 = lm (Pulse ~ Temp + Species,data = Data)library(car)Anova(model.2, type="II")Anova Table (Type II tests)Sum Sq Df F value Pr(>F) Temp 4376.1 1 1371.4 < 2.2e-16 ***Species 598.0 1 187.4 6.272e-14 ***### The category variable (Species) is significant,### so the intercepts among groups are differentCoefficients:Estimate Std. Error t value Pr(>|t|) (Intercept) -7.21091 2.55094 -2.827 0.00858 **Temp 3.60275 0.09729 37.032 < 2e-16 ***Speciesniv -10.06529 0.73526 -13.689 6.27e-14 ***### but the calculated results will be identical.### The slope estimate is the same.### The intercept for species 1 (ex) is (intercept).### The intercept for species 2 (niv) is (intercept) + Speciesniv.### This is determined from the contrast coding of the Species### variable shown below, and the fact that Speciesniv is shown in### coefficient table above.nivex 0niv 1
拟合线的简单图解
plot(x = Data$Temp, y = Data$Pulse, col = Data$Species, pch = 16,xlab = "Temperature",ylab = "Pulse")
模型的p值和R平方
Multiple R-squared: 0.9896, Adjusted R-squared: 0.9888F-statistic: 1331 on 2 and 28 DF, p-value: < 2.2e-16
检查模型的假设
线性模型中残差的直方图。这些残差的分布应近似正态。
残差与预测值的关系图。残差应无偏且均等。
### additional model checking plots with: plot(model.2)
### alternative: library(FSA); residPlot(model.2)
具有三类和II型平方和的协方差示例分析
本示例使用II型平方和,并考虑具有三个组的情况。
### --------------------------------------------------------------
### Analysis of covariance, hypothetical data
### --------------------------------------------------------------Data = read.table(textConnection(Input),header=TRUE)
plot(x = Data$Temp, y = Data$Pulse, col = Data$Species, pch = 16,xlab = "Temperature",ylab = "Pulse")legend('bottomright', legend = levels(Data$Species), col = 1:3, cex = 1, pch = 16)
协方差分析
options(contrasts = c("contr.treatment", "contr.poly"))### These are the default contrasts in RAnova(model.1, type="II")Sum Sq Df F value Pr(>F) Temp 7026.0 1 2452.4187 <2e-16 ***Species 7835.7 2 1367.5377 <2e-16 ***Temp:Species 5.2 2 0.9126 0.4093 ### Interaction is not significant, so the slope among groups### is not different. Anova(model.2, type="II")Sum Sq Df F value Pr(>F) Temp 7026.0 1 2462.2 < 2.2e-16 ***Species 7835.7 2 1373.0 < 2.2e-16 ***Residuals 125.6 44 ### The category variable (Species) is significant,### so the intercepts among groups are differentsummary(model.2)Coefficients:Estimate Std. Error t value Pr(>|t|) (Intercept) -6.35729 1.90713 -3.333 0.00175 **Temp 3.56961 0.07194 49.621 < 2e-16 ***Speciesfake 19.81429 0.66333 29.871 < 2e-16 ***Speciesniv -10.18571 0.66333 -15.355 < 2e-16 ***### The slope estimate is the Temp coefficient.### The intercept for species 1 (ex) is (intercept).### The intercept for species 2 (fake) is (intercept) + Speciesfake.### The intercept for species 3 (niv) is (intercept) + Speciesniv.### This is determined from the contrast coding of the Species### variable shown below.contrasts(Data$Species)fake nivex 0 0fake 1 0niv 0 1
拟合线的简单图解
组合模型的p值和R平方
Multiple R-squared: 0.9919, Adjusted R-squared: 0.9913F-statistic: 1791 on 3 and 44 DF, p-value: < 2.2e-16
检查模型的假设
hist(residuals(model.2), col="darkgray")
线性模型中残差的直方图。这些残差的分布应近似正态。
plot(fitted(model.2), residuals(model.2))
残差与预测值的关系图。残差应无偏且均等。
### additional model checking plots with: plot(model.2)
### alternative: library(FSA); residPlot(model.2)
拓端tecdat|R语言对回归模型进行协方差分析相关推荐
- 拓端tecdat|R语言逻辑回归(Logistic回归)模型分类预测病人冠心病风险
最近我们被客户要求撰写关于冠心病风险的研究报告,包括一些图形和统计输出. 相关视频:R语言逻辑回归(Logistic回归)模型分类预测病人冠心病风险 逻辑回归Logistic模型原理和R语言分类预测冠 ...
- 拓端tecdat|R语言向量误差修正模型 (VECMs)分析长期利率和通胀率影响关系
最近我们被客户要求撰写关于向量误差修正模型的研究报告,包括一些图形和统计输出. 向量自回归模型估计的先决条件之一是被分析的时间序列是平稳的.但是,经济理论认为,经济变量之间在水平上存在着均衡关系,可以 ...
- 拓端tecdat|R语言线性回归和时间序列分析北京房价影响因素可视化案例
最近我们被客户要求撰写关于北京房价影响因素的研究报告,包括一些图形和统计输出. 目的 房价有关的数据可能反映了中国近年来的变化: 人们得到更多的资源(薪水),期望有更好的房子 人口众多 独生子女政策: ...
- 拓端tecdat|R语言用LOESS(局部加权回归)季节趋势分解(STL)进行时间序列异常检测
最近我们被客户要求撰写关于LOESS(局部加权回归)的研究报告,包括一些图形和统计输出. 这篇文章描述了一种对涉及季节性和趋势成分的时间序列的中点进行建模的方法.我们将对一种叫做STL的算法进行研究, ...
- R语言构建回归模型并进行模型诊断(线性关系不满足时)、进行变量变换(Transforming variables)、使用car包中的boxTidwell函数对预测变量进行Box–Tidwell变换
R语言构建回归模型并进行模型诊断(线性关系不满足时).进行变量变换(Transforming variables).使用car包中的boxTidwell函数对预测变量进行Box–Tidwell变换 目 ...
- R语言计算回归模型每个样本(观察、observation、sample)的DFFITS度量实战:忽略单个观察(样本)时,回归模型所做的预测会发生多大的变化
R语言计算回归模型每个样本(观察.observation.sample)的DFFITS度量实战:忽略单个观察(样本)时,回归模型所做的预测会发生多大的变化 目录
- R语言构建回归模型并获取对于新数据预测的预测区间实战:给出预测区间而不是一个具体的预测值、置信区间与预测区间的异同
R语言构建回归模型并获取对于新数据预测的预测区间实战:95%或者99%预测区间而不是一个具体的预测值.置信区间与预测区间的异同 目录
- R语言计算回归模型每个样本(观察、observation、sample)的杠杆值(leverage)实战:如果一个样本的预测变量比其他样本的预测变量值更极端,那么被认为具有很高的杠杆作用
R语言计算回归模型每个样本(观察.observation.sample)的杠杆值(leverage)实战:如果一个样本的预测变量比其他样本的预测变量值更极端,那么被认为具有很高的杠杆作用 目录
- R语言计算回归模型标准化残差实战(Standardized Residuals):识别回归模型中离群点
R语言计算回归模型标准化残差实战(Standardized Residuals):识别回归模型中离群点 目录
- R语言计算回归模型的SST、SSR以及SSE指标实战
R语言计算回归模型的SST.SSR以及SSE指标实战 目录 R语言计算回归模型的SST.SSR以及SSE指标实战 #仿真数据
最新文章
- 动态改变Android控件大小
- Google更新最大的带注释图像数据集,添加本地化叙述
- Linux存储保护,谈谈Linux中的存储保护
- python中的demo_python中简单工厂实现demo
- python函数type的用意_Python内置函数Type()函数一个有趣的用法
- PDA与服务器时间同步
- 使用ubuntu18搭建nfs分布式文件系统
- iOS 4 Background Audio
- SpringCloud入门教程(全集)
- 基于 Verilog 的经典数字电路设计(8)计数器
- android 平板重装系统,平板电脑系统重装方法
- 10Wqps评论中台,如何架构?B站是这么做的!!!
- 星环科技如何站稳脚跟?
- Word2vec原理+实战学习笔记(二)
- js中break关键字的用法。
- MATLAB仿真斜坡信号的校正,控制系统仿真matlab第六章习题答案.doc
- 获取QQ音乐歌曲播放源地址
- 朗朗pk机器人_弹琴机器人PK郎朗爱徒,艺术能被机器代替吗?
- python读取txt文件并分割成列表_在python中读取文本文件并将其拆分为单个单词
- 2019最新WEB前端从入门到资深专家课程全套