library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ 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(dplyr)
library(ggplot2)

Veri Seçimi Veri seçimi için İsviçre’deki bölgelere ait sosyoekonomik göstergeleri içeren “SWiss” veri seti kullanılmıştır.

data("swiss")
head(swiss)
##              Fertility Agriculture Examination Education Catholic
## Courtelary        80.2        17.0          15        12     9.96
## Delemont          83.1        45.1           6         9    84.84
## Franches-Mnt      92.5        39.7           5         5    93.40
## Moutier           85.8        36.5          12         7    33.77
## Neuveville        76.9        43.5          17        15     5.16
## Porrentruy        76.1        35.3           9         7    90.57
##              Infant.Mortality
## Courtelary               22.2
## Delemont                 22.2
## Franches-Mnt             20.2
## Moutier                  20.3
## Neuveville               20.6
## Porrentruy               26.6

Eksik veriler kontrol edilmiş ve eksik verinin bulunmadığı saptanmıştır.

colSums(is.na(swiss))
##        Fertility      Agriculture      Examination        Education 
##                0                0                0                0 
##         Catholic Infant.Mortality 
##                0                0
swiss %>% 
  summarise(korelasyon = cor(Fertility, Education))
##   korelasyon
## 1 -0.6637889

cor() fonksiyonu kullanılarak fertility(doğurganlık oranı) ve education(eğitim düzeyi) değişkenleri arasındaki ilişki incelenmiştir. Korelasyon sonucuna göre doğurganlık oranı ile eğitim düzeyi arasında orta düzeyde negatif yönlü bir ilişki tespit edilmiştir (r = −0.66). Bu sonuç, eğitim düzeyinin artmasıyla doğurganlık oranının azalma eğiliminde olduğunu göstermektedir. Korelasyon katsayısının negatif olması, değişkenler arasında ters yönlü bir ilişki olduğunu göstermektedir.

Verilerin Görselleştirilmesi

ggplot(data = swiss, aes(x= Fertility, y= Education)) +
  geom_point(size=2) +
  geom_smooth(method = "lm", color= "red",se= FALSE)+
  labs(x="Dogurganlik Orani", y="Egitim Duzeyi", title ="Dogurganlik ile Egitim Duzeyi Arasindaki İliski" ) +
  theme_classic()
## `geom_smooth()` using formula = 'y ~ x'

Saçılım grafiğinde ilişkinin negatif yönde olduğu ve de veride uç değerlerin bulunduğu gözlemlenmektedir.

library(corrplot)
## Warning: package 'corrplot' was built under R version 4.5.2
## corrplot 0.95 loaded
korelasyon_matrisi <- cor(swiss[, c("Fertility", "Education")])

corrplot(korelasyon_matrisi,
         method = "circle",
         type = "full",
         addCoef.col = "black",
         tl.col = "darkblue")

Anlamlılık düzeyinin psych paketiyle incelenmesi

library(psych)
## Warning: package 'psych' was built under R version 4.5.2
## 
## Attaching package: 'psych'
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
anlamlilik_duzeyi<- corr.test(swiss[, c("Fertility", "Education")])

corrplot(anlamlilik_duzeyi$r,
         p.mat = anlamlilik_duzeyi$p,
         sig.level = 0.05,
         insig = "blank",
         method = "square",
         addCoef.col = "black")

Hmisc paketiyle veri setindeki korelasyon matrisine yönelik grafiğin incelenmesi.

library(Hmisc)
## Warning: package 'Hmisc' was built under R version 4.5.2
## 
## Attaching package: 'Hmisc'
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
data <- swiss
corr_swiss <- rcorr(as.matrix(data))
r <- corr_swiss$r
p<- corr_swiss$ p
corPlot(r, method = "square", 
         outline = T,
         addgrid.col = "darkgray",      type = "upper",
         order="hclust",
        cex = 0,7)
## Warning in axis(2, at = at2, labels = lab2, las = ylas, ...): "method" is not a
## graphical parameter
## Warning in axis(2, at = at2, labels = lab2, las = ylas, ...): "outline" is not
## a graphical parameter
## Warning in axis(2, at = at2, labels = lab2, las = ylas, ...): "addgrid.col" is
## not a graphical parameter
## Warning in axis(2, at = at2, labels = lab2, las = ylas, ...): graphical
## parameter "type" is obsolete
## Warning in axis(2, at = at2, labels = lab2, las = ylas, ...): "order" is not a
## graphical parameter
## Warning in axis(xaxis, at = at1, labels = lab1, las = xlas, line = line, :
## "method" is not a graphical parameter
## Warning in axis(xaxis, at = at1, labels = lab1, las = xlas, line = line, :
## "outline" is not a graphical parameter
## Warning in axis(xaxis, at = at1, labels = lab1, las = xlas, line = line, :
## "addgrid.col" is not a graphical parameter
## Warning in axis(xaxis, at = at1, labels = lab1, las = xlas, line = line, :
## graphical parameter "type" is obsolete
## Warning in axis(xaxis, at = at1, labels = lab1, las = xlas, line = line, :
## "order" is not a graphical parameter
## Warning in text.default(rx, ry, rv, cex = 1.5 * cex, ...): "method" is not a
## graphical parameter
## Warning in text.default(rx, ry, rv, cex = 1.5 * cex, ...): "outline" is not a
## graphical parameter
## Warning in text.default(rx, ry, rv, cex = 1.5 * cex, ...): "addgrid.col" is not
## a graphical parameter
## Warning in text.default(rx, ry, rv, cex = 1.5 * cex, ...): graphical parameter
## "type" is obsolete
## Warning in text.default(rx, ry, rv, cex = 1.5 * cex, ...): "order" is not a
## graphical parameter
## Warning in axis(4, at = at2, labels = labels, las = 2, ...): "method" is not a
## graphical parameter
## Warning in axis(4, at = at2, labels = labels, las = 2, ...): "outline" is not a
## graphical parameter
## Warning in axis(4, at = at2, labels = labels, las = 2, ...): "addgrid.col" is
## not a graphical parameter
## Warning in axis(4, at = at2, labels = labels, las = 2, ...): graphical
## parameter "type" is obsolete
## Warning in axis(4, at = at2, labels = labels, las = 2, ...): "order" is not a
## graphical parameter

GGally paketiyle değişkenler arasındaki ilişkinin incelenmesi

library(GGally)
## Warning: package 'GGally' was built under R version 4.5.2
data_1<- swiss[, c("Fertility", "Education")]
ggpairs(data_1, title = "correlogram")

Değişkenler arasındaki ilşkinin boxplot ile tespit edilmesi ve uç değerlerin daha iyi görülmesi.

data(swiss)

box_plot_1 <- swiss %>%
  select(Fertility, Education) %>%
  pivot_longer(cols = everything(), names_to = "Degisken", values_to = "Deger")

ggplot(box_plot_1, aes(x = Degisken, y = Deger, fill = Degisken)) +
  geom_boxplot(alpha = 0.7) +
  labs(
    title = "Dogum Orani  ve Eğitim Duzeyi Degiskenlerinin Kutu Grafigi",
    x = "Degisken",
    y = "Deger"
  ) +
  theme_minimal()

Öğrenme Günlüğü

Bu çalışma sonucunda korelasyon hesaplanması ve grafiklerin korelasyon sonuçlarını yorumlamakta kullanılan farklı yöntemleri öğrenme şansı buldum. Değişkenler arasındaki ilişkinin anlamlılığı ve yönü hakkındaki aynı anda bilgi veren grafiklerin kullanımını öğrendim. bununla birlikte anlamlılık düzeyinin grafikte görsel olarak gözükmesi değişkenler e-arası ilişkiyi kavramak açısından yararlıydı. ilk başta cor() fonksiyonu ile ilşkiyi inceledim fakat grafikleri olşuturduktan sonra ilişki hakkında kafamda daha somut bilgiler oluştu. Bu nedenle yaptığım işlemlerin göselleştirilmesinin öneminin farkına vardım.