##----------
## This is a trivially updated version based on the R document "?anscombe".
require(stats); require(graphics)
anscombe
##-- now some "magic" to do the 4 regressions in a loop:##< -
ff = y ~ x
for(i in 1:4) {
ff[2:3] = lapply(paste(c(”y”,”x”), i, sep=”"), as.name)
assign(paste(”lm.”,i,sep=”"), lmi <- lm(ff, data= anscombe))
}## See how close they are (numerically!)
sapply(objects(pattern=”lm\\.[1-4]$”), function(n) coef(get(n)))
lapply(objects(pattern=”lm\\.[1-4]$”),
function(n) coef(summary(get(n))))## Now, do what you should have done in the first place: PLOTS
op <- par(mfrow=c(4,3),mar=.1+c(4,4,1,1), oma= c(0,0,2,0))
for(i in 1:4) {
ff[2:3] <- lapply(paste(c(”y”,”x”), i, sep=”"), as.name)
plot(ff, data =anscombe, col=”red”, pch=21, bg = “orange”, cex = 1.2,
xlim=c(3,19), ylim=c(3,13))
abline(get(paste(”lm.”,i,sep=”")), col=”blue”)
plot(lm(ff, data =anscombe),which=1,col=”red”, pch=21, bg = “orange”, cex = 1.2
,sub.caption=”",caption=”" )
plot(lm(ff, data =anscombe),which=2,col=”red”, pch=21, bg = “orange”, cex = 1.2
,sub.caption=”",caption=”" )
}
mtext(”Anscombe’s 4 Regression data sets”, outer = TRUE, cex=1.5)
par(op)##
## Anscombe, F. J. (1973). Graphs in statistical analysis. American Statistician, 27, 17–21.
Categories
-
Meta
-
Recent Comments
- 谢益辉: 第一届中国R语言会议纪要 | 统计之都 on Paper for 1st Chinese useR! Conference: Web Powered by R, or R Powered by Web
- 10001036 » Paper for 1st Chinese userR Conference: Web Powered by R, or R Powered by Web on Wordpress (and WPMU) Plugin for R Web Interface
- 理性选民 » Blog Archive » 感谢yo2采纳RWebFriend插件 on Understanding the nominal IV
- 理性选民 » Blog Archive » 感谢yo2采纳RWebFriend插件 on Wordpress (and WPMU) Plugin for R Web Interface
- Rweb demo for base::source(…) on “Confidence interval of R-square”, but, which one?
链接表
-
Recent Posts
Archives

{ 1 } Comments
ft
R代码的问题出在两点:
引号会被自动替换,可能与后台的某种插件有关。用<code></code>括起来就解决了;
yo2.cn自己会把遇到的第一个小于号作一个处理。
Post a Comment