You are on page 1of 3

Antlion - BS2460

JJ’s Angels

2024-03-14
library(tidyverse)

## Warning: package 'tidyverse' was built under R version 4.3.3

## Warning: package 'tidyr' was built under R version 4.3.3

## Warning: package 'purrr' was built under R version 4.3.3

## Warning: package 'forcats' was built under R version 4.3.3

## Warning: package 'lubridate' was built under R version 4.3.3

## ── Attaching core tidyverse packages ──────────────────────── tidyverse


2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── 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(janitor)

## Warning: package 'janitor' was built under R version 4.3.3

##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test

antlion <- read_csv("C:/Users/Admin/Downloads/BS2460/Week 5/class antlion


data.csv")

## Rows: 158 Columns: 4


## ── Column specification
────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (4): distance to neighbour, diameter pit 1, diamter pit 2, mean
diameter
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this
message.

antlion<-antlion%>%
janitor::clean_names()
View(antlion)
str(antlion)

## spc_tbl_ [158 × 4] (S3: spec_tbl_df/tbl_df/tbl/data.frame)


## $ distance_to_neighbour: num [1:158] 239 239 239 239 238 238 238 212 45
45 ...
## $ diameter_pit_1 : num [1:158] 29 29 66 29 36 59 36 36 45 45 ...
## $ diamter_pit_2 : num [1:158] 66 66 29 66 59 36 59 59 50 50 ...
## $ mean_diameter : num [1:158] 47.5 47.5 47.5 47.5 47.5 47.5 47.5
47.5 47.5 47.5 ...
## - attr(*, "spec")=
## .. cols(
## .. `distance to neighbour` = col_double(),
## .. `diameter pit 1` = col_double(),
## .. `diamter pit 2` = col_double(),
## .. `mean diameter` = col_double()
## .. )
## - attr(*, "problems")=<externalptr>

names(antlion)

## [1] "distance_to_neighbour" "diameter_pit_1" "diamter_pit_2"

## [4] "mean_diameter"

library(ggplot2)

ggplot(antlion, aes(x = distance_to_neighbour, y = mean_diameter)) +


geom_point() + # add points
geom_smooth(method = "lm", se = TRUE, level = 0.95) + # add linear
regression line with confidence intervals
labs(x = "Distance to neighbor (mm)", y = "Mean diameter (mm)")+
theme_classic()

## `geom_smooth()` using formula = 'y ~ x'


model1<-lm(mean_diameter~distance_to_neighbour, data=antlion)
summary(model1)

##
## Call:
## lm(formula = mean_diameter ~ distance_to_neighbour, data = antlion)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.2460 -7.9612 -0.3502 7.8173 22.4017
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 22.753390 1.194501 19.048 < 2e-16 ***
## distance_to_neighbour 0.052110 0.008195 6.359 2.14e-09 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 9.887 on 156 degrees of freedom
## Multiple R-squared: 0.2058, Adjusted R-squared: 0.2007
## F-statistic: 40.43 on 1 and 156 DF, p-value: 2.141e-09

#Estimate of the intercept = 22.753390


#Estimate of the slope = 0.052110
# Variability = 20.07%
# p-value = 2.141e-09 (Relationship is significant as p-value is < 0.05)

You might also like