KULLANILACAK PAKETLER

 library(psych)
library(naniar)
library(ggplot2)
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
 library(finalfit) 
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ lubridate 1.9.4     ✔ tibble    3.2.1
## ✔ purrr     1.0.4     ✔ tidyr     1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ ggplot2::%+%()   masks psych::%+%()
## ✖ ggplot2::alpha() masks psych::alpha()
## ✖ dplyr::filter()  masks stats::filter()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(mvdalab)
## 
## Attaching package: 'mvdalab'
## 
## The following object is masked from 'package:psych':
## 
##     smc
library(mice)
## 
## Attaching package: 'mice'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     cbind, rbind
library(dplyr)

A-Veri seti adı: “TRUSA.RDS”. Bu veri setini R ortamına aktarınız.

 dat<- readRDS("C:/Users/Salih/Desktop/TRUSA.rds")

B-Veri setinde eksik veri olup olmadığını kontrol ediniz.

any_na(dat)
## [1] FALSE

#veri setinde kayıp veri yoktur

C-Kitapçıktaki 35 maddenin toplamını hesaplayarak veri setine yeni bir sütun olarak ekleyiniz.

dat <- dat %>%
  mutate(toplam = rowSums(across(3:37), na.rm = TRUE))

D- Toplam puanın her iki ülkeye göre betimsel istatistiklerini hesaplayınız.

summary_stats <- dat %>%
  filter(CNT %in% c("TUR", "USA")) %>%
  group_by(CNT) %>%
  summarise(
    mean = mean(toplam, na.rm = TRUE),
    median = median(toplam, na.rm = TRUE),
    sd = sd(toplam, na.rm = TRUE),
    min = min(toplam, na.rm = TRUE),
    max = max(toplam, na.rm = TRUE),
    range = max(toplam, na.rm = TRUE) - min(toplam, na.rm = TRUE),
    IQR = IQR(toplam, na.rm = TRUE)
  )

E- Toplam puanın, Türkiye ve ABD örneklemlerinde farklılaşıp farklılaşmadığını t testi ile test ediniz.

turkey_data <- dat %>%           
  filter(CNT == "TUR") %>%
  pull(toplam)


usa_data <- dat %>%        
  filter(CNT == "USA") %>%
  pull(toplam)


t_test_result <- t.test(turkey_data, usa_data)   

print(t_test_result) 
## 
##  Welch Two Sample t-test
## 
## data:  turkey_data and usa_data
## t = -7.8242, df = 912.31, p-value = 1.41e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.494510 -2.691921
## sample estimates:
## mean of x mean of y 
##  13.45287  17.04609
library(effsize)
## 
## Attaching package: 'effsize'
## The following object is masked from 'package:psych':
## 
##     cohen.d
cohen_d <- cohen.d(turkey_data, usa_data)
print(cohen_d)
## 
## Cohen's d
## 
## d estimate: -0.4762813 (small)
## 95 percent confidence interval:
##      lower      upper 
## -0.5971341 -0.3554285

İstatistiksel olarak anlamlı bir ilişki var |d| = 0.4762813 olduğu için, küçük bir etki olduğu söylenebilir.

F- Veri setinde %5, %10 ve %15 oranında eksik veriler oluşturunuz

delete_MCAR <- function(data, p) {
  # Rastgele bir maske oluştur (TRUE/FALSE değerleri)
  mask <- matrix(runif(nrow(data) * ncol(data)), nrow = nrow(data), ncol = ncol(data)) < p
  
  # Maskedeki TRUE değerlerine karşılık gelen hücreleri NA yap
  data[mask] <- NA
  
  # Değiştirilmiş veriyi döndür
  return(data)
}
set.seed(48)
dat_05 <- delete_MCAR(dat[, 3:37], p = 0.05)
dat_05 <- cbind(dat_05, CNT = dat$CNT)
dat_10 <- delete_MCAR(dat[,3:37],p = 0.10)
dat_10 <- cbind(dat_10,CNT = dat$CNT)
dat_15 <- delete_MCAR(dat[,3:37],p = 0.15)
dat_15 <- cbind(dat_15,CNT = dat$CNT)

 prop_miss(dat_05)
## [1] 0.04792934
  prop_miss(dat_10)
## [1] 0.09561734
   prop_miss(dat_15)
## [1] 0.1472874

G-Oluşturulan eksik veri setlerinde önce eksik verinin rasgele olup olmadığını test ediniz. Ardından, liste bazında silme yöntemiyle eksik verileri temizleyerek e seçeneğinde gerçekleştirdiğiniz t testini tekrarlayınız. Tam veri ile elde edilen sonuçlarla karşılaştırınız.

mcar_test(dat_05)
## Warning in norm::prelim.norm(data): NAs introduced by coercion to integer range
## # A tibble: 1 × 4
##   statistic    df p.value missing.patterns
##       <dbl> <dbl>   <dbl>            <int>
## 1     1681. 18520       1              557
mcar_test(dat_10)
## Warning in norm::prelim.norm(data): NAs introduced by coercion to integer range
## # A tibble: 1 × 4
##   statistic    df p.value missing.patterns
##       <dbl> <dbl>   <dbl>            <int>
## 1     5174. 32377       1             1006
mcar_test(dat_15)
## Warning in norm::prelim.norm(data): NAs introduced by coercion to integer range
## # A tibble: 1 × 4
##   statistic    df p.value missing.patterns
##       <dbl> <dbl>   <dbl>            <int>
## 1   627539. 35052       0             1144

p değerleri 1 çıktı. #p değerlerin anlamsız olduğu için verilerin rastgele dağıldığı söylenebilir.

dat_05_deleted <- na.omit(dat_05)
dat_10_deleted <- na.omit(dat_10)
dat_15_deleted <- na.omit(dat_15)
dat_05_deleted <- dat_05_deleted %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))
  
   dat_10_deleted <- dat_10_deleted %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))
   
    dat_15_deleted <- dat_15_deleted %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))
tr_toplam_05_deleted <- dat_05_deleted %>% filter(CNT == "TUR") %>% select(toplam) %>% unlist()
usa_toplam_05_deleted <- dat_05_deleted %>% filter(CNT == "USA") %>% select(toplam) %>% unlist()
 tr_toplam_10_deleted <- dat_10_deleted %>% filter(CNT == "TUR") %>% select(toplam) %>% unlist()
usa_toplam_10_deleted <- dat_10_deleted %>% filter(CNT == "USA") %>% select(toplam) %>% unlist()
 tr_toplam_15_deleted <- dat_15_deleted %>% filter(CNT == "TUR") %>% select(toplam) %>% unlist()
usa_toplam_15_deleted <- dat_15_deleted %>% filter(CNT == "USA") %>% select(toplam) %>% unlist()
t.test(tr_toplam_05_deleted, usa_toplam_05_deleted) 
## 
##  Welch Two Sample t-test
## 
## data:  tr_toplam_05_deleted and usa_toplam_05_deleted
## t = -2.5408, df = 153.08, p-value = 0.01205
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -5.2246006 -0.6538953
## sample estimates:
## mean of x mean of y 
##  14.12162  17.06087
library(effsize) 
cohen_d <- cohen.d(tr_toplam_05_deleted, usa_toplam_05_deleted)
print(cohen_d)
## 
## Cohen's d
## 
## d estimate: -0.3806705 (small)
## 95 percent confidence interval:
##       lower       upper 
## -0.67718795 -0.08415303

iki değişken arasındaki ilişki var ancak gerçek veri setindeki etki büyüklüğünden daha küçük

t.test(tr_toplam_10_deleted, usa_toplam_10_deleted)
## 
##  Welch Two Sample t-test
## 
## data:  tr_toplam_10_deleted and usa_toplam_10_deleted
## t = -4.3386, df = 19.898, p-value = 0.0003221
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -12.978514  -4.548759
## sample estimates:
## mean of x mean of y 
##  9.636364 18.400000
cohen_d <- cohen.d(tr_toplam_05_deleted, usa_toplam_05_deleted)
print(cohen_d)
## 
## Cohen's d
## 
## d estimate: -0.3806705 (small)
## 95 percent confidence interval:
##       lower       upper 
## -0.67718795 -0.08415303

Elde edilen sonuçlar etki büyüklüğü bakımından hemen hemen %5 düzeyündeki eksik veri ile aynıdır.

#%15 eksik silinmiş veri seti için yeterli değer yok.

**Gerçek veri setinde gruplar arasıdaki farklılık istatistiksel olarak anlamlı bulunmuştu (p>0,05, p=0,00). %5 ve %10 eksi eksik veri setinin temizlenmesinden sonra gruplar arasındaki farklılıklar istatistiksel olarak anlamlı bulunmuştur. %15 eksik veri setinin temizlenmesinden sonra gruplar arasında t testi yapılamamıştır. Eksik verilerde iki grup arasındaki ilişki istatisitksel olarak anlamlı olsa da etki büyüklüğü bakımından elde edilen değerler daha küçüktür.

H-f seçeneğinde oluşturulan veri setlerindeki eksik verileri, belirlediğiniz bir kayıp veri atama yöntemiyle doldurunuz. Daha sonra, e seçeneğinde gerçekleştirdiğiniz t testini tekrar ediniz ve tam veri ile elde edilen sonuçlarla karşılaştırınız.

#çoklu atama denedim ama R hata verdi. Ortalama atama ile eksiklikleri gidereceğim

dat_10 <- dat_10 %>%
  mutate(CNT = dat_05[, 36])

dat_15 <- dat_15 %>%
  mutate(CNT = dat_05[, 36])


dat_05$CNT <- as.numeric(as.factor(dat_05$CNT))
dat_10$CNT <- as.numeric(as.factor(dat_10$CNT))
dat_15$CNT <- as.numeric(as.factor(dat_15$CNT))
  #hata verdiği için kategorik ülke değişkeni sürekli yaptım

for(i in 1:ncol(dat_05)){
  dat_05[ , i][is.na(dat_05[ , i])] <- mean(dat_05[ , i], na.rm = TRUE)
}

for(i in 1:ncol(dat_10)){
  dat_10[ , i][is.na(dat_10[ , i])] <- mean(dat_10[ , i], na.rm = TRUE)
}

for(i in 1:ncol(dat_15)){
  dat_15[ , i][is.na(dat_15[ , i])] <- mean(dat_15[ , i], na.rm = TRUE)
}

any_na(dat_05)
## [1] FALSE
any_na(dat_10)
## [1] FALSE
any_na(dat_15)
## [1] FALSE
dat_05 <- dat_05 %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))


turkey_data_05 <- dat_05 %>%           
  filter(CNT == "1") %>%
  pull(toplam)

usa_data_05 <- dat_05 %>%       
  filter(CNT == "2") %>%
  pull(toplam)

t_test_result <- t.test(turkey_data_05, usa_data_05) 
print(t_test_result) 
## 
##  Welch Two Sample t-test
## 
## data:  turkey_data_05 and usa_data_05
## t = -7.8389, df = 911.44, p-value = 1.265e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.293625 -2.574188
## sample estimates:
## mean of x mean of y 
##  13.55912  16.99303

#%5 eksik verilerin giderilmesi ile elde edilen sonuçlar ile gerçek veri setinde iki grup arasındaki ilişki anlamlı bulunmuştur. t katsayılarıda benzerdir.

dat_10 <- dat_10 %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))

turkey_data_10 <- dat_10 %>%           
  filter(CNT == "1") %>%
  pull(toplam)
usa_data_10 <- dat_10 %>%        
  filter(CNT == "2") %>%
  pull(toplam)

t_test_result <- t.test(turkey_data_10, usa_data_10)
print(t_test_result) 
## 
##  Welch Two Sample t-test
## 
## data:  turkey_data_10 and usa_data_10
## t = -7.7217, df = 919.66, p-value = 2.992e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.043688 -2.404747
## sample estimates:
## mean of x mean of y 
##  13.65349  16.87770

#%10 eksik verilerin giderilmesi ile elde edilen sonuçlar ile gerçek veri setinde iki grup arasındaki ilişki anlamlı bulunmuştur. t katsayılarıda benzerdir.

dat_15 <- dat_15 %>%
  mutate(toplam = rowSums(across(1:35), na.rm = TRUE))
turkey_data_15 <- dat_15 %>%           
  filter(CNT == "1") %>%
  pull(toplam)
usa_data_15 <- dat_15 %>%        
  filter(CNT == "2") %>%
  pull(toplam)

t_test_result <- t.test(turkey_data_15, usa_data_15)   

print(t_test_result) 
## 
##  Welch Two Sample t-test
## 
## data:  turkey_data_15 and usa_data_15
## t = -7.6154, df = 914.54, p-value = 6.55e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -3.774700 -2.227797
## sample estimates:
## mean of x mean of y 
##  13.81931  16.82056

#%15 eksik verilerin giderilmesi ile elde edilen sonuçlar ile gerçek veri setinde iki grup arasındaki ilişki anlamlı bulunmuştur. t katsayılarıda benzerdir

Bu sonuçlar ortalama veri atama yöntemi ile giderilecek eksik veri sorununda istatistiklerde büyük çaplı değişklikler oluşturmayacağını ortaya koymaktadır

Ödevi hazırlamam belki 12 saat sürdü toplamda çünkü 1. dönem R dersini alamamıştım. Öncelikle konuyu anlamaya çalıştım ve günlüğü yaptım. Sonrasında ödeve geçtim. Ödevde ders notlarından chatgpt den ve TUgay ve Sametin ödevlerin yardım aldım bu şekilde hazırlardım. Uzun sürmesinin bir diğer sebebide aldığım hataları çözmek için farklı kaynaklara bakmam oldu bence.