Working with R-output (2)

In thinking about the scientific research question, if IQ is caused only by genetics, then we would expect the slope of the line between the two sets of twins to be 1. Testing the hypothesized slope value of 1 can be done by making a new test statistic which evaluates how far the observed slope is from the hypothesized value of 1.

$$new_t = \frac{slope - 1}{SE}$$

If the hypothesis that the slope equals one is true, then the new test statistic will have a t-distribution which we can use for calculating a p-value.

The biological term from the model is available as biological_term.

This exercise is part of the course

Inference for Linear Regression in R

View Course

Exercise instructions

  • Calculate the degrees of freedom of the twins dataset.
  • Calculate the two-sided p-value for the alternative hypothesis that the true slope is different than 1. Build up the calculation in stages.
    • Calculate the test statistic as the slope estimate minus 1, all divided by the standard error.
    • Calculate the one-sided p-value of the test statistic using the cumulative distribution function of the t-distribution, pt(), at the test_statistic, with the degrees of freedom you just calculated.
    • Calculate the two-sided p-value as double the one-sided p-value.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Calculate the degrees of freedom of twins
degrees_of_freedom <- nrow(twins) - 2

biological_term %>%
  mutate(
    # Calculate the test statistic
    test_statistic = ___,
    # Calculate its one-sided p-value
    one_sided_p_value_of_test_statistic = ___,
    # ... and its two-sided p-value
    two_sided_p_value_of_test_statistic = ___
  )