Soal 1. Persiapan Data

# Soal 1. Persiapan data

data <- data.frame(
  id = 1:30,
  before = c(140,150,135,142,128,155,138,147,131,144,
             129,152,141,137,148,133,149,136,130,145,
             139,143,134,151,127,146,132,140,138,135),
  after = c(132,145,130,138,125,148,135,140,128,136,
            125,146,135,132,142,130,144,133,127,140,
            134,138,130,145,124,139,128,137,134,131)
)

data
##    id before after
## 1   1    140   132
## 2   2    150   145
## 3   3    135   130
## 4   4    142   138
## 5   5    128   125
## 6   6    155   148
## 7   7    138   135
## 8   8    147   140
## 9   9    131   128
## 10 10    144   136
## 11 11    129   125
## 12 12    152   146
## 13 13    141   135
## 14 14    137   132
## 15 15    148   142
## 16 16    133   130
## 17 17    149   144
## 18 18    136   133
## 19 19    130   127
## 20 20    145   140
## 21 21    139   134
## 22 22    143   138
## 23 23    134   130
## 24 24    151   145
## 25 25    127   124
## 26 26    146   139
## 27 27    132   128
## 28 28    140   137
## 29 29    138   134
## 30 30    135   131

Soal 2. Visualisasi

# Soal 2. Visualisasi

boxplot(data$before, data$after,
        names = c("Sebelum", "Sesudah"),
        main = "Tekanan Darah Sebelum dan Sesudah Intervensi",
        ylab = "Tekanan Darah Sistolik (mmHg)")

Soal 3. Pemeriksaan Asumsi

# Soal 3. Pemeriksaan asumsi

data$diff <- data$before - data$after

shapiro.test(data$diff)
## 
##  Shapiro-Wilk normality test
## 
## data:  data$diff
## W = 0.89942, p-value = 0.008129

Soal 4. Uji Hipotesis Paired t-test:

# Soal 4. Uji hipotesis
# Paired t-test

t.test(data$before,
       data$after,
       paired = TRUE)
## 
##  Paired t-test
## 
## data:  data$before and data$after
## t = 16.826, df = 29, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  4.216556 5.383444
## sample estimates:
## mean difference 
##             4.8

Wilcoxon signed-rank test:

# Uji Wilcoxon Signed-Rank

wilcox.test(data$before,
            data$after,
            paired = TRUE)
## Warning in wilcox.test.default(data$before, data$after, paired = TRUE): cannot
## compute exact p-value with ties
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  data$before and data$after
## V = 465, p-value = 1.619e-06
## alternative hypothesis: true location shift is not equal to 0

Soal 5. Ukuran Efek

# Soal 5. Ukuran efek

mean_diff <- mean(data$diff)
sd_diff <- sd(data$diff)

cohen_d <- mean_diff / sd_diff

cohen_d
## [1] 3.072017

Soal 6. Laporan Singkat

# Soal 6. Laporan singkat

mean_before <- mean(data$before)
sd_before <- sd(data$before)

mean_after <- mean(data$after)
sd_after <- sd(data$after)

mean_diff <- mean(data$diff)
sd_diff <- sd(data$diff)

hasil_t <- t.test(data$before,
                  data$after,
                  paired = TRUE)

cat("Mean sebelum =", mean_before, "\n")
## Mean sebelum = 139.8333
cat("SD sebelum =", sd_before, "\n")
## SD sebelum = 7.70617
cat("Mean sesudah =", mean_after, "\n")
## Mean sesudah = 135.0333
cat("SD sesudah =", sd_after, "\n")
## SD sesudah = 6.713257
cat("Mean selisih =", mean_diff, "\n")
## Mean selisih = 4.8
cat("SD selisih =", sd_diff, "\n")
## SD selisih = 1.562491
cat("t hitung =", hasil_t$statistic, "\n")
## t hitung = 16.82613
cat("df =", hasil_t$parameter, "\n")
## df = 29
cat("p-value =", hasil_t$p.value, "\n")
## p-value = 1.674497e-16
cat("Confidence Interval =", hasil_t$conf.int, "\n")
## Confidence Interval = 4.216556 5.383444
cat("Cohen's d =", cohen_d, "\n")
## Cohen's d = 3.072017

jika memakai csv datanya Soal 1. Persiapan Data

# Soal 1. Persiapan data

data <- read.csv("bp_before_after.csv")

head(data)
##   id before after
## 1  1    140   132
## 2  2    150   145
## 3  3    135   130
## 4  4    142   138
## 5  5    128   125
## 6  6    155   148
data
##    id before after
## 1   1    140   132
## 2   2    150   145
## 3   3    135   130
## 4   4    142   138
## 5   5    128   125
## 6   6    155   148
## 7   7    138   135
## 8   8    147   140
## 9   9    131   128
## 10 10    144   136
## 11 11    129   125
## 12 12    152   146
## 13 13    141   135
## 14 14    137   132
## 15 15    148   142
## 16 16    133   130
## 17 17    149   144
## 18 18    136   133
## 19 19    130   127
## 20 20    145   140
## 21 21    139   134
## 22 22    143   138
## 23 23    134   130
## 24 24    151   145
## 25 25    127   124
## 26 26    146   139
## 27 27    132   128
## 28 28    140   137
## 29 29    138   134
## 30 30    135   131

Soal 2. Visualisasi

# Soal 2. Visualisasi

boxplot(data$before, data$after,
        names = c("Sebelum", "Sesudah"),
        main = "Tekanan Darah Sebelum dan Sesudah Intervensi",
        ylab = "Tekanan Darah Sistolik (mmHg)")

Soal 3. Pemeriksaan Asumsi

# Soal 3. Pemeriksaan asumsi

data$diff <- data$before - data$after

shapiro.test(data$diff)
## 
##  Shapiro-Wilk normality test
## 
## data:  data$diff
## W = 0.89942, p-value = 0.008129

Soal 4. Uji Hipotesis Paired t-test

# Soal 4. Paired t-test

t.test(data$before,
       data$after,
       paired = TRUE)
## 
##  Paired t-test
## 
## data:  data$before and data$after
## t = 16.826, df = 29, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  4.216556 5.383444
## sample estimates:
## mean difference 
##             4.8

Wilcoxon Signed-Rank Test

# Uji Wilcoxon Signed-Rank

wilcox.test(data$before,
            data$after,
            paired = TRUE)
## Warning in wilcox.test.default(data$before, data$after, paired = TRUE): cannot
## compute exact p-value with ties
## 
##  Wilcoxon signed rank test with continuity correction
## 
## data:  data$before and data$after
## V = 465, p-value = 1.619e-06
## alternative hypothesis: true location shift is not equal to 0

Soal 5. Ukuran Efek

# Soal 5. Ukuran efek

mean_diff <- mean(data$diff)

sd_diff <- sd(data$diff)

cohen_d <- mean_diff / sd_diff

cohen_d
## [1] 3.072017

Soal 6. Laporan Singkat

# Soal 6. Laporan singkat

mean_before <- mean(data$before)
sd_before <- sd(data$before)

mean_after <- mean(data$after)
sd_after <- sd(data$after)

mean_diff <- mean(data$diff)
sd_diff <- sd(data$diff)

hasil_t <- t.test(data$before,
                  data$after,
                  paired = TRUE)

mean_before
## [1] 139.8333
sd_before
## [1] 7.70617
mean_after
## [1] 135.0333
sd_after
## [1] 6.713257
mean_diff
## [1] 4.8
sd_diff
## [1] 1.562491
hasil_t
## 
##  Paired t-test
## 
## data:  data$before and data$after
## t = 16.826, df = 29, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  4.216556 5.383444
## sample estimates:
## mean difference 
##             4.8

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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

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