library(readxl)
time <- read_excel("time.xlsx")
mean(time$time)
## [1] 62.35294
hist(time$time)

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

## You can use the below code to generate the graph.
## Don't forget to replace the 'df' with the name
## of your dataframe

# You need the following package(s):
library("ggplot2")

# The code below will generate the graph:
graph <- ggplot(time2, aes(x = school, y = work)) +
  geom_point()+
  geom_smooth(se = FALSE, method = 'lm') +
  theme_bw()
graph
## `geom_smooth()` using formula = 'y ~ x'

# If you want the plot to be interactive,
# you need the following package(s):
library("plotly")
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
ggplotly(graph)
## `geom_smooth()` using formula = 'y ~ x'
# If you would like to save your graph, you can use:
ggsave('my_graph.pdf', graph, width = 14, height = 14, units = 'cm')
## `geom_smooth()` using formula = 'y ~ x'

確率密度関数の一例

教科書p.70 例題2

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

標準正規分布

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

curve(dnorm,-5,5)

正規分布

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)

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

#正規分布
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)