【R】report

1. はじめに

reportは、Rでの結果をレポートするために見やすく表示してくれるパッケージです。

2. インストール

CRANからインストールできます。

install.packages("report")

3. つかってみる

データのレポートもできます。

library(report)
report(mtcars)
> report(mtcars)
The data contains 32 observations of the following 11 variables:
  - mpg: n = 32, Mean = 20.09, SD = 6.03, Median = 19.20, MAD = 5.41, range: [10.40, 33.90], Skewness = 0.67, Kurtosis = -0.02, 0 missing
  - cyl: n = 32, Mean = 6.19, SD = 1.79, Median = 6.00, MAD = 2.97, range: [4, 8], Skewness = -0.19, Kurtosis = -1.76, 0 missing
  - disp: n = 32, Mean = 230.72, SD = 123.94, Median = 196.30, MAD = 140.48, range: [71.10, 472], Skewness = 0.42, Kurtosis = -1.07, 0 missing
  - hp: n = 32, Mean = 146.69, SD = 68.56, Median = 123.00, MAD = 77.10, range: [52, 335], Skewness = 0.80, Kurtosis = 0.28, 0 missing
  - drat: n = 32, Mean = 3.60, SD = 0.53, Median = 3.70, MAD = 0.70, range: [2.76, 4.93], Skewness = 0.29, Kurtosis = -0.45, 0 missing
  - wt: n = 32, Mean = 3.22, SD = 0.98, Median = 3.33, MAD = 0.77, range: [1.51, 5.42], Skewness = 0.47, Kurtosis = 0.42, 0 missing
  - qsec: n = 32, Mean = 17.85, SD = 1.79, Median = 17.71, MAD = 1.42, range: [14.50, 22.90], Skewness = 0.41, Kurtosis = 0.86, 0 missing
  - vs: n = 32, Mean = 0.44, SD = 0.50, Median = 0.00, MAD = 0.00, range: [0, 1], Skewness = 0.26, Kurtosis = -2.06, 0 missing
  - am: n = 32, Mean = 0.41, SD = 0.50, Median = 0.00, MAD = 0.00, range: [0, 1], Skewness = 0.40, Kurtosis = -1.97, 0 missing
  - gear: n = 32, Mean = 3.69, SD = 0.74, Median = 4.00, MAD = 1.48, range: [3, 5], Skewness = 0.58, Kurtosis = -0.90, 0 missing
  - carb: n = 32, Mean = 2.81, SD = 1.62, Median = 2.00, MAD = 1.48, range: [1, 8], Skewness = 1.16, Kurtosis = 2.02, 0 missing

tidyverseの中でも使えます。

library(tidyverse)

diamonds %>% 
  group_by(cut) %>% 
  report() %>% 
  summary()
+   summary()
The data contains 53940 observations, grouped by cut, of the following 10 variables:

- Fair (n = 1610):
  - carat: Mean = 1.05, SD = 0.52, range: [0.22, 5.01]
  - color: 7 levels, namely D (n = 163), E (n = 224), F (n = 312), G (n = 314), H (n = 303), I (n = 175) and J (n = 119)
  - clarity: 8 levels, namely I1 (n = 210), SI2 (n = 466), SI1 (n = 408), VS2 (n = 261), VS1 (n = 170), VVS2 (n = 69), VVS1 (n = 17) and IF (n = 9)
  - depth: Mean = 64.04, SD = 3.64, range: [43, 79]
  - table: Mean = 59.05, SD = 3.95, range: [49, 95]
  - price: Mean = 4358.76, SD = 3560.39, range: [337, 18574]
  - x: Mean = 6.25, SD = 0.96, range: [0, 10.74]
  - y: Mean = 6.18, SD = 0.96, range: [0, 10.54]
  - z: Mean = 3.98, SD = 0.65, range: [0, 6.98]

- Good (n = 4906):
  - carat: Mean = 0.85, SD = 0.45, range: [0.23, 3.01]
  - color: 7 levels, namely D (n = 662), E (n = 933), F (n = 909), G (n = 871), H (n = 702), I (n = 522) and J (n = 307)
  - clarity: 8 levels, namely I1 (n = 96), SI2 (n = 1081), SI1 (n = 1560), VS2 (n = 978), VS1 (n = 648), VVS2 (n = 286), VVS1 (n = 186) and IF (n = 71)
  - depth: Mean = 62.37, SD = 2.17, range: [54.30, 67]
  - table: Mean = 58.69, SD = 2.85, range: [51, 66]
  - price: Mean = 3928.86, SD = 3681.59, range: [327, 18788]
  - x: Mean = 5.84, SD = 1.06, range: [0, 9.44]
  - y: Mean = 5.85, SD = 1.05, range: [0, 9.38]
  - z: Mean = 3.64, SD = 0.65, range: [0, 5.79]

- Very Good (n = 12082):
  - carat: Mean = 0.81, SD = 0.46, range: [0.20, 4]
  - color: 7 levels, namely D (n = 1513), E (n = 2400), F (n = 2164), G (n = 2299), H (n = 1824), I (n = 1204) and J (n = 678)
  - clarity: 8 levels, namely I1 (n = 84), SI2 (n = 2100), SI1 (n = 3240), VS2 (n = 2591), VS1 (n = 1775), VVS2 (n = 1235), VVS1 (n = 789) and IF (n = 268)
  - depth: Mean = 61.82, SD = 1.38, range: [56.80, 64.90]
  - table: Mean = 57.96, SD = 2.12, range: [44, 66]
  - price: Mean = 3981.76, SD = 3935.86, range: [336, 18818]
  - x: Mean = 5.74, SD = 1.10, range: [0, 10.01]
  - y: Mean = 5.77, SD = 1.10, range: [0, 9.94]
  - z: Mean = 3.56, SD = 0.73, range: [0, 31.80]

- Premium (n = 13791):
  - carat: Mean = 0.89, SD = 0.52, range: [0.20, 4.01]
  - color: 7 levels, namely D (n = 1603), E (n = 2337), F (n = 2331), G (n = 2924), H (n = 2360), I (n = 1428) and J (n = 808)
  - clarity: 8 levels, namely I1 (n = 205), SI2 (n = 2949), SI1 (n = 3575), VS2 (n = 3357), VS1 (n = 1989), VVS2 (n = 870), VVS1 (n = 616) and IF (n = 230)
  - depth: Mean = 61.26, SD = 1.16, range: [58, 63]
  - table: Mean = 58.75, SD = 1.48, range: [51, 62]
  - price: Mean = 4584.26, SD = 4349.20, range: [326, 18823]
  - x: Mean = 5.97, SD = 1.19, range: [0, 10.14]
  - y: Mean = 5.94, SD = 1.26, range: [0, 58.90]
  - z: Mean = 3.65, SD = 0.73, range: [0, 8.06]

- Ideal (n = 21551):
  - carat: Mean = 0.70, SD = 0.43, range: [0.20, 3.50]
  - color: 7 levels, namely D (n = 2834), E (n = 3903), F (n = 3826), G (n = 4884), H (n = 3115), I (n = 2093) and J (n = 896)
  - clarity: 8 levels, namely I1 (n = 146), SI2 (n = 2598), SI1 (n = 4282), VS2 (n = 5071), VS1 (n = 3589), VVS2 (n = 2606), VVS1 (n = 2047) and IF (n = 1212)
  - depth: Mean = 61.71, SD = 0.72, range: [43, 66.70]
  - table: Mean = 55.95, SD = 1.25, range: [43, 63]
  - price: Mean = 3457.54, SD = 3808.40, range: [326, 18806]
  - x: Mean = 5.51, SD = 1.06, range: [0, 9.65]
  - y: Mean = 5.52, SD = 1.07, range: [0, 31.80]
  - z: Mean = 3.40, SD = 0.66, range: [0, 6.03]

検定結果をデータフレーム形式で出力もできます。

cor.test(mtcars$mpg, mtcars$am) %>%
  report() %>%
  as.data.frame()
Parameter1 | Parameter2 |    r |       95% CI | t(30) |      p |                               Method | Alternative
-------------------------------------------------------------------------------------------------------------------
mtcars$mpg |  mtcars$am | 0.60 | [0.32, 0.78] |  4.11 | < .001 | Pearson's product-moment correlation |   two.sided

4. さいごに

レポートには便利なパッケージです。レポートでなくてもちょっとした結果の確認にも見やすくていいですね。

Add a Comment

メールアドレスが公開されることはありません。