risk.ratio.confidence: Confidence intervals for the Risk Ratio Integral

Description Usage Arguments Note Author(s) References See Also Examples

View source: R/risk_ratio_confidence.R

Description

Function that calculates confidence interval for the integral

\int RR(x;θ)f(x)dx

where f(x) is the density function of the exposure X, RR(x;θ) the relative risk of the exposure with associated parameter θ.

Usage

1
2
3
risk.ratio.confidence(X, thetahat, rr, thetavar,
  weights = rep(1/nrow(as.matrix(X)), nrow(as.matrix(X))), nsim = 1000,
  confidence = 95, check_thetas = TRUE, force.min = FALSE)

Arguments

X

Random sample (data.frame) which includes exposure and covariates.

thetahat

Estimator (vector) of theta for the Relative Risk function.

rr

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

**Optional**

thetavar

Estimator of variance of thetahat

weights

Normalized survey weights for the sample X.

nsim

Number of simulations.

confidence

Confidence level % (default: 95).

check_thetas

Checks that theta parameters are correctly inputed.

force.min

Boolean indicating whether to force the rr to have a minimum value of 1 instead of 0 (not recommended).

Note

The force.min option forces the relative risk rr to have a minimum of 1 and thus an rr < 1 is NOT possible. This is only for when absolute certainty is had that rr > 1 and should be used under careful consideration. The confidence interval to acheive such an rr is based on the paper by Do Le Minh and Y. .s. Sherif

Author(s)

Rodrigo Zepeda-Tello [email protected]

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

References

Sherif, Y. .s. (1989). The lower confidence limit for the mean of positive random variables. Microelectronics Reliability, 29(2), 151-152.

See Also

risk.ratio.approximate.confidence for a method when only mean(X) and var(X) are known.

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
87
88
89
90
91
92
93
94
## Not run: 
#Example 1: Exponential Relative Risk
#--------------------------------------------
set.seed(18427)
X        <- data.frame(rnorm(100))
thetahat <- 0.1
thetavar <- 0.2
rr       <- function(X, theta){exp(theta*X)}
risk.ratio.confidence(X, thetahat, rr, thetavar)

#We can force RR'.s CI to be >= 1.
#This should be done with extra methodological (philosophical) care as 
#RR>= 1 should only be assumed with absolute mathematical certainty
risk.ratio.confidence(X, thetahat, rr, thetavar, force.min = TRUE)


#Example 2: Multivariate Relative Risk
#--------------------------------------------
set.seed(18427)
X1        <- rnorm(1000)
X2        <- runif(1000)
X         <- data.frame(cbind(X1,X2))
thetahat  <- c(0.02, 0.01)
thetavar  <- matrix(c(0.1, 0, 0, 0.4), byrow = TRUE, nrow = 2)
rr        <- function(X, theta){exp(theta[1]*X[,1] + theta[2]*X[,2])}
risk.ratio.confidence(X, thetahat, rr, thetavar) 

#Example 3: Categorical Relative Risk & Exposure
#--------------------------------------------
set.seed(18427)
X        <- as.data.frame(sample(c("Normal","Overweight","Obese"), 100, 
                   replace = TRUE, prob = c(0.4, 0.1, 0.5)))
thetahat <- c(1, 1.2, 1.5)
thetavar  <- diag(c(0.1, 0.2, 0.4))

#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)
}

risk.ratio.confidence(data.frame(X), thetahat, rr, thetavar)

#Example 4: Categorical Relative Risk & continuous exposure
#----------------------------------------------------------
set.seed(18427)
BMI      <- data.frame(rlnorm(100, 3.1, sdlog = 0.1))
thetahat <- c(Malnourished = 2.2, Normal = 1, Overweight = 1.8, Obese = 2.5)
thetavar <- diag(c(0.5, 0.1, 0.1, 0.2))
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 < 20)]                             <- theta[1] #Malnourished
     r_risk[intersect(which(X >= 20), which(X < 25))]  <- theta[2] #Normal
     r_risk[intersect(which(X >= 25), which(X < 30))]  <- theta[3] #Overweight
     r_risk[which(X >= 30)]                            <- theta[4] #Obese
   
   return(r_risk)
}

risk.ratio.confidence(BMI, thetahat, rr, thetavar)

#Example 5: Bivariate exposure and rr ("classical rr")
#------------------------------------------------------------------
set.seed(18427)
X        <- sample(c("Exposed","Unexposed"), 1000, replace = TRUE, prob = c(0.1, 0.9))
thetahat <- c("Exposed" = 2.5, "Unexposed" = 1.2)  
thetavar <- matrix(c(0.1, 0.2, 0.2, 0.4), ncol = 2)
rr <- function(X, theta){
   
   #Create relative risk function
   r_risk <- rep(1, length(X))
   
   #Assign values of relative risk
   r_risk[which(X == "Unexposed")] <- theta["Unexposed"]
   r_risk[which(X == "Exposed")]   <- theta["Exposed"]
   
   return(r_risk)
}    

risk.ratio.confidence(data.frame(X), thetahat, rr, thetavar)

## End(Not run)

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