1. Learn
  2. /
  3. Courses
  4. /
  5. Parallel Programming in R

Connected

Exercise

Catch modeling errors

Life expectancy at birth is a major indicator of population health.

You work as a consultant public health researcher. Your client would like to know the increase in life expectancy for each dollar spent on healthcare. You have sourced data for the life expectancy (in years) for all countries and their corresponding healthcare expenditure per capita, from 2001 to 2021. The consulting statistician has written code to fit regression models to each country's data. However, there are missing values in the data which cause errors in model fitting.

You have a list of data frames in your workspace, ls_df, where each element is the data for a given country. You plan to parallelize with parLapply() and use tryCatch() to catch errors. The parallel package has been loaded for you.

Instructions

100 XP
  • Supply a function to the error argument. This function should take one argument, e, and use paste() to put the string "Error!" before e.
  • Edit fit_lm() to check if model is a character string containing the error message.
  • Make a cluster with six cores.
  • Apply fit_lm() to the list ls_df in parallel using parLapply().