-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAssignment7.R
More file actions
29 lines (23 loc) · 846 Bytes
/
Assignment7.R
File metadata and controls
29 lines (23 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Import data
data <- read_excel("/Users/preeti/Downloads/cohort.xlsx")
View(data)
#descriptive table of variables
install.packages("Hmisc")
describe(data)
summary(data)
#linear regression model:
#effect of cardiac events (predictor) on cost of care (outcome)
#control for smoking status, age and gender
model <- lm(cost~cardiac+smoke+age+female, data=data)
summary(model)
#create regression figure
install.packages("coefplot")
install.packages("ggplot2")
# Scatter plot with regression line
ggplot(data, aes(x = age, y = cost)) +
geom_point(aes(color = cardiac), alpha = 0.6) + # Plot points with color indicating cardiac events
geom_smooth(method = "lm", se = FALSE, color = "blue") + # Add regression line
labs(title = "Scatter Plot of Cost vs. Age with Regression Line",
x = "Age",
y = "Cost") +
theme_minimal()