1 データの読み込み

library(readxl)
time <- read_excel("time.xlsx")

2 記述統計

# 平均
mean(time$time)
## [1] 62.35294
# 中央値
median(time$time)
## [1] 60
# 最大値
max(time$time)
## [1] 120
# 最小値
min(time$time)
## [1] 25

3 ヒストグラム with hist

hist(time$time)

4 データの読み込み

library(readxl)
time2 <- read_excel("time2.xlsx")

5 グラフ with ggplot2

# パッケージ
library("ggplot2")

# グラフ
graph <- ggplot(time2, aes(x = school, y = work)) +
  geom_point()+
  geom_smooth(se = FALSE, method = 'lm') +
  theme_bw()
graph

6 動的グラフ with plotly

library("plotly")
ggplotly(graph)
# If you would like to save your graph, you can use:
ggsave('my_graph.pdf', graph, width = 14, height = 14, units = 'cm')

7 確率密度関数の例

x=seq(0,1,0.01)
y=6*(x-x^2)
plot(x,y)

7.1 標準正規分布

x=seq(-5,5,0.01)
y=(1/sqrt(2*pi))*exp(-(x^2/2))
plot(x,y)

curve(dnorm,-5,5)

7.2 正規分布

x=seq(5,15,0.01)
m=10
s=5

y=(1/(sqrt(2*pi)*s^2))*exp(-((x-m)^2/2*s^2))
plot(x,y)

7.3 平均が18、標準偏差10の正規分布

curve(dnorm(x,18,10),0,40)

X=c(28,13,16,28,29,12,14,12,10)
hist(X)

mean<-mean(X)
low<-mean-1.96*(10/3)
upper<-mean+1.96*(10/3)
mean
## [1] 18
low
## [1] 11.46667
upper
## [1] 24.53333

8 例)身長のデータ

library(readxl)
height <- read_excel("height.xlsx")
hist(height$h)

8.1 正規分布

mean(height$h)
## [1] 167.5833
sd(height$h)
## [1] 9.307459
x=seq(147,187,1)
y=dnorm(x,167.5,9.3)
plot(x,y)

9 中心極限定理

x=runif(1000000)
hist(x, freq=FALSE)

x=x+runif(1000000)+runif(1000000)+runif(1000000)
hist(x,freq = FALSE)