An R script for IQ_Beh data set

總覽資料

## 'data.frame':    94 obs. of  3 variables:
##  $ Dep: Factor w/ 2 levels "D","N": 2 2 2 2 1 2 2 2 2 2 ...
##  $ IQ : int  103 124 124 104 96 92 124 99 92 116 ...
##  $ BP : int  4 12 9 3 3 3 6 4 3 9 ...

看資料的圖

##   Dep  IQ BP
## 1   N 103  4
## 2   N 124 12
## 3   N 124  9
## 4   N 104  3
## 5   D  96  3
## 6   N  92  3

資料型態是「資料框」

## [1] "data.frame"

資料有94列3行

## [1] 94  3

變項名稱為:Depressed、IQ、Behavioral Problem

## [1] "Dep" "IQ"  "BP"

向量

## [1] TRUE

第一個資料項目

##   Dep  IQ BP
## 1   N 103  4

第一~第三的IQ數值

## [1] 103 124 124

依Behavioral Problem順序檢視最後面的資料

##    Dep  IQ BP
## 16   N  89 11
## 58   N 117 11
## 66   N 126 11
## 2    N 124 12
## 73   D  99 13
## 12   D  22 17

依Behavioral Problem順序檢視最後面的資料 (資料順序倒反)

##    Dep  IQ BP
## 77   N 124  1
## 80   N 121  1
## 24   N 106  0
## 75   N 122  0

直方圖

盒狀圖

散布圖

回歸線

回歸

## 
## Call:
## lm(formula = BP ~ IQ, data = dta)
## 
## Coefficients:
## (Intercept)           IQ  
##    13.18280     -0.06792

兩組小孩的Behavioral Problems是否有差異 (t考驗)

## 
##  Welch Two Sample t-test
## 
## data:  BP by Dep
## t = 1.4924, df = 17.14, p-value = 0.1538
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.6637017  3.8788916
## sample estimates:
## mean in group D mean in group N 
##        7.000000        5.392405

兩組小孩的IQ是否有差異 (t考驗)

## 
##  Welch Two Sample t-test
## 
## data:  IQ by Dep
## t = -1.6374, df = 15.53, p-value = 0.1216
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -26.926586   3.490299
## sample estimates:
## mean in group D mean in group N 
##        101.0667        112.7848

According to t-test, two groups of children have different IQ and behavioral problems.

end