Probability and Statistics: Exercises


6. Independence. The function rnorm(n,mean,sd) generates n draws from a normal distribution. Generate 1000 observations from a normal distribution with mean 0 and standard deviation 1 twice. Using cor(), compute the correlation between the two sets of draws. After that, construct a scatterplot with the two sets of draws.


# Draw 1000 observations from a normal distribution. draws_1 <- ___(___, ___, 1) # Draw 1000 observations from a normal distribution. draws_2 <- ___ # Compute correlation. correlation <- ___(draws_1, draws_2) # Create scatterplot of draws_1 and draws_2. plot(draws_1, ___) # Draw 1000 observations from a normal distribution. draws_1 <- rnorm(1000, 0, 1) # Draw 1000 observations from a normal distribution. draws_2 <- rnorm(1000, 0, 1) # Compute correlation. correlation <- cor(draws_1, draws_2) # Create scatterplot of draws_1 and draws_2. plot(draws_1, draws_2) test_error() test_object("draws_1", incorrect_msg="Did you enter the correct arguments to `rnorm()`?") test_object("draws_2", incorrect_msg="Did you enter the correct arguments to `rnorm()`?") test_object("correlation", incorrect_msg="Did you enter the correct arguments to `cor()`?") success_msg("Good job! Based on your findings, do the draws appear to be independent?")
Did you use the rnorm() function?

Previous Exercise Next Exercise