DAY 30
1

## Day 30- R語言 假設檢定 (Hypothesis testing) 函數練習

Day 30- R語言 假設檢定 (Hypothesis testing) 的函數

``````t.test(x, y = NULL,
alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE,
conf.level = 0.95, ...)
``````

`x`, `y`代表資料組
`alternative`設定對立假設，可以為 `“two.sided”`, `“less”`, `“greater”`三個種類
`mu` = 單一樣本T檢定是用來檢驗平均值是否等於該數字、獨立樣本T檢定是用來檢驗平均值的差是否等於該數字
`paired` = 用來設定是否需要成對樣本T檢定
`var.equal` = 設定變異數相等與否
`conf.level` = 對區間的信任程度

``````x <- sample(1:100, size = 10, replace = FALSE)
t.test(x, mu = 30)
``````

``````	One Sample t-test

data:  x
t = 1.3129, df = 9, p-value = 0.2217
alternative hypothesis: true mean is not equal to 30
95 percent confidence interval:
21.25089 62.94911
sample estimates:
mean of x
42.1
``````

``````> t.test(x, mu = 30, alternative = "less")

One Sample t-test

data:  x
t = 1.3129, df = 9, p-value = 0.8891
alternative hypothesis: true mean is less than 30
95 percent confidence interval:
-Inf 58.99483
sample estimates:
mean of x
42.1

> t.test(x, mu = 30, alternative = "greater")

One Sample t-test

data:  x
t = 1.3129, df = 9, p-value = 0.1109
alternative hypothesis: true mean is greater than 30
95 percent confidence interval:
25.20517      Inf
sample estimates:
mean of x
42.1
``````

``````c1 <- c(90, 87, 98, 98, 96)
c2 <- c(89, 86, 87, 86, 84)

t.test(c1, c2, paired = TRUE)
``````

``````Paired t-test

data:  c1 and c2
t = 2.8253, df = 4, p-value = 0.04757
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.1280456 14.6719544
sample estimates:
mean of the differences
7.4
``````

1. 學習統計學概念，畢竟R最大的功能還是做資料處理，如果沒有熟悉基礎統計學的原理，那麼R要運用起來可能還是有點難度（就像我現在這樣 :’)）
2. 探索其它套件，靈活運用R語言
3. 學習如何運用其他R語言函數

### 1 則留言

0

iT邦好手 1 級 ‧ 2020-02-03 06:14:31