pif.sensitivity: Potential Impact Fraction Sensitivity Analysis plot

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/pif_sensitivity.R

Description

Function that plots a sensitivity analysis for the Potential Impact Fraction pif by checking how estimates vary when reducing the exposure's sample X.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pif.sensitivity(X, thetahat, rr, cft = NA, method = "empirical",
  weights = rep(1/nrow(as.matrix(X)), nrow(as.matrix(X))), nsim = 50,
  mremove = min(nrow(as.matrix(X))/2, 100), adjust = 1, n = 512,
  ktype = "gaussian", bw = "SJ", ylab = "PIF",
  xlab = "Number of randomly deleted observations for X",
  legendtitle = "Sensitivity Analysis",
  title = "Potential Impact Fraction (PIF) Sensitivity Analysis",
  colors = c("red", "deepskyblue", "gray75", "gray25"),
  check_exposure = TRUE, check_rr = TRUE, check_integrals = TRUE,
  is_paf = FALSE)

Arguments

X

Random sample (data.frame) which includes exposure and covariates or sample mean if "approximate" method is selected.

thetahat

Asymptotically consistent or Fisher consistent estimator (vector) of theta for the Relative Risk function.

rr

function for Relative Risk which uses parameter theta. The order of the parameters should be rr(X, theta).

**Optional**

cft

function cft(X) for counterfactual. Leave empty for the Population Attributable Fraction paf where counterfactual is that of a theoretical minimum risk exposure X0 such that rr(X0,theta) = 1.

method

Either "empirical" (default), "kernel" or "approximate". For details on estimation methods see pif.

weights

Normalized survey weights for the sample X.

nsim

Integer with number of samples to include (for each removal) in order to conduct sensitivity analysis. See details for additional information.

mremove

Limit number of measurements of X to remove when resampling. See details for additional information.

adjust

Adjust bandwith parameter (for "kernel" method) from density.

n

Number of equally spaced points at which the density (for "kernel" method) is to be estimated (see density).

ktype

kernel type: "gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine" (for "kernel" method). Additional information on kernels in density.

bw

Smoothing bandwith parameter (for "kernel" method) from density. Default "SJ".

ylab

string label for the Y-axis of the plot.

xlab

string label for the X-axis of the plot.

legendtitle

string title for the legend of plot.

title

string title of plot.

colors

string vector with colours for plots.

check_exposure

boolean Check that exposure X is positive and numeric.

check_rr

boolean Check that Relative Risk function rr equals 1 when evaluated at 0.

check_integrals

boolean Check that counterfactual cft and relative risk's rr expected values are well defined for this scenario.

is_paf

Boolean forcing evaluation of paf. This forces the pif function ignore the inputed counterfactual and set it to the theoretical minimum risk value of 1.

Details

pif.sensitivity conducts a sensitivity analysis of the pif estimate by removing mremove elements nsim times and re-estimating pif with the reduced sample.

Value

plotpif ggplot object plotting a sensitivity analysis of pif.

Author(s)

Rodrigo Zepeda-Tello [email protected]

Dalia Camacho-Garc<c3><ad>a-Forment<c3><ad> [email protected]

See Also

See pif for Potential Impact Fraction estimation, pif.heatmap for sensitivity analysis of counterfactual, pif.plot for a plot of Potential Impact Fraction as a function of the relative risk's parameter theta.

Examples

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
## Not run: 
#Example 1
#------------------------------------------------------------------
set.seed(3284)
X  <- data.frame(Exposure = rnorm(250,3)) #Sample
rr <- function(X,theta){exp(X*theta)}     #Relative risk
theta <- 0.1                              #Estimate of theta

pif.sensitivity(X, thetahat = theta, rr = rr)


#Save file
#require(ggplot2)
#ggsave("My Potential Impact Fraction Sensitivity Analysis.pdf")

#Example 2
#--------------------------------------------------------------
set.seed(3284)
X     <- data.frame(Exposure = rbeta(1000, 1, 0.2))
theta <- c(0.12, 1)
rr    <- function(X, theta){X*theta[1] + theta[2]}
cft   <- function(X){X/2}


#Using empirical method
pif.sensitivity(X, thetahat = theta, rr = rr, cft = cft,
                mremove = 100, nsim = 50, 
                title = "My Sensitivity Analysis for example 1")
                
#Same example with kernel
pif.sensitivity(X, theta, rr = rr, cft = cft,
                 mremove = 100, nsim = 50, method = "kernel", 
                 title = "Sensitivity Analysis for example 1 using kernel")
                 

#Example 3: Plot counterfactual with categorical risks
#------------------------------------------------------------------
set.seed(18427)
X        <- data.frame(Exposure = 
               sample(c("Normal","Overweight","Obese"), 1000, 
                      replace = TRUE, prob = c(0.4, 0.1, 0.5)))
thetahat <- c(1, 1.7, 2)

#Categorical relative risk function
rr <- function(X, theta){

   #Create return vector with default risk of 1
   r_risk <- rep(1, length(X))
   
   #Assign categorical relative risk
   r_risk[which(X == "Normal")]      <- thetahat[1]
   r_risk[which(X == "Overweight")]  <- thetahat[2]
   r_risk[which(X == "Obese")]       <- thetahat[3]
   
   return(r_risk)
}


#Counterfactual of halving the percent of obesity and overweight cases
#to normality
cft <- function(X){

   #Find the overweight and obese individuals
   which_obese <- which(X == "Obese")
   which_over  <- which(X == "Overweight")
   
   #Reduce per.over % of overweight and per.obese % of obese
   X[sample(which_obese, floor(length(which_obese)*0.5)),1] <- "Normal"
   X[sample(which_over,  floor(length(which_over)*0.5)),1]  <- "Normal"
   
   return(X)
}


pifplot <- pif.sensitivity(X, thetahat = thetahat, rr = rr, cft = cft, 
                           title = "Sensitivity analysis of PIF for excess-weight",
                           colors = rainbow(4), 
                           legendtitle = "Values", 
                           check_exposure = FALSE, check_rr = FALSE)              
pifplot              

#You can edit pifplot as it is a ggplot object
#require(ggplot2)
#pifplot + theme_classic()

## End(Not run)

pifpaf documentation built on Sept. 29, 2017, 1:03 a.m.