Probability and Statistics: Exercises


7. Validating a Probability Density Function. One of the properties of a probability density function (pdf) is that its values must be non-negative over its entire support. Let's validate this property for a given function.

Consider the function \( f = \frac{x}{60} \) over the interval [0, 10]. In this exercise, you will check if the values of this function are non-negative over its support using R.

To evaluate a function over a sequence of numbers, you can use the sapply() function in R, which applies a function to each element of a list or vector. Also, use the min() function to check the minimum value of the sequence.

Note: We are only checking whether the function is negative at the integers between 0 and 10; however, it is, of couse, also possible that it is negative between integer values.


# Define the function f <- function(x) { return(x/60) } # Evaluate the function over the interval [0, 10]. values <- sapply(___ : ___, f) # Check if all values are non-negative. min_value <- min(___) # Print minimum value min_value # Define the function f <- function(x) { return(x/60) } # Evaluate the function over the interval [0, 10]. values <- sapply(0:10, f) # Check if all values are non-negative. min_value <- min(values) # Print minimum value min_value test_error() test_object("values", incorrect_msg="Make sure to evaluate the function over the correct interval.") test_object("min_value", incorrect_msg="Check the minimum value of the sequence.") success_msg("Good job! Based on your findings, does the function satisfy the non-negativity property of a pdf?")
Make sure to use the provided function `f` over the interval [0, 10] using `sapply()`.

Previous Exercise Next Exercise