Github Code: Hoon0427/RPubs
library(formattable)
library(ggplot2)
library(tidyverse)
before_study <- c(34, 76, 76, 63, 73, 75, 67, 78, 81, 53, 58, 81, 77, 80, 43, 65, 76, 63, 54, 64, 85, 54, 70, 71, 71, 55, 40, 78, 76, 100, 51, 93, 64, 42, 63, 61, 82, 67, 98, 59, 63, 84, 50, 67, 80, 83, 66, 86, 57, 48)
after_study <- c (74, 87, 89, 98, 65, 82, 70, 70, 70, 84, 56, 76, 72, 69, 73, 61, 83, 82, 89, 75, 48, 72, 80, 66, 82, 71, 49, 54, 70, 65, 74, 63, 65, 101, 82, 75, 62, 83, 90, 76, 87, 90, 78, 63, 59, 79, 74, 65, 77, 74)
#boxplot(before_study, after_study, names = c("수강 전", "수강 후),
# col=c("blue", "red"), main="수강전후 성적비교", xlab= "Status", ylab= "Score")
study_compare<-data.frame(before_study, after_study)
study_compare<-cbind("No"=rownames(study_compare), study_compare)
##tidy gather
study_compare_2 <- gather(study_compare, 'before_study', 'after_study',
key="compare", value="score")
study_compare_2$No<-study_compare_2$No %>% as.character() %>% as.numeric()
study_compare_2$compare<-factor(study_compare_2$compare, levels= c("before_study","after_study"))
#ggplot boxplot
ggplot(study_compare_2, aes(x=compare, y=score, fill=compare)) + geom_boxplot()
#ggplot line
ggplot(study_compare_2, aes(x=No, y=score, color=compare)) + geom_line()
#증감표 테이플
study_compare %>%
head(5) %>%
mutate(Difference = after_study - before_study) %>%
mutate(Change = case_when(
Difference > 0 ~ "증가",
Difference < 0 ~ "감소",
TRUE ~ "변동없음"
)) %>%
formattable(., list(
Difference = formatter("span", style = x ~ ifelse(x > 0,
style(color = "Green", font.weight = "bold"), ifelse(x < 0,
style(color = "red"),NA))),
Change = formatter("span", style = x ~ ifelse(x == "증가",
style(color = "Green", font.weight = "bold"), ifelse(x == "감소",
style(color = "red"),NA)))
)
)
| No | before_study | after_study | Difference | Change |
|---|---|---|---|---|
| 1 | 34 | 74 | 40 | 증가 |
| 2 | 76 | 87 | 11 | 증가 |
| 3 | 76 | 89 | 13 | 증가 |
| 4 | 63 | 98 | 35 | 증가 |
| 5 | 73 | 65 | -8 | 감소 |
var_test_vector1 <- c(75,67,78,81,53,71,71,55,40,78,76,42,67,98,59,63,84,50,67,80,83)
var_test_vector2 <- c(58,81,77,80,76,63,54,64,85,54,70,71,71,55,40,78,76,100,51,42,63,61,82,57,48)
var_test_data <- var.test(var_test_vector1,var_test_vector2)
t.test(before_study, after_study, paired=TRUE)
##
## Paired t-test
##
## data: before_study and after_study
## t = -2.1129, df = 49, p-value = 0.03973
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -11.6285348 -0.2914652
## sample estimates:
## mean of the differences
## -5.96
t.test(before_study, after_study, paired=TRUE, alternative = "less")
##
## Paired t-test
##
## data: before_study and after_study
## t = -2.1129, df = 49, p-value = 0.01986
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf -1.230848
## sample estimates:
## mean of the differences
## -5.96
t.test(before_study, after_study, paired = TRUE, alternative = "greater")
##
## Paired t-test
##
## data: before_study and after_study
## t = -2.1129, df = 49, p-value = 0.9801
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
## -10.68915 Inf
## sample estimates:
## mean of the differences
## -5.96
# 증감표 테이블
study_compare %>%
mutate(Difference = after_study - before_study) %>%
mutate(Change = case_when(
Difference > 0 ~ "증가",
Difference < 0 ~ "감소",
TRUE ~ "변동없음"
)) %>%
formattable(., list(
Difference = formatter("span", style = x ~ ifelse(x > 0,
style(color = "Green", font.weight = "bold"), ifelse(x < 0,
style(color = "red"),NA))),
Change = formatter("span", style = x ~ ifelse(x == "증가",
style(color = "Green", font.weight = "bold"), ifelse(x == "감소",
style(color = "red"),NA)))
)
)
| No | before_study | after_study | Difference | Change |
|---|---|---|---|---|
| 1 | 34 | 74 | 40 | 증가 |
| 2 | 76 | 87 | 11 | 증가 |
| 3 | 76 | 89 | 13 | 증가 |
| 4 | 63 | 98 | 35 | 증가 |
| 5 | 73 | 65 | -8 | 감소 |
| 6 | 75 | 82 | 7 | 증가 |
| 7 | 67 | 70 | 3 | 증가 |
| 8 | 78 | 70 | -8 | 감소 |
| 9 | 81 | 70 | -11 | 감소 |
| 10 | 53 | 84 | 31 | 증가 |
| 11 | 58 | 56 | -2 | 감소 |
| 12 | 81 | 76 | -5 | 감소 |
| 13 | 77 | 72 | -5 | 감소 |
| 14 | 80 | 69 | -11 | 감소 |
| 15 | 43 | 73 | 30 | 증가 |
| 16 | 65 | 61 | -4 | 감소 |
| 17 | 76 | 83 | 7 | 증가 |
| 18 | 63 | 82 | 19 | 증가 |
| 19 | 54 | 89 | 35 | 증가 |
| 20 | 64 | 75 | 11 | 증가 |
| 21 | 85 | 48 | -37 | 감소 |
| 22 | 54 | 72 | 18 | 증가 |
| 23 | 70 | 80 | 10 | 증가 |
| 24 | 71 | 66 | -5 | 감소 |
| 25 | 71 | 82 | 11 | 증가 |
| 26 | 55 | 71 | 16 | 증가 |
| 27 | 40 | 49 | 9 | 증가 |
| 28 | 78 | 54 | -24 | 감소 |
| 29 | 76 | 70 | -6 | 감소 |
| 30 | 100 | 65 | -35 | 감소 |
| 31 | 51 | 74 | 23 | 증가 |
| 32 | 93 | 63 | -30 | 감소 |
| 33 | 64 | 65 | 1 | 증가 |
| 34 | 42 | 101 | 59 | 증가 |
| 35 | 63 | 82 | 19 | 증가 |
| 36 | 61 | 75 | 14 | 증가 |
| 37 | 82 | 62 | -20 | 감소 |
| 38 | 67 | 83 | 16 | 증가 |
| 39 | 98 | 90 | -8 | 감소 |
| 40 | 59 | 76 | 17 | 증가 |
| 41 | 63 | 87 | 24 | 증가 |
| 42 | 84 | 90 | 6 | 증가 |
| 43 | 50 | 78 | 28 | 증가 |
| 44 | 67 | 63 | -4 | 감소 |
| 45 | 80 | 59 | -21 | 감소 |
| 46 | 83 | 79 | -4 | 감소 |
| 47 | 66 | 74 | 8 | 증가 |
| 48 | 86 | 65 | -21 | 감소 |
| 49 | 57 | 77 | 20 | 증가 |
| 50 | 48 | 74 | 26 | 증가 |