Docsity

Ecology Research Report: Correlation using R studio, Assignments of Ecology and Environment

Partial preview of the text

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

Correlation & Regression

Tarika Arjune

Dr. Wei Fang

Ecology

November 26th, 2021

Section 1: Introduction (10 pts) Correlation is when two numerical variables are associated. The correlation coefficient is a quality that describes the strength and direction of an association between two numbers of variables measured on a sample of subjects or units. Correlation reflects the amount of scatter in a scatter plot of the two variables. Unlike linear regression, correlation fits no line to the data. The correlation coefficient measures the tendency of two numerical variables to change together along a line. Regression is the method used to predict values of one numerical variable from values of another. A line fitted to the data is the regression line and the line is used to predict the response variable based on the explanatory variable. Like correlation, linear regression measures aspects of the linear relation between two numerical variables. However, regression fits a line through the data to predict one variable from another and to measure how steeply one variable changes with changes in the other. It measures strength of association between two variables, reflecting the amount of scatter in the data. The learning objectives is to calculate a correlation coefficient and the coefficient of determination. Other learning outcomes include testing hypotheses about correlation, using the non-parametric Spearman’s correlation, estimating slopes of regressions, testing regression models, plotting regression lines and examining residual plots for deviations from the assumptions of linear regression.

b. Do the data require any transformation before analysis using linear regression? telomere_inheritance <- lm(offspring_telomere_length ~ father_telomere_length, data = telomere_inheritance) telomere_inheritance Call: lm(formula = offspring_telomere_length ~ father_telomere_length, data = telomere_inheritance) Coefficients: (Intercept) father_telomere_length 0.2252 0. c. Estimate an equation that predicts the offspring telomere length from its father’s. Is there evidence that the father’s telomere length predicts his offspring’s value? The regression equation is: y = 0.2134 + 0.9971*x with a p-value of 4.792e-05. Therefore, there is significant evidence to suggest that the father's telomere length predicts his offspring's value.

  1. Opfer and Segler (2007) asked second- and fourth-grade school children to mark on a number line where a given number would fall. Each child was given a drawing of a number line with two ends marked at 0 and 1000 and was then asked to make an X on that line where a number, for example 150, should be placed. They asked each child to place several different numbers on the number lines, each on a fresh new piece of paper. The researchers then measured the placement of each mark on a linear scale. The results, averaged over all 93 kids for each group, are given in the file “numberline.csv”. a. Plot the fourth graders’ guesses against the true value. Is this relationship linear? If not, find a transformation of X or Y that converts the relationship into an approximately linear one. library(readr) numberline <- read_csv("DataForLabs/numberline.csv") View(numberline) ggplot(numberline, aes(x=fourth_graders_guess, y=true_value)) + geom_point() + theme_minimal() + xlab("Fourth graders guess") + ylab("True value")

c. Assume that the difference between the shapes of these curves is real. What would you conclude about the difference in the way 2nd graders and 4th graders perceive numbers? In conclusion, the difference in the way 2nd^ graders and 4th^ graders perceive numbers at different magnitudes.

  1. Larger animals tend to have larger brains. But is the increase in brain size proportional to the increase in body size? A set of data on body and brain size of 62 mammal species was collated by Allison and Cicchetti (1976), and these data are in the data set “mammals.csv”. The file contains columns giving the species name, the average body mass (in kg) and average brain size (in g) for each species. These are the same data used in the second half of the app about residuals that you used in the activities earlier in this lab. a. Plot brain size against body size. Is the relationship linear? library(readr) mammals <- read_csv("DataForLabs/mammals.csv") View(mammals) ggplot(mammals, aes(x=brain_mass_g, y=body_mass_kg)) +

geom_point() + theme_minimal() + xlab("Brain mass g") + ylab("Body mass kg") b. Find a transformation (for either or both variables) that makes the relationship between these two variables linear. log_body<- log(mammals$body_mass_kg) log_brain<- log(mammals$brain_mass_g) c. Is there statistical evidence that brain size is correlated with body size? Assume that the species data are independent. library(readr) mammals <- read_csv("DataForLabs/mammals.csv") View(mammals) t.test(mammals$brain_mass_g, mammals$body_mass_kg) Welch Two Sample t-test

lm(formula = brain_mass_g ~ body_mass_kg, data = mammals) Coefficients: (Intercept) body_mass_kg 91.0045 0. Call: lm(formula = brain_mass_g ~ body_mass_kg, data = mammals) Residuals: Min 1Q Median 3Q Max -810.07 -88.52 -79.64 -13.02 2050. Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 91.00454 43.55257 2.09 0.0409 * body_mass_kg 0.96650 0.04766 20.28 <2e-16 ***


Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 334.7 on 60 degrees of freedom Multiple R-squared: 0.8727,Adjusted R-squared: 0. F-statistic: 411.2 on 1 and 60 DF, p-value: < 2.2e-

g. [ OPTIONAL – hint: try using filter() from the dplyr package.] Which species has the highest brain size relative to that predicted by its body size? Which species has the smallest brain relative to that predicted by its body size? Section 3: Feedbacks (bonus) a. What have you learned in this lab? (5 pts) In this lab we learnt about correlation and regression in a data set. We learnt how to use the cor() function to calculate the correlation coefficient as well as the linear regression. b. What do you enjoy the most? (5 pts) I enjoyed the most about this lesson was the discussions with my peers to further understand the topic and the demonstrations using R studio. The best part of this lab was understanding the relationship between the two variables and determining if the data had meaning. c. What do you find confusing and hard to understand? (5pts) In this lab, the most confusing thing for me to understand was analyzing the meaning of the data or the linear regression. It is confusing to understand if my data showed a relationship or not because for me, numbers are hard to understand and convert into words.