Rcmdr交互作业

http://v.youku.com/v_show/id_XODY3NTM2MTUy.html

HTML文本:file:///C:/Windows/System32/RcmdrMarkdown.html

> data(airquality, package="datasets")
> airquality <- within(airquality, {
+ day airquality <- within(airquality, { #修改了day与month的变量类型改为离散变量
+ month scatterplotMatrix(~Day+Month+Ozone+Solar.R+Temp+Wind, reg.line=lm, smooth=TRUE,
+ spread=FALSE, span=0.5, id.n=0, diagonal = 'density', data=airquality)#得到Matrix图,可看到变量个数与其维度

> LinearModel.1 summary(LinearModel.1)#第一个回归
> oldpar plot(LinearModel.1)#对一个回归做基本的回归检验,发现非线性需要加入二次项
> par(oldpar)
> LinearModel.2 summary(LinearModel.2)#第二个回归加入二次项
> anova(LinearModel.1, LinearModel.2)#两个模型的检验,发现第二个模型显著,于是选择第二个模型放弃第一个模型

plotEx.data.frame

plotEx.data.frame <- function (x, ...)
{
plot2 <- function(x, xlab = names(x)[1L], ylab = names(x)[2L],
...) plot(x[[1L]], x[[2L]], xlab = xlab, ylab = ylab,
...)
if (!is.data.frame(x))
stop("'plot.data.frame' applied to non data frame")
if (ncol(x) == 1) {
x1 <- x[[1L]]
cl <- class(x1)
if (cl %in% c("integer", "numeric"))
stripchart(x1, ...)
else plot(x1, ...)
}
else if (ncol(x) == 2) {
plot2(x, ...)
}
else {
pairs(data.matrix(x), ...)
}

if (is.numeric(x))
x3<- length(unique(na.omit(x)))
if (x3 < 6)
pie(x,labels=names(x))
if(if.factor(x[[1L]]) $ if.factor(x[[2L]]))
mosica(x, ...)
elseif(if.numeric(x[[1L]]) | if.numeric(x[[2L]]))
boxplot(x1, x2 ,jitter(x))
}

R作图

Dataset = read.csv('http://fudan.lxxm.com/wp-content/uploads/2012/12/Prac.csv',encoding='GBK')
attach(Dataset)
opar <- par(no.readonly=T)
reg<-substr(Sub_Region,1,1)
is.numeric(reg)
g.reg<-as.numeric(as.character(reg))
f.reg<-0
f.reg[g.reg==1] <- "Latin America"
f.reg[g.reg==2] <-"Western World"
f.reg[g.reg==3] <-"Middle East and North Africa"
f.reg[g.reg==4] <- "Sub Saharan Africa"
f.reg[g.reg==5] <-"South Asia"
f.reg[g.reg==6] <- "East Asia"
f.reg[g.reg==7] <- "Transition States"
op <- palette(rainbow(7, end = 6/7))
par(fig=c(0,.8,0, 0.8))

x<-c( "Latin America" , "Western World", "Middle East and North Africa","Sub Saharan Africa", "South Asia", "East Asia" ,
"Transition States")

symbols(GDP_pc, Well.Being , circles = g.reg/100, inches = .07, bg = 1:7 , main = "gdp~hpi|region",
)
legend("bottomright",x,fill=1:7)
abline(h=5.398,lty=2,col="blue")
idx <- identify(GDP_pc, Well.Being, label=Country, plot= TRUE)
Dataset[idx,]
par(fig=c(0,.8,.55, 1),new=T)

plot(Life.Expectancy~g.reg)