library(MASS)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.5.2
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:MASS':
##
## select
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
eğim (β₁)
kesişim (β₀)
R-kare (R²)
geom_jitter fonksiyonunun kullanım amacı
nedir?data("Boston")
names(Boston)
## [1] "crim" "zn" "indus" "chas" "nox" "rm" "age"
## [8] "dis" "rad" "tax" "ptratio" "black" "lstat" "medv"
Boston_tr <- Boston %>%
dplyr::select(medv, rm, lstat, chas, tax)
Boston_tr <- Boston_tr %>%
rename(konut_degeri = medv,
oda_sayisi = rm,
dusuk_sosyoek = lstat,
nehir_kenari = chas,
emlak_vergisi = tax)
names(Boston_tr)
## [1] "konut_degeri" "oda_sayisi" "dusuk_sosyoek" "nehir_kenari"
## [5] "emlak_vergisi"
summary(Boston_tr)
## konut_degeri oda_sayisi dusuk_sosyoek nehir_kenari
## Min. : 5.00 Min. :3.561 Min. : 1.73 Min. :0.00000
## 1st Qu.:17.02 1st Qu.:5.886 1st Qu.: 6.95 1st Qu.:0.00000
## Median :21.20 Median :6.208 Median :11.36 Median :0.00000
## Mean :22.53 Mean :6.285 Mean :12.65 Mean :0.06917
## 3rd Qu.:25.00 3rd Qu.:6.623 3rd Qu.:16.95 3rd Qu.:0.00000
## Max. :50.00 Max. :8.780 Max. :37.97 Max. :1.00000
## emlak_vergisi
## Min. :187.0
## 1st Qu.:279.0
## Median :330.0
## Mean :408.2
## 3rd Qu.:666.0
## Max. :711.0
### konut_degerinin ortalam değeri 22.53, medyan değeri 21.20 ranj ise max-min değer olduğu için 50-5=45tir.
table(Boston_tr$chas)
## < table of extent 0 >
prop.table(table(Boston_tr$chas*100))
## numeric(0)
ggplot(
data = Boston_tr,
aes(x = oda_sayisi, y= konut_degeri)
) +
geom_point() +
labs(
x = "Oda Sayısı" ,
y = "Konut Değeri",
title= "Oda Sayısı ile Konut Değeri Arasında ki İlişki"
)
cor(
Boston_tr$konut_degeri,
Boston_tr$oda_sayisi,
use= "pairwise.complete.obs"
)
## [1] 0.6953599
###bu korelasyon değeri orta güvenirlirliktedir.
Boston_tr<- Boston_tr |>
select(konut_degeri, oda_sayisi)|>
na.omit()
Boston_tr <- lm (konut_degeri ~ oda_sayisi, data = Boston_tr)
summary(Boston_tr)
##
## Call:
## lm(formula = konut_degeri ~ oda_sayisi, data = Boston_tr)
##
## Residuals:
## Min 1Q Median 3Q Max
## -23.346 -2.547 0.090 2.986 39.433
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -34.671 2.650 -13.08 <2e-16 ***
## oda_sayisi 9.102 0.419 21.72 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 6.616 on 504 degrees of freedom
## Multiple R-squared: 0.4835, Adjusted R-squared: 0.4825
## F-statistic: 471.8 on 1 and 504 DF, p-value: < 2.2e-16
###eğimi eğer konut dğeri artarsa odas sayısıda %9 artış gösterir.
###kesişim kesişişmdeki 3 yıldız güçlü ve anlamlı bi ilişki oldugunu gösterir
###r: bu modelin başarısı konut derğerinde ki değişkenliğin sadece %48ini oda sayısına bakarak açıklayabiliriz.
ggplot(Boston_tr, aes (x= oda_sayisi, y=konut_degeri)) +
geom_point() +
geom_smooth(method= "lm", se = FALSE, color= "red") +
labs (x="Oda Sayısı",
y = "Konut Değeri",
title = "Oda Sayısı ile Konut Sayısını Gösteren Tablo")
## Warning: `fortify(<lm>)` was deprecated in ggplot2 3.6.0.
## ℹ Please use `broom::augment(<lm>)` instead.
## ℹ The deprecated feature was likely used in the ggplot2 package.
## Please report the issue at <https://github.com/tidyverse/ggplot2/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
###geom_jitter fonksiyonu üst üste binen noktaları aşağı ve yukarı kaydırır.