Docsity

Ecology Research Report: T-Test using R studio, Assignments of Ecology and Environment

Partial preview of the text

Download Ecology Research Report: T-Test using R studio and more Assignments Ecology and Environment in PDF only on Docsity!

Comparing the means of two groups (T-tests)

Tarika Arjune

Dr. Wei Fang

Ecology

October 8th, 2021

Section 1: Introduction (10 pts) Biological data often compares two groups or variables that we can produce viable conclusions from. Comparing means of a numerical variable between two treatments or groups can be achieved by using the t-distribution to calculate confidence intervals for mean differences and test the hypotheses about means. There are two sample designs which include a two-sample design or a paired design. The two-sample design is a random sampling in which you end up with two independent samples that is a result of one from each treatment. In the paired design, we take random sample of half the dataset and leave the other half of the dataset untouched. Each of the two experimental designs have their benefits and address the same question but they are different in the effects of how the data is analyzed. In the paired design, both treatments are applied to every sampled unit while in the two-sample design, each treatment group is composed of an independent, random sample of units. The paired design helps to minimize the impact of a lot of the extraneous variation between sampling units because it is easier to see a difference between two treatments if nearly everything is similar between the sampling units. The paired design reduces the effects of variation among sampling units that has nothing to do with the treatment. The paired t-test is used to test a null hypothesis that the mean difference of paired measurements equals a specified value. This tests differences when both treatments have been applied to every sampling unit and the data is paired. H0 is when the mean change in the variable being tested is zero while HA is when the mean change in the variable being tested is not zero. The HA is two tailed because it is either greater or less of the variable being measured would reject the null hypothesis. The paired t-test make the assumptions that the sampling units are randomly sampled from the population and the paired differences have a normal distribution in the population. The two-

b. Use t.test () to do a Welch’s t -test to look for a difference in mean body weight between the surviving and dying birds. t.test(weight_g~survival, data=bumpus.csv, var.equal=FALSE) Welch Two Sample t-test data: weight_g by survival t = 2.5161, df = 117.88, p-value = 0. alternative hypothesis: true difference in means between group died and group survived is not equal to 0 95 percent confidence interval: 0.1351376 1. sample estimates: mean in group died mean in group survived 25.86094 25. c. What is the 95% confidence interval for the difference in mean weight of surviving and dying birds? The 95% confidence interval for the difference in mean weight of surviving and dying birds is 0.13513761-1.1339597.

d. Use a Levene’s test to ask whether the surviving and dying birds had the same variance in weight. library(car) leveneTest(data=bumpus.csv,weight_g~survival, center=mean) Levene's Test for Homogeneity of Variance (center = mean) Df F value Pr(>F) group 1 0.7992 0. 134 Section 3: Question 2 (R scripts & graphs & answers to individual questions) (30pts)

  1. Let’s return to the data about ecological footprint in the data set “countries.csv”. As you remember, the ecological footprint of a country is a measure of the average amount of resources consumed by a person in that country (as measured by the amount of land required to produce those resources and to handle the average person’s waste). For many countries in the data set, information is available on the ecological footprint in the year 2000 as well as in
  2. Use a paired t -test to ask whether the ecological footprint has changed over that time period. a. Plot a histogram showing the difference in ecological footprint between 2012 and
    1. (Note, you will probably need to create a new vector containing the differences, and use hist() to make the graph.) read.csv("DataForLabs/countries.csv") countries.csv$CarbonDifference<-countries.csv$ecological_footprint_2012- countries.csv$ecological_footprint_ hist(countries.csv$CarbonDifference)

c. Interpret your result. Is there evidence that the ecological footprint changed over that time? If so, did it increase or decrease? There is evidence that the ecological footprint changed over that time which is the ecological footprint is increasing. Section 4: Question 3 (R scripts & graphs & answers to individual questions) (30pts)

  1. A common belief is that shaving causes hair to grow back faster or coarser than it was before. Is this true? Lynfield and McWilliams (1970) did a small experiment to test for an effect of shaving. Five men shaved one leg weekly for several months while leaving the other leg unshaved. (The data from the shaved leg has the word “test” in the variable name; the data from the unshaved leg is labeled with “control.”) At the end of the experiment, the researchers measured the difference in leg hair width and the hair growth rate on each of the legs. These data are given in “leg shaving.csv”. a. Perform a suitable hypothesis test to determine whether shaving affects hair thickness. library(ggplot2) leg_shaving.csv<-read.csv("DataForLabs/leg shaving.csv", stringsAsFactors = TRUE) t.test(leg_shaving.csv$hair_width_change_control, leg_shaving.csv$hair_width_change_test, paired = TRUE) Paired t-test data: leg_shaving.csv$hair_width_change_control and leg_shaving.csv$hair_width_change_test t = 1.905, df = 4, p-value = 0. alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -4.025854-21. sample estimates: mean of the differences

b. How big is the difference? Find the 95% confidence interval for the difference between shaved and unshaved legs for hair thickness. 95 percent confidence interval: -4.025854-21. Section 5: Feedbacks (bonus) a. What have you learned in this lab? (5 pts) In this lab, we learnt the purposes of the t-test, how to write the function for the t-test on RStudio and produce histograms that depict the data properly to determine distribution and variance from them. b. What do you enjoy the most? (5 pts) The part of this lab I enjoyed the most was getting more familiar with RStudio and understand much more of the basic programs such as finding the directory and reading the csv. Writing the codes for those functions on RStudio have become much easier to understand because of constant practice with them. I also enjoyed having my peers show me how to navigate how to perform the t-test function and understanding the 95% confidence interval as well as what that means in terms of the data. c. What do you find confusing and hard to understand? (5pts) During this lab, I was extremely confused about the t-test, and I kept getting an error when inputting the leg shaving data but that was due to spacing/ typing errors. I also was having an issue with understanding the distribution and variance of the histograms as well as trying to understand the question regarding the hypothesis test for hair thickness. d. What change/improvement would you like to see for the lab? (5 pts) The change/improvement that I would like to see in this lab is understanding more of the statistics side to this lab because it was very heavy content that I found to be a bit confusing for me. I think that what would help would be more visuals and scenario problems that we could practice on. I also think that it would be great if we could have collected our own data to work with and tried to use the t-test function for our own data as well as make graphs and determine what our data was showing us.