# In zhaoxue-xmu/RDA: Datasets, functions and examples from the book: R Data Analysis-Methods and Application (in chinese)by Kuangnan Fang et al

```knitr::opts_chunk\$set(tidy = FALSE, comment = "#>")
```
```library(RDA)
```

`RDA`包主要包含几种重要的函数：探索性数据分析、参数检验和非参数检验以及绘图等.

# 探索性数据分析

```pay <- c(11,19,14,22,14,28,13,81,12,43,11,16,31,16,23,42,
22,26,17,22,13,27,108,16,43,82,14,11,51,76,28,66,
29,14,14,65,37,16,37,35,39,27,14,17,13,38,28,40,85,
32,25,26,16,12,54,40,18,27,16,14,33,29,77,50,19,34)
EDA(pay)
```
```pay <- c(11,19,14,22,14,28,13,81,12,43,11,16,31,16,23,42,
22,26,17,22,13,27,108,16,43,82,14,11,51,76,28,66,
29,14,14,65,37,16,37,35,39,27,14,17,13,38,28,40,85,
32,25,26,16,12,54,40,18,27,16,14,33,29,77,50,19,34)
log.pay <- log10(pay)
EDA(log.pay)
```

# 参数假设检验

## 正态总体单样本均值检验

### 方差已知时

```b <- c(22, 24, 21, 24, 23, 24, 23, 22, 21, 25)
u_test(b, 25, 2.4, alternative = 'twoside')
```

### 方差未知时

```x <- c(50.2, 49.6, 51.0, 50.8, 50.6, 49.8, 51.2, 49.7, 51.5, 50.3, 51.0, 50.6)
t.test(x, mu = 50, alternative = 'greater')
```

## 正态总体单样本方差检验

```set.seed(123)
x <- rnorm(20, 500, 20)
var_test(x, 400)
```

## 比例假设检验

### 单样本

`RDA`包中的`proptest`函数可以进行单样本比例检验：

```proptest(45, 100, 0.5, alternative = 'twoside')
proptest(450, 1000, 0.5, alternative = 'twoside')
```

### 两样本

```prop.test(c(45, 56), c(45 + 35, 56 + 47))
```

# 非参数假设检验

## 秩和检验

```x <- c(21240, 4632, 22836, 5484, 5052, 5064, 6972, 7596, 14760, 15012, 18720, 9480, 4728, 67200, 52788)
(Ri <- rank(x))
```

`Ri`就是数据`X`的秩，利用秩的大小进行推断就避免了不知道数据分布的困难。这也是大多数非参数检验的优点。

### 单样本符号秩检验

```x <- c(21240, 4632, 22836, 5484, 5052, 5064, 6972, 7596,
14760, 15012, 18720, 9480, 4728, 67200, 52788)
wilcox.test(x, mu = 5080)
```

```x <- c(21240,4632,22836,5484,5052,5064,6972,7596,
14760,15012,18720,9480,4728,67200,52788)
median_test(x, median = 5080)
```

# 线性回归模型的扩展

## 异方差性

```data("plantarea_outputvalue")
GQtest(plantarea_outputvalue\$plant_area,plantarea_outputvalue\$output_value)
```

# 绘制三维图形

```x <- seq(-10, 10, length = 30)
y <- x
f <- function(x, y){r <- sqrt(x ^ 2 + y ^ 2);10 * sin (r) / r}
plot3D(x, y, f)
```

zhaoxue-xmu/RDA documentation built on May 28, 2017, 12:47 p.m.