If you collaborated with anyone, you must include “Collaborated with: FIRSTNAME LASTNAME” at the top of your lab!

Part 1. t-test (10 points)

Write a function my_t.test() that performs a one sample t-test in R. Your code should not use the t.test function in it.

Your function should have the following parameters:

Your function should return a list with elements:

You should use the following information:

(Hint: Be careful about whether you use lower.tail = TRUE or lower.tail = FALSE in the two-sided test! One safe option is to use lower.tail = FALSE with the absolute value (abs()) of your test statistic.)

To prove it works, load the data below (description at https://www.openintro.org/data/index.php?data=helium). THe air column represents the distance traveled by an air-filled ball whereas the helium column is the same for a helium-filled ball. Use this data for a two-sided t-test to test the hypothesis that the population mean of helium is different than 20 using both my_t.test() and t.test(). The results should match. Do the same for a one-sided t-test testing that the population mean of helium is greater than 20.

helium_data <- read.csv("https://www.openintro.org/data/csv/helium.csv")

Part 2. Linear model (10 points)

Write a function my_lm() that fits a linear model in R.

Your function should have the following parameters:

Your function should return a table similar to the coefficent table from summary() with rows for each coefficient (including the (Intercept)!) and columns for the Estimate, Std. Error, t value, and Pr(>|t|). There should be row and column names.

You may find the following information helpful:

(Hint: As before, be careful about whether you use lower.tail = TRUE or lower.tail = FALSE! One safe option is to use lower.tail = FALSE with the absolute value (abs()) of your test statistic. Make sure you never end up with a p-value greater than 1!)

To prove it works, Use the code below to read in data from a survey of 55 Duke University students about their study habits and grades. You can read more about this data at https://www.openintro.org/data/index.php?data=gpa.

grades_data <- read.csv("https://www.openintro.org/data/csv/gpa.csv")

Use this data to regress gpa upon studyweek using both my_lm() and lm(). The results of my_lm() should match the coefficient table from the summary of your lm() output.