module09

Author

Rachael Berghahn

##setting up heights of actors
aragorn = rnorm(50, mean=180, sd=10) ##data for aragorn actors heights
gimli = rnorm(50, mean=132, sd=15) ##data for gimli actors heights
legolas = rnorm(50, 195, 15) ##data for legolas actors heights
 ##t-tests
t.test(legolas, aragorn, alternative="two.sided") ##p value is less then 0.05 at 95% confidence meaning there is substanial difference between heights of legolas and aragorn actors

    Welch Two Sample t-test

data:  legolas and aragorn
t = 6.0019, df = 97.902, p-value = 3.301e-08
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  8.561653 17.020028
sample estimates:
mean of x mean of y 
 194.3599  181.5691 
t.test(legolas, gimli, alternative="two.sided") ##very tiny p value (smaller than 0.05 at 95% confidence) allows null hypothesis to be rejected, meaning there is substanial difference between heights of legolas and gimli actors

    Welch Two Sample t-test

data:  legolas and gimli
t = 25.408, df = 95.335, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 55.55795 64.97554
sample estimates:
mean of x mean of y 
 194.3599  134.0932 
 ##variance tests
var.test(legolas,gimli) ##p-value is very high (0.897) putting it way above 0.05, meaning we have failed to reject null hypothesis meanign there is no significant difference between variance in legolas and gimli

    F test to compare two variances

data:  legolas and gimli
F = 0.7135, num df = 49, denom df = 49, p-value = 0.2409
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
 0.4048953 1.2573249
sample estimates:
ratio of variances 
         0.7135019 
 ##corelation tests for iris dataset
iris <- read.csv("iris.csv")
cor(iris$Sepal.Length[iris$Species == "setosa"],
    iris$Sepal.Width[iris$Species == "setosa"]) ##being the correlation is close to 1, it shows sepal length and width are correlated for setosa
[1] 0.7425467
cor(iris$Sepal.Length[iris$Species == "versicolor"], 
    iris$Sepal.Width[iris$Species == "versicolor"]) ##being the correlation is between 0 and one, it shows that sepal length and width are correlated somtimes for versicolor
[1] 0.5259107
cor(iris$Sepal.Length[iris$Species == "virginica"],
    iris$Sepal.Width[iris$Species == "virginica"]) ##being the correlation is closer to 0 than one, it shows that the sepal length and width are not strongly correlated for virginica
[1] 0.4572278
##chi-squared tests for deer dataset
deer <- read.csv("Deer.csv")
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)) ##as the p value is signficantly less then 0.05 it shows at 95% confidence there is a signficant difference in the number of deer caught per month

    Chi-squared test for given probabilities

data:  table(deer$Month)
X-squared = 997.07, df = 11, p-value < 2.2e-16
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)) ##as the p value is significantly less than 0.05 it shows at 95% confidence there is a signficant difference in the number of deer with tb for farm, meaning it is not evenly distributed
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

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).