Module 9

Author

K M

Module 9

reading in csv files and packages

library(knitr)
Warning: package 'knitr' was built under R version 4.5.2
library(tidyverse)
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'dplyr' was built under R version 4.5.2
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.2
✔ ggplot2   4.0.3     ✔ 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
iris<-read.csv("~/Desktop/GEOG 5680/Data/iris.csv")
deer<-read.csv("~/Desktop/GEOG 5680/Data/Deer.csv")

t-tests

aragorn = rnorm(50,180,10)
gimli = rnorm(50,132,15)
legolas = rnorm(50,195,15)

t.test(legolas, aragorn)

    Welch Two Sample t-test

data:  legolas and aragorn
t = 5.3392, df = 96.809, p-value = 6.164e-07
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  8.504662 18.568920
sample estimates:
mean of x mean of y 
 194.0094  180.4726 

yes, significant difference, p < 0.001

t.test(legolas, gimli)

    Welch Two Sample t-test

data:  legolas and gimli
t = 21.869, df = 97.771, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 54.47172 65.34436
sample estimates:
mean of x mean of y 
 194.0094  134.1014 

yes, even more significant, p < 0.001


F-test

var.test(gimli, legolas)

    F test to compare two variances

data:  gimli and legolas
F = 1.1016, num df = 49, denom df = 49, p-value = 0.7361
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.6251579 1.9413081
sample estimates:
ratio of variances 
          1.101646 

no significant difference in variation, p > 0.05


Correlation Tests

setosa = subset(iris, Species == "setosa")
versi = subset(iris, Species == "versicolor")
virg = subset(iris, Species == "virginica")

cor.test(setosa$Sepal.Length, setosa$Sepal.Width)

    Pearson's product-moment correlation

data:  setosa$Sepal.Length and setosa$Sepal.Width
t = 7.6807, df = 48, p-value = 6.71e-10
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.5851391 0.8460314
sample estimates:
      cor 
0.7425467 

strong positive correlation, r = 0.74

cor.test(versi$Sepal.Length, versi$Sepal.Width)

    Pearson's product-moment correlation

data:  versi$Sepal.Length and versi$Sepal.Width
t = 4.2839, df = 48, p-value = 8.772e-05
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.2900175 0.7015599
sample estimates:
      cor 
0.5259107 

moderate positive correlation, r = 0.53

cor.test(virg$Sepal.Length, virg$Sepal.Width)

    Pearson's product-moment correlation

data:  virg$Sepal.Length and virg$Sepal.Width
t = 3.5619, df = 48, p-value = 0.0008435
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.2049657 0.6525292
sample estimates:
      cor 
0.4572278 

moderate positive correlation, r = 0.46


chi-squared tests

table(deer$Month)

  1   2   3   4   5   6   7   8   9  10  11  12 
256 165  27   3   2  35  11  19  58 168 189 188 
chisq.test(table(deer$Month))

    Chi-squared test for given probabilities

data:  table(deer$Month)
X-squared = 997.07, df = 11, p-value < 2.2e-16

yes, significant difference in the number of deers caught per month (p < 0.001)

table(deer$Farm, deer$Tb)
      
         0   1
  AL    10   3
  AU    23   0
  BA    67   5
  BE     7   0
  CB    88   3
  CRC    4   0
  HB    22   1
  LCV    0   1
  LN    28   6
  MAN   27  24
  MB    16   5
  MO   186  31
  NC    24   4
  NV    18   1
  PA    11   0
  PN    39   0
  QM    67   7
  RF    23   1
  RN    21   0
  RO    31   0
  SAL    0   1
  SAU    3   0
  SE    16  10
  TI     9   0
  TN    16   2
  VISO  13   1
  VY    15   4
chisq.test(table(deer$Farm, deer$Tb))
Warning in chisq.test(table(deer$Farm, deer$Tb)): Chi-squared approximation may
be incorrect

    Pearson's Chi-squared test

data:  table(deer$Farm, deer$Tb)
X-squared = 129.09, df = 26, p-value = 1.243e-15

the distribution is not uniform (p < 0.001)