## Normal Distribution
# sampling
nRandom <- 1000000 # sample size
# 평균이 0이고 표준편차가 5인 정규분포에서 임의로 데이터 뽑기
Z <- rnorm(nRandom, mean = 0, sd = 5) 
# 평균이 0이고 표준편차가 1인 정규분포에서 임의로 데이터 뽑기
Z1 <- rnorm(nRandom, mean = 0, sd = 1) 
# visualization
hist(Z, col = "orange", xlab = "Values") # 첫 번째 히스토그램 그리기
hist(Z1, col = "purple", add = TRUE) # 두 번째 히스토그램을 추가로 겹쳐서 그리기
legend("topright", legend = c("Z1", "Z2"), fill = c("orange", "purple")) # 범례 추가

# 평균이 0이고 표준편차가 1인 표준 정규분포에서 확률이 0.95일 때의 값을 계산
x <- qnorm(0.95, mean = 0, sd = 1)
x
## [1] 1.644854
# 평균이 0이고 표준편차가 1인 표준 정규분포에서 x값이 3보다 작을 확률 계산
p <- pnorm(3, mean = 0, sd = 1)
p
## [1] 0.9986501
##Because this is Z distribition the mean score is 0 and 
##the standard deviation is 10.

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

### 실습1
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
## function1: 두 개의 주사위를 던져 나오는 눈의 합을 구하는 함수
dice <- function(x) {
a <- sample(1:6, 2, replace = TRUE)
b <- sum(a)
return(b)
}


n = 1000 #숫자 바꾸기
## function: funtion1을 n 번 실행하고 얻어진 결과를 막대그래프로 표시
lapply(1:n, dice) %>%
do.call('rbind', .) %>%
as.data.frame() %>%
group_by(V1) %>%
summarise(n = n()) %>%
ggplot(aes(V1, n)) +
geom_bar(stat ='identity')

Including Plots

You can also embed plots, for example:

qnorm(0.9, mean = 70, sd = 10)
## [1] 82.81552
##When the average score for the exam is 80 and the standared deviation is 10. ##I should get at least 82.82 to be the top 10% to get an A grade

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

qnorm(0.95, mean=35, sd=5)
## [1] 43.22427
sample_mean=35
sample_std_dev<-5
threshold<-40
sample<-10
sample_size<-10
t_value <- (threshold - sample_mean) / (sample_std_dev / sqrt(sample_size))
answer <- 1 - pt(t_value, df = sample_size - 1)
percentage <- answer * 100

percentage
## [1] 0.5753993
#The percemtage is 57.5%