Advertisement
Guest User

Untitled

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