使用R计算敏感性指数

0h4hbjxa  于 2022-12-05  发布在  其他
关注(0)|答案(1)|浏览(161)

I am currently working on a class project where I am supposed to analyze some results in few select papers. I want to calculate the sensitivity indices of the parameters with respect to the basic reproduction number (R0) using the formula S(p)=(p/R0)*(∂R0/∂p) where p is a parameter and S(p) is the sensitivity index of p. I have already calculated the indices manually, but I was wondering if there is a way to automate this process using R. The formula for R0 and the parameter values are given below.

beta_s = 0.274,
alpha_a = 0.4775,
alpha_u = 0.695,
mu = 0.062,
q_i = 0.078,
gamma_a = 0.29,
1/eta_i = 0.009,
1/eta_u = 0.05

R0 = (beta_s*alpha_a)/(gamma_a+mu) + (beta_s*alpha_u*gamma_a*(1-q_i))/((gamma_a+mu)*(eta_u+mu))

It would be great if someone could help me with finding the sensitivity indices using R. Thanks a lot for your time!
Edited code based on @epsilonG's answer

beta_s = 0.274
alpha_a = 0.4775
alpha_u = 0.695
mu = 0.062
q_i = 0.078
gamma_a = 0.29
1/eta_i = 0.009
1/eta_u = 0.05

R0 = (beta_s*alpha_a)/(gamma_a+mu) + (beta_s*alpha_u*gamma_a*(1-q_i))/((gamma_a+mu)*(eta_u+mu))

# Create function
func <- expression((beta_s*alpha_a)/(gamma_a+mu) + (beta_s*alpha_u*gamma_a*(1-q_i))/((gamma_a+mu)*(eta_u+mu))

# Calculate the derivative of R0 to alpha_a

dalpha_a <- deriv(func, 'alpha_a')
val <- eval(dalpha_a)

# Calculate the sensitivity index of alpha_a

S_alpha_a <- (alpha_a/R0)*val
xwbd5t1u

xwbd5t1u1#

# Create function
func <- expression((beta_s*alpha_a)/(gamma_a+mu) + 
        (beta_s*alpha_u*gamma_a*(1-q_i))/((gamma_a+mu)))

# Calculate the derivative of R0 to beta_s
dbeta_s <- deriv(func , 'beta_s')
val <- eval(dbeta_s)

# Calculate the sensitivity index of beta_s
s_beta_s <- beta_s/R0 * val

您可以使用for循环通过所有参数来执行此操作。

相关问题