R Markdown

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
data("penguins")
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,
    yüzgec_uzunluk=flipper_length_mm,
    kilo=body_mass_g,
    cinsiyet=sex,
    yıl=year
  )
names(penguins_tr)
## [1] "tür"            "ada"            "gaga_uzunluk"   "gaga_derinlik" 
## [5] "yüzgec_uzunluk" "kilo"           "cinsiyet"       "yıl"
penguins_tr<-penguins_tr |>
  select(kilo,yüzgec_uzunluk)|>
  na.omit()
ggplot(penguins_tr,aes(x=yüzgec_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ığı İlişkisi")

peng_mod <- lm(kilo ~ yüzgec_uzunluk,data = penguins_tr)
summary(peng_mod)
## 
## Call:
## lm(formula = kilo ~ yüzgec_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 ***
## yüzgec_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
## 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) yüzgec_uzunluk 
##    -5780.83136       49.68557
ggplot(penguins_tr,aes(x=yüzgec_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'

## 'geom_smooth()' using formula ='y ~ x'
new_peng <-data.frame(yüzgec_uzunluk=200)
predict(peng_mod,newdata = new_peng)
##        1 
## 4156.282