Get startedGet started for free

Evaluating BMI outcomes

What is the difference in the predicted disease progression (the response, y) for patients who are in the top 10% of BMI compared to the lowest 10% of BMI? You'll use the results of a simulation sampling the multivariate normal distribution to answer this question!

The simulation has already been performed for you: your task is to evaluate the simulation results in df_results.

The following libraries have been imported for you: pandas as pd, numpy as np, and scipy.stats as st.

This exercise is part of the course

Monte Carlo Simulations in Python

View Course

Exercise instructions

  • Use np.quantile() to calculate the 10th and 90th quantile of bmi in the simulated results, saving as bmi_q10 and bmi_q90.
  • Use bmi_q10 and bmi_q90 to filter df_summary and obtain predicted y values.

Hands-on interactive exercise

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

simulation_results = st.multivariate_normal.rvs(mean=mean_dia, size=20000, cov=cov_dia)
df_results = pd.DataFrame(simulation_results,columns=["age", "bmi", "bp", "tc", "ldl", "hdl", "tch", "ltg", "glu"])
predicted_y = regr_model.predict(df_results)
df_y = pd.DataFrame(predicted_y, columns=["predicted_y"])
df_summary = pd.concat([df_results,df_y], axis=1)

# Calculate the 10th and 90th quantile of bmi in the simulated results
bmi_q10 = np.quantile(df_summary["bmi"], ____)
bmi_q90 = np.quantile(df_summary["bmi"], ____)

# Use bmi_q10 and bmi_q90 to filter df_summary and obtain predicted y values
mean_bmi_q90_outcome = np.mean(df_summary[____]["predicted_y"]) 
mean_bmi_q10_outcome = np.mean(df_summary[____]["predicted_y"])
y_diff = mean_bmi_q90_outcome - mean_bmi_q10_outcome
print(y_diff)
Edit and Run Code