library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(palmerpenguins)
##
## Attaching package: 'palmerpenguins'
## The following objects are masked from 'package:datasets':
##
## penguins, penguins_raw
library(broom)
data(penguins)
names(penguins)
## [1] "species" "island" "bill_length_mm"
## [4] "bill_depth_mm" "flipper_length_mm" "body_mass_g"
## [7] "sex" "year"
glimpse(penguins)
## Rows: 344
## Columns: 8
## $ species <fct> Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…
## $ island <fct> Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…
## $ bill_length_mm <dbl> 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …
## $ bill_depth_mm <dbl> 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …
## $ flipper_length_mm <int> 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…
## $ body_mass_g <int> 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …
## $ sex <fct> male, female, female, NA, female, male, female, male…
## $ year <int> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…
penguins_tr <- penguins %>%
rename(
tür=species,
ada=island,
gaga_uzunluk=bill_length_mm,
gaga_derinlik=bill_depth_mm,
yuzgec_uzunluk=flipper_length_mm,
kilo=body_mass_g,
cinsiyet=sex,
yil=year
)
penguins_tr <- penguins_tr|>
select(kilo, yuzgec_uzunluk)
na.omit
## function (object, ...)
## UseMethod("na.omit")
## <bytecode: 0x13e6ab508>
## <environment: namespace:stats>
ggplot(penguins_tr, aes(x = yuzgec_uzunluk, y= kilo))+
geom_point() +
labs(x = "yüzgeç uzunluğu (mm)",
y = "vücut ağırlığı(gram)",
title = "yüzgeç uzunluğu ile vücut ağırlığı ilişkisi" )
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

peng_mod<-lm(kilo ~ yuzgec_uzunluk, data = penguins_tr)
summary(peng_mod)
##
## Call:
## lm(formula = kilo ~ yuzgec_uzunluk, data = penguins_tr)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1058.80 -259.27 -26.88 247.33 1288.69
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -5780.831 305.815 -18.90 <2e-16 ***
## yuzgec_uzunluk 49.686 1.518 32.72 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 394.3 on 340 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.759, Adjusted R-squared: 0.7583
## F-statistic: 1071 on 1 and 340 DF, p-value: < 2.2e-16
coef(peng_mod)
## (Intercept) yuzgec_uzunluk
## -5780.83136 49.68557
ggplot(penguins_tr, aes(x = yuzgec_uzunluk, y = kilo )) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(x = "yüzgeç uzunluğu (mm)",
y = "vücut ağırlığı (gram)",
title = "basit doğrusal regresyon çizgisi")
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 2 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 2 rows containing missing values or values outside the scale range
## (`geom_point()`).

new_peng <- data.frame(yuzgec_uzunluk = 200)
predict(peng_mod, newdata = new_peng)
## 1
## 4156.282