Rcmdr交互作业

http://www.tudou.com/programs/view/Lry4o66Fjb0/

 

<!-- R Commander Markdown Template -->

Rcmdr交互作业
=======================

### 12300730013

### `r as.character(Sys.Date())`

```{r echo=FALSE}
# include this code chunk as-is to set options
knitr::opts_chunk$set(comment=NA, prompt=TRUE, out.width=750, fig.height=8, fig.width=8)
library(Rcmdr)
library(car)
library(RcmdrMisc)
```

```{r}
library(foreign, pos=14)
```

```{r}
Dataset <- read.spss("C:/Users/ShaoYR/Documents/百度云同步盘/文档/统计软件/T2_1.SAV",
use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE)#导入数据:1991年我国分地区n年人均食品支出和年人均收入及粮食单价数据(地区area变量改为南北两个水平)
colnames(Dataset) <- tolower(colnames(Dataset))
```

```{r}
scatterplotMatrix(~area+foodexp+income+price, reg.line=lm, smooth=TRUE,
spread=FALSE, span=0.5, id.n=0, diagonal = 'qqplot', data=Dataset)#概览数据,找出需要转换为factor的变量
```

```{r}
Dataset <- within(Dataset, {
f.area <- as.factor(area)
})#将area变量转为factor
```

```{r}
t.test(foodexp~f.area, alternative='two.sided', conf.level=.95, var.equal=FALSE,
data=Dataset)#对南北城市的人均食品支出做独立样本t检验
```

```{r}
Boxplot(foodexp~f.area, data=Dataset, id.method="y")#按照南北分组作人均食品支出的箱型图
```

#模型及其嵌套

```{r}
RegModel.1 <- lm(foodexp~income, data=Dataset)
summary(RegModel.1)#模型一:线性回归-用人均收入预测人均食品支出
```

```{r}
LinearModel.2 <- lm(foodexp ~ income +price, data=Dataset)
summary(LinearModel.2)#嵌套模型:增加粮食单价变量,预测人均食品支出
```

```{r}
anova(RegModel.1, LinearModel.2)#两个模型的比较
```

 

扩充版plotEx.data.frame函数



GDP-HPI plot of happy index