We have a function. t ~ Weibull(alpha, lambda) and c ~ Exponential(beta):
Given p = 0.10, alpha = 1, lambda = 4. Find the value of beta.
We want to integrate this function for t then to c. Then find the value of beta where integral equals to p using uniroot function.
See the code below:
alpha = 1
lambda = 4
p = 0.10
func1 <- function(t, c, beta) {alpha * lambda * exp(-lambda * t^ alpha)*
                           beta * exp(- beta * c) }
func2 <- function(c, beta){integrate(func1, lower = c, upper = Inf, c=c, 
beta=beta)}
func3 <- function(beta){integrate(func2, lower = 0, upper = Inf, beta = 
beta)$value - cen.p}
uniroot(func3 ,lower = 0.001, upper = 10, extendInt = "yes")$root
However it throws the error:
Error in integrate(func1, lower = c, upper = Inf, c = c, beta = beta) : length(lower) == 1 not TRUE
Answer should be  0.444

                        
I corrected typos (substituted
cen.ptop) and vectorized function arguments forfunc2andfunc3, since theintegratefunction returns one value (scalar). However as a first argumentintegrateshould accept vector of numeric values, not a scalar.Output: