如何读取R 的sumary()结果
思路
step 1: sum = summary(model)
step 2: sum有好多属性,直接根据属性名称引用(\()即可, 如:
+ > sum\)call 返回 model 使用的模型语句
+ > sum\(coefficients; 返回一个列表,可以继续引用,如下
+ > sum\)coefficients[1 : 12]; 返回一个列表的一个切片,还可以继续切片
+ > sum$coefficients[1 : 12][2]; 返回一个列表的一个切片的第二个元素
下面是一些 测试代码,未整理,可以大致学习一下
用'demo()'来看一些示范程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
用'q()'退出R.
[Workspace loaded from ~/.RData]
> y=c(53,434,111,38,108,48)
> x1=c(1,2,3,1,2,3)
> x2=c(1,2,1,2,1,2)
> log.glm <-glm(y~x1+x2,family = possion(link=log))
Error in possion(link = log) : 没有"possion"这个函数
> log.glm <-glm(y~x1+x2,family = possion(link=log),data=(y,x1,x2))
错误: 意外的',' in "log.glm <-glm(y~x1+x2,family = possion(link=log),data=(y,"
> dataframe <-data.frame(y,x1,x2)
> head(dataframe)
y x1 x2
1 53 1 1
2 434 2 2
3 111 3 1
4 38 1 2
5 108 2 1
6 48 3 2
> log.glm <-glm(y~x1+x2,family = possion(link=log),data=data.frame(y,x1,x2))
Error in possion(link = log) : 没有"possion"这个函数
> log.glm <-glm(y~x1+x2,family = poisson(link=log),data=data.frame(y,x1,x2))
> summary(log.glm)
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
Deviance Residuals:
1 2 3 4 5 6
-3.1382 16.6806 0.8189 -11.0398 1.8210 -12.6942
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.59532 0.15792 22.767 < 2e-16 ***
x1 0.12915 0.04370 2.955 0.00312 **
x2 0.64803 0.07483 8.660 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 662.84 on 5 degrees of freedom
Residual deviance: 575.10 on 3 degrees of freedom
AIC: 619.08
Number of Fisher Scoring iterations: 5
> log.glm.x1
错误: 找不到对象'log.glm.x1'
>
>
>
>
>
>
> summary(log.glm)
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
Deviance Residuals:
1 2 3 4 5 6
-3.1382 16.6806 0.8189 -11.0398 1.8210 -12.6942
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.59532 0.15792 22.767 < 2e-16 ***
x1 0.12915 0.04370 2.955 0.00312 **
x2 0.64803 0.07483 8.660 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 662.84 on 5 degrees of freedom
Residual deviance: 575.10 on 3 degrees of freedom
AIC: 619.08
Number of Fisher Scoring iterations: 5
> log.glm.x1
错误: 找不到对象'log.glm.x1'
> help("glm")
> anova(log.glm)
Analysis of Deviance Table
Model: poisson, link: log
Response: y
Terms added sequentially (first to last)
Df Deviance Resid. Df Resid. Dev
NULL 5 662.84
x1 1 8.770 4 654.07
x2 1 78.978 3 575.10
> ano= anova(log.glm)
> ano[1]
Df
NULL
x1 1
x2 1
> ano[2]
Deviance
NULL
x1 8.770
x2 78.978
> ano[3]
Resid. Df
NULL 5
x1 4
x2 3
> sum= summary(log.glm)
> sum
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
Deviance Residuals:
1 2 3 4 5 6
-3.1382 16.6806 0.8189 -11.0398 1.8210 -12.6942
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.59532 0.15792 22.767 < 2e-16 ***
x1 0.12915 0.04370 2.955 0.00312 **
x2 0.64803 0.07483 8.660 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 662.84 on 5 degrees of freedom
Residual deviance: 575.10 on 3 degrees of freedom
AIC: 619.08
Number of Fisher Scoring iterations: 5
> sum[1]
$call
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
> sum[1,1]
Error in sum[1, 1] : 量度数目不对
> sum[2]
$terms
y ~ x1 + x2
attr(,"variables")
list(y, x1, x2)
attr(,"factors")
x1 x2
y 0 0
x1 1 0
x2 0 1
attr(,"term.labels")
[1] "x1" "x2"
attr(,"order")
[1] 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
attr(,"predvars")
list(y, x1, x2)
attr(,"dataClasses")
y x1 x2
"numeric" "numeric" "numeric"
> sum[3]
$family
Family: poisson
Link function: log
> sum[4]
$deviance
[1] 575.0954
> sum[4,1]
Error in sum[4, 1] : 量度数目不对
> sum
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
Deviance Residuals:
1 2 3 4 5 6
-3.1382 16.6806 0.8189 -11.0398 1.8210 -12.6942
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.59532 0.15792 22.767 < 2e-16 ***
x1 0.12915 0.04370 2.955 0.00312 **
x2 0.64803 0.07483 8.660 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 662.84 on 5 degrees of freedom
Residual deviance: 575.10 on 3 degrees of freedom
AIC: 619.08
Number of Fisher Scoring iterations: 5
> sum[5]
$aic
[1] 619.0808
> sum[6]
$contrasts
NULL
> sum[8]
$null.deviance
[1] 662.8432
> sum[9]
$df.null
[1] 5
> sum[10]
$iter
[1] 5
> sum$aic
[1] 619.0808
> sum$null.deviance
[1] 662.8432
> sum$residual.deviance
NULL
> sum$residual.devianc
NULL
> sum[11]
$deviance.resid
1 2 3 4 5 6
-3.1382350 16.6805594 0.8189003 -11.0397892 1.8209720 -12.6941833
> summary.aov()
Error in summary.aov() : 缺少参数"object",也没有缺省值
> sum
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log), data = data.frame(y,
x1, x2))
Deviance Residuals:
1 2 3 4 5 6
-3.1382 16.6806 0.8189 -11.0398 1.8210 -12.6942
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.59532 0.15792 22.767 < 2e-16 ***
x1 0.12915 0.04370 2.955 0.00312 **
x2 0.64803 0.07483 8.660 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 662.84 on 5 degrees of freedom
Residual deviance: 575.10 on 3 degrees of freedom
AIC: 619.08
Number of Fisher Scoring iterations: 5
> sum$coefficients
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.5953201 0.15791713 22.767132 9.709542e-115
x1 0.1291456 0.04370053 2.955240 3.124256e-03
x2 0.6480267 0.07482977 8.660013 4.717107e-18
> sum$coefficients[4]
[1] 0.1579171
> sum$coefficients[5]
[1] 0.04370053
> sum$coefficients[6]
[1] 0.07482977
> sum$coefficients[1]
[1] 3.59532
> sum$coefficients[1..2]
错误: unexpected numeric constant in "sum$coefficients[1..2"
> sum$coefficients[1:2]
[1] 3.5953201 0.1291456
> sum$coefficients[1:5]
[1] 3.59532005 0.12914558 0.64802675 0.15791713 0.04370053
> sum$coefficients[11:12]
[1] 3.124256e-03 4.717107e-18
> sum$coefficients[11:12][1]
[1] 0.003124256
> sum$coefficients[11:12][2]
[1] 4.717107e-18
如何读取R 的sumary()结果的更多相关文章
- R语言基础
一.扩展包的基本操作语句R安装好之后,默认自带了"stats" "graphics" "grDevices" "utils&qu ...
- R语言︱文件读入、读出一些方法罗列(批量xlsx文件、数据库、文本txt、文件夹)
笔者寄语:小规模的读取数据的方法较为简单并且多样,但是,批量读取目前看到有以下几种方法:xlsx包.RODBC包.批量转化成csv后读入. R语言中还有一些其他较为普遍的读入,比如代码包,R文件,工作 ...
- R语言手册
在R的官方教程里是这么给R下注解的:一个数据分析和图形显示的程序设计环境(A system for data analysis and visualization which is built bas ...
- 让R与Python共舞
转载:http://ices01.sinaapp.com/?p=129 R(又称R语言)是一款开源的跨平台的数值统计和数值图形化展现 工具.通俗点说,R是用来做统计和画图的.R拥有自己的脚本 ...
- Android小例子:使用反射机制来读取图片制作一个图片浏览器
效果图: 工程文件夹: 该例子可供于新手参考练习,如果有哪里不对的地方,望指正>-< <黑幕下的人> java代码(MainActivity.java): package co ...
- ArcGIS二次开发之读取遥感图像像素值的做法
作者:朱金灿 来源:http://blog.csdn.net/clever101 首先是读取遥感图像的R.G.B波段数据的做法.读取R.G.B波段数据的像素值主要通过IRaster接口的Read方法在 ...
- go语言学习笔记---读取文件io/ioutil 包
io/ioutil 包几个函数方法 名称 作用 备注 ReadAll 读取数据,返回读到的字节 slice 1 ReadDir 读取一个目录,返回目录入口数组 []os.FileInfo, 2 Re ...
- GO 文件读取常用的方法
方式1: 一行一行的方式读取 其中常用的方法就有:ReadString,ReadLine,ReadBytes ReadLine 返回单个行,不包括行尾字节,就是说,返回的内容不包括\n或者\r\n,返 ...
- [高性能MYSQL 读后随笔] 关于事务的隔离级别(一)
一.锁的种类 MySQL中锁的种类很多,有常见的表锁和行锁,也有新加入的Metadata Lock等等,表锁是对一整张表加锁,虽然可分为读锁和写锁,但毕竟是锁住整张表,会导致并发能力下降,一般是做dd ...
随机推荐
- !!!常用CSS代码块
图片排满一行.左右两端无间隙. <style type="text/css"> .img_abc{float:left;width:30%;margin-left:5% ...
- easy ui 关闭选项卡
var tab = window.parent.getCurrentTab(); var tabs = window.parent.getTabs(); var index = tabs.tabs(& ...
- 序列化与反序列化之Kryo
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序列化:把字节序列恢复为对象的过程称为对象的反序列化. 需要序列化的情况: 当你想把的内存中的对象状态保存到一个文件中或者数据库中时候: 当你想 ...
- orcal 安装失败解决办法
若安装失败
- 纯Java——简易高并发框架
转自:https://blog.csdn.net/MonkeyDCoding/article/details/81369610 0.源代码github-简易高并发框架 注:本篇博客知识来自于网课. 1 ...
- PHP对接微信支付采坑
第一次做PHP商城项目对接微信支付接口,踩了N次坑,这也不对,那也不对,搞了很久,查了一些资料,终于实现了支付功能,小小总结一下,万一下次遇到就不用到处找资料了. 微信扫码支付 前期准备: 1.微信公 ...
- oracle 连接字符串的问题
未指定的错误,发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息.数据类型不被支持. 原因是你用的ADO for ORACLE的驱动是微软的Microsoft OLE DB ...
- javaScript+html5实现图片拖拽
源码: <!DOCTYPE html><html><head> <meta charset="utf-8"/> <title& ...
- 150. Evaluate Reverse Polish Notation逆波兰表达式
[抄题]: Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are ...
- React-router4 第八篇 ReactCSSTransitionGroup 动画转换
https://reacttraining.com/react-router/web/example/animated-transitions 动画转换这么高级,其实是又引入了一个组件,没什么特别, ...