Programming sensitivity analysis in parameter R: Vary 1 (column), hold other constants. The best way?

I want to check the sensitivity of the calculation for a value of 4 parameters. For this, I want to change one parameter at a time, i.e. Change variable 1, hold variables 2-4 at the default value (for example, 1). I thought that a simple way to organize these values ​​would be in data.frame (), where each column corresponds to a different variable, and each row to a set of parameters for which the calculation should be performed. Then I scrolled through each row of the data frame, evaluating the function given by the parameter values ​​in that row.

It seems like it should be simple, but I cannot find a quick way to do this.

The problem may be my general approach to sensitivity analysis programming, but I cannot come up with a good and easy way to program the above data.frame.

My code for generating data.frame:

Adj_vals <- c(seq(0, 1, by=0.1), seq(1.1, 2, by=0.1)) #a series of values for 3 of the parameters to use A_Adj_vals <- 10^(seq(1,14,0.5)) #a series of values for another one of the parameters to use n1 <- length(Adj_vals) n2 <- length(A_Adj_vals) data.frame( "Dg_Adj"=c(Adj_vals, rep(1, n1*2+n2)), #this parameter default is 1 "Df_Adj"=c(rep(1, n1), Adj_vals, rep(1, n1+n2)), #this parameter default is 1 "sd_Adj"=c(rep(1, n1*2), 0.01, Adj_vals[-1], rep(1, n2)), #This parameter has default of 1, but unlike the others using Adj_vals, it can only take on values >0 "A"=c(rep(1E7, n1*3), A_Adj_vals) #this parameter default is 10 million ) 

This code creates the desired data file. Is there an easier way to achieve the same result? I would accept the answer, where sd_Adj takes 0 instead of 0.01 .

+4
source share
1 answer

It's pretty debatable if it's better, but another way to do this would be to follow this pattern:

 defaults<-data.frame(a=1,b=1,c=1,d=10000000) merge(defaults[c("b","c","d")],data.frame(a=c(seq(0, 1, by=0.1), seq(1.1, 2, by=0.1)))) 

This should be pretty easy to compile into a function that automatically removes the correct column from the default values ​​based on the column name in the data frame that you combine with etc.

0
source

Source: https://habr.com/ru/post/1480989/


All Articles