Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- df <- data.frame(ch = rep(1:10, each = 12), # care home id
- month_id = rep(1:12, times = 10), # month using the system over the course of a year (1 = first month, 2 = second month...etc.)
- totaladministrations = rbinom(n=1440, size = 1000, prob = 0.6), # administrations that were scheduled to have been given in the month
- missed = rbinom(n=1440, size = 20, prob = 0.8), # administrations that weren't given in the month (these are bad!)
- beds = rep(rbinom(n = 10, size = 60, prob = 0.6), each = 12), # number of beds in the care home
- rating = rep(rbinom(n= 10, size = 4, prob = 0.5), each = 12)) # latest inspection rating (1. Inadequate, 2. Requires Improving, 3. Good, 4 Outstanding)
- # Summary measures
- df$missed_pct <- df$missed / df$totaladministrations * 100 # missed meds as a percentage of all scheduled administrations
- df$missed_dm <- df$missed / 30.416 # missed meds daily mean for the month
- # classifications
- df$ch_size <- car::recode(df$beds, "lo:29 = 1; 30:36 = 2; 37:hi = 3", as.factor = TRUE)
- str(df)
- > str(df)
- 'data.frame': 1440 obs. of 9 variables:
- $ ch : int 1 1 1 1 1 1 1 1 1 1 ...
- $ month_id : int 1 2 3 4 5 6 7 8 9 10 ...
- $ totaladministrations: int 572 614 603 598 588 591 599 576 596 611 ...
- $ missed : int 16 18 17 17 18 17 15 14 19 16 ...
- $ beds : int 38 38 38 38 38 38 38 38 38 38 ...
- $ rating : Factor w/ 5 levels "0","1","2","3",..: 1 1 1 1 1 1 1 1 1 1 ...
- $ ch_size : Factor w/ 2 levels "2","3": 2 2 2 2 2 2 2 2 2 2 ...
- $ missed_pct : num 2.8 2.93 2.82 2.84 3.06 ...
- $ missed_dm : num 0.526 0.592 0.559 0.559 0.592 ...
- lm_mm_pct_mo_3mth <- lm(missed_pct ~ month_id, data = df)
- > lm_mm_pct_mo_3mth
- Call:
- lm(formula = MissedMeds_PCT ~ month_id, data = facs_3mth)
- Coefficients:
- (Intercept) month_id
- 2.63581 -0.01126
- > summary(lm_mm_pct_mo_3mth$residuals)
- Min. 1st Qu. Median Mean 3rd Qu. Max.
- -2.5811 -1.9563 -0.7864 0.0000 0.9766 8.3717
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement