Diff of /R/plcom2012.R [000000] .. [fb0f7e]

Switch to unified view

a b/R/plcom2012.R
1
#' PLCOm2012 risk prediction model for lung cancer
2
#'
3
#' @param age a vector of patient's age
4
#' @param race categorical variable of patient's race or ethnic group (White, Black, Hispanic,
5
#' Asian, American Indian, Alaskan Native, Native Hawaiian, Pacific Islander)
6
#' @param education education was measured in six ordinal levels: less than high-school graduate (level 1),
7
#' high-school graduate (level 2), some training after high school (level 3), some college (level 4),
8
#' college graduate (level 5), and postgraduate or professional degree (level 6)
9
#' @param bmi a vector of patient's body mass index, per 1 unit of increase
10
#' @param copd binary variable of chronic obstructive pulmonary disease (yes as 1 or no as 0)
11
#' @param cancer_hist binary variable of patient's cancer history (yes as 1 or no as 0)
12
#' @param family_hist_lung_cancer binary variable of patient's family history of lung cancer (yes as 1 or no as 0)
13
#' @param smoking_status binary variable of patient's smoking status (current as 1 or former as 0)
14
#' @param smoking_intensity a vector of the number cigarettes patient smokes per day
15
#' @param duration_smoking a vector of patient's duration of smoking, per 1-yr increase
16
#' @param smoking_quit_time a vector of patient's smoking quit time, per 1-yr increase
17
#'
18
#' @return prob patient's 6-year probability of lung-cancer
19
#' @export
20
#'
21
#' @examples
22
#'plcom2012(age=62, race='White', education=4, bmi=27, copd=0, cancer_hist=0,
23
#'family_hist_lung_cancer=0, smoking_status=0, smoking_intensity=80,
24
#'duration_smoking=27, smoking_quit_time=10)
25
26
plcom2012 <- function(age, race, education, bmi, copd, cancer_hist, family_hist_lung_cancer, smoking_status, smoking_intensity, duration_smoking,
27
                      smoking_quit_time) {
28
  
29
  race <- tolower(race)
30
31
  if (race == "white" | race == "american indian" | race == "alaskan native" | race == 1) {
32
    model <- 0.0778868 * (age - 62) - 0.0812744 * (education - 4) - 0.0274194 * (bmi - 27) + 0.3553063 * copd + 0.4589971 * cancer_hist +
33
      0.587185 * family_hist_lung_cancer + 0.2597431 * smoking_status - 1.822606 * ((smoking_intensity/10)^(-1) - 0.4021541613) + 0.0317321 *
34
      (duration_smoking - 27) - 0.0308572 * (smoking_quit_time - 10) - 4.532506
35
  }
36
37
  if (race == "black" | race == 2) {
38
    model <- 0.0778868 * (age - 62) - 0.0812744 * (education - 4) - 0.0274194 * (bmi - 27) + 0.3553063 * copd + 0.4589971 * cancer_hist +
39
      0.587185 * family_hist_lung_cancer + 0.2597431 * smoking_status - 1.822606 * ((smoking_intensity/10)^(-1) - 0.4021541613) + 0.0317321 *
40
      (duration_smoking - 27) - 0.0308572 * (smoking_quit_time - 10) - 4.532506 + 0.3944778
41
  }
42
43
  if (race == "hispanic" | race == 3) {
44
    model <- 0.0778868 * (age - 62) - 0.0812744 * (education - 4) - 0.0274194 * (bmi - 27) + 0.3553063 * copd + 0.4589971 * cancer_hist +
45
      0.587185 * family_hist_lung_cancer + 0.2597431 * smoking_status - 1.822606 * ((smoking_intensity/10)^(-1) - 0.4021541613) + 0.0317321 *
46
      (duration_smoking - 27) - 0.0308572 * (smoking_quit_time - 10) - 4.532506 - 0.7434744
47
  }
48
49
  if (race == "asian" | race == 4) {
50
    model <- 0.0778868 * (age - 62) - 0.0812744 * (education - 4) - 0.0274194 * (bmi - 27) + 0.3553063 * copd + 0.4589971 * cancer_hist +
51
      0.587185 * family_hist_lung_cancer + 0.2597431 * smoking_status - 1.822606 * ((smoking_intensity/10)^(-1) - 0.4021541613) + 0.0317321 *
52
      (duration_smoking - 27) - 0.0308572 * (smoking_quit_time - 10) - 4.532506 - 0.466585
53
  }
54
55
  if (race == "native hawaiian" | race == "pacific islander" | race == 5) {
56
    model <- 0.0778868 * (age - 62) - 0.0812744 * (education - 4) - 0.0274194 * (bmi - 27) + 0.3553063 * copd + 0.4589971 * cancer_hist +
57
      0.587185 * family_hist_lung_cancer + 0.2597431 * smoking_status - 1.822606 * ((smoking_intensity/10)^(-1) - 0.4021541613) + 0.0317321 *
58
      (duration_smoking - 27) - 0.0308572 * (smoking_quit_time - 10) - 4.532506 + 1.027152
59
  }
60
61
  prob <- exp(model)/(1 + exp(model))
62
  results <- list()
63
  results$prob <- prob
64
  return(results)
65
    
66
}