10

import numpy as np

import pandas as pd

# Define the regression model coefficients

intercept = 2.5

beta_age = -0.03

beta_condition = 0.5

# Create a DataFrame for two patients: one with and one without a chronic condition

data = pd.DataFrame({

'Age': [60, 60],

'Condition': [1, 0]  # 1 = has chronic condition, 0 = does not

})

# Calculate log(λ) using the model

data['log_lambda'] = intercept + beta_age * data['Age'] + beta_condition * data['Condition']

# Exponentiate to get λ (expected number of visits)

data['lambda'] = np.exp(data['log_lambda'])

# Calculate the percentage increase due to chronic condition

increase_pct = ((data.loc[0, 'lambda'] - data.loc[1, 'lambda']) / data.loc[1, 'lambda']) * 100

# Display results

print(data[['Age', 'Condition', 'lambda']])

print(f"\nIncrease in expected visits due to chronic condition: {increase_pct:.2f}%")


Comments

Popular posts from this blog

6