0

I have a data set of 144 scenarios and would like to calculate the percent change of all possible combinations using the comb n function. I have tried to use a percent difference function within the combn but it keeps giving me a large amount of NA's. Is there a way that I can accomplish this?

create percent change function:

pcchange=function(x,lag=1)
c(diff(x,lag),rep(NA,lag))/x*100

use withing combn:

Catch_comp<-combn(catch_table$av_muC, 2, pcchange)

convert results into a matrix

inputs <- headers 
out2 <- Catch_comp
class(out2) <- "dist"
attr(out2, "Labels") <- as.character(inputs)
attr(out2, "Size") <- length(inputs)
out2 <- as.matrix(out2)
out2

This is what my table is coming out looking like:

> out2
             F_R1S2_11   F_R1S2_12   F_R1S2_13   F_R1S2_21   F_R1S2_22    F_R1S2_23   F_R1S2_31      0.00000000  -0.8328001          NA  -2.1972852          NA  -0.11300746          NA  -1.15112915          NA  -2.7011787          NA  -0.5359923          NA
F_R1S2_12  -0.83280008   0.0000000          NA  -1.4558031          NA  

As an example: I have the average of 1000 simulations of the actual catch for two scenarios-

F_R1S1_11=155420.36

and

F_R1S1_12= 154126.0215.

Using the pcchange function I would like to calculate:

((F_R1S1_11-F_R1S1_12)/F_R1S1_11)*100 or ((155420.36-154126.02)/155420.36)*100=0.83% change in the values.

I would like to do this for all possible combinations in a 144x144 matrix form. I hope that helps.

Thanks!

  • What are you attempting to calculate with `pcchange`? If you are passed two values `x1` and `x2`, what should the result be? It's is unclear because you haven't provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (no sample data) and you have not clearly defined the desired output. – MrFlick Aug 04 '14 at 17:23
  • @MrFlick, Ok so as an example I have the average of 1000 simulations of the actual catch for two scenarios- F_R1S1_11=155420.36 and F_R1S1_12= 154126.0215. Using the pcchange function I would like to calculate ((F_R1S1_11-F_R1S1_12)/F_R1S1_11)*100 or ((155420.36-154126.02)/155420.36)*100=0.83% change in the values. I would like to do this for all possible combinations (I have 144 of these scenarios) in a matrix form. I hope that helps, sorry for the poor explanation before. – user3907231 Aug 05 '14 at 13:22
  • It's better to edit your original question to include the information. It can be rather difficult to read long expressions in comments. – MrFlick Aug 05 '14 at 18:04

0 Answers0