Veri Üretim

Burada iki koşullu bir çalışmadan elde edilen verileri simüle edeceğiz. A koşulundaki ortalama 0 ve B koşulundaki ortalama 1’dir.

n <- 100

data <- data.frame(
  id = 1:n,
  condition = c("A", "B") |> rep(each = n/2),
  dv = c(rnorm(n/2, 0), rnorm(n/2, 1))
)

Grafik

library(datasets)
data(iris)

n <- nrow(iris) # toplam satır sayısı
mu <- mean(iris$Petal.Length)  # taç yaprak uzunluğu ortalaması
sd <- sd(iris$Petal.Length) # taç yaprak uzunluğu standart sapması

simule_deger <- rnorm(n, mu, sd)

set.seed(41)
simule_deger <- rnorm(n, mu, sd)

tac yaprak uzunlugu ortalaması ‘r round(mu, 2)’ dir.

# analiz
library(dplyr)
setosa_petal <- filter(iris, Species == "setosa") %>% #cmnd+shift+m ile yapılır.
  pull(Petal.Length)
virginica_petal <- filter(iris, Species == "virginica") %>%
  pull(Petal.Length)
petal_test <- t.test(setosa_petal, virginica_petal)

# rapor edilecek degerleri yorumlama
t <- petal_test$statistic %>% round(2)
df <- petal_test$parameter %>% round(1)
p <- petal_test$p.value %>% round(3)
# handle p-values < .001
p_symbol <- ifelse(p < .001, "<", "=")
if (p < .001) p <- .001

# sonucları birleştirme
petal_result <- glue::glue("t = {t}, df = {df}, p = {p}")
petal_result
## t = -49.99, df = 58.6, p = 0.001

virginica çiçeklerinin yaprakları setosa çiçeklerinin yapraklarından uzundur(t = -49.99, df = 58.6, p = 0.001).

virginica çiçeklerinin yaprakları (\(\overline{X}_v\) = ‘r round(mean(virginica_petal’), 2)‘) setosa çiçeklerinin yapraklarından (\(\overline{X}_s\) = ’r round(mean(setosa_petal’), 2)’) uzundur (t = -49.99, df = 58.6, p = 0.001).

Tablo oluşturmak

library(knitr)
ozet_tablo <- iris %>%
  group_by(Species) %>%
  summarise(
    n = n(),
    ortalama = mean(Petal.Length),
    sd = sd(Petal.Length)
  )
ozet_tablo %>% kable()
Species n ortalama sd
setosa 50 1.462 0.1736640
versicolor 50 4.260 0.4699110
virginica 50 5.552 0.5518947