# Simulation - example usage

    library(powerHaDeX)

The package `powerHaDeX` is a tool for simulating and analyzing data coming from HDX-MS experiments along with the possibility of comparing the power of the tests verifying differences in deuteration levels. The functionality of the simulation involves generating a theoretical spectrum along with its replications, replicating the deuterium uptake curves obtained from spectra, and rejection rate estimation for comparison of the tests for differences in deuteration. Let us go through the process of simulation and all its features.

## Data simulation

### Theoretical spectra simulation

The first step of the simulation is the generation of theoretical spectra of a deuterated peptide over time. To do so, the function `simulate_theoretical_spectra` is used. There is the possibility of simulation a mass spectrum for more than one point of time and more than one charge by specifying the parameters `charge` and `times`. Providing vector of charges and/or vector of exposure times we obtain a `data table` of spectra consistent with assumed parameters.

For example, a single spectrum can be simulated as below

    set.seed(17)

    theo_spectrum <- simulate_theoretical_spectra(sequence = "CHERICHERILADY",
                                                  charge = 4,
                                                  protection_factor = 100,
                                                  times = 0.167,
                                                  pH = 7.5,
                                                  temperature = 15,
                                                  n_molecules = 500,
                                                  time_step_const = 1,
                                                  use_markov = TRUE)
    theo_spectrum
    #>     Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>  1:    0.000 7.5 0.3519156204 440.2107      4 CHERICHERILADY 100
    #>  2:    0.000 7.5 0.3231637738 440.2107      4 CHERICHERILADY 100
    #>  3:    0.000 7.5 0.1934355070 440.2107      4 CHERICHERILADY 100
    #>  4:    0.000 7.5 0.0868056117 440.2107      4 CHERICHERILADY 100
    #>  5:    0.000 7.5 0.0315957363 440.2107      4 CHERICHERILADY 100
    #>  6:    0.000 7.5 0.0097206744 440.2107      4 CHERICHERILADY 100
    #>  7:    0.000 7.5 0.0025936359 440.2107      4 CHERICHERILADY 100
    #>  8:    0.000 7.5 0.0006109695 440.2107      4 CHERICHERILADY 100
    #>  9:    0.000 7.5 0.0001288097 440.2107      4 CHERICHERILADY 100
    #> 10:    0.167 7.5 0.3209565658 440.2107      4 CHERICHERILADY 100
    #> 11:    0.167 7.5 0.3249997450 440.4623      4 CHERICHERILADY 100
    #> 12:    0.167 7.5 0.2049151762 440.7138      4 CHERICHERILADY 100
    #> 13:    0.167 7.5 0.0964513599 440.9654      4 CHERICHERILADY 100
    #> 14:    0.167 7.5 0.0366685527 441.2170      4 CHERICHERILADY 100
    #> 15:    0.167 7.5 0.0117564483 441.4686      4 CHERICHERILADY 100
    #> 16:    0.167 7.5 0.0032646623 441.7201      4 CHERICHERILADY 100
    #> 17:    0.167 7.5 0.0007997219 441.9717      4 CHERICHERILADY 100
    #> 18:    0.167 7.5 0.0001752103 442.2233      4 CHERICHERILADY 100

As we can see in the output - we obtain a spectrum for the given time of measurement 0.167 sec and control measurement measured directly after adding the buffer (conventionally at time equal to 0). Each row of the data is correspondent to a single peak in the spectrum. Such a result for a particular time can be visualized using `powerHaDeX` as shown below.

    plot_spectra(theo_spectrum)

We can also draw the measurement at the time 0 specifying `control_time = TRUE` as below.

    plot_spectra(theo_spectrum, control_time = TRUE)

As said before, more than one spectrum can be simulated for different exposure times and charges. Such a case is shown in the following code. We specify two values of charge (3 and 5) and time of measurements (0.167 and 5).

    set.seed(17)

    theo_spectra <- simulate_theoretical_spectra(sequence = "CHERICHERILADY",
                                                 charge = c(3, 5),
                                                 protection_factor = 100,
                                                 times = c(0.167, 5),
                                                 pH = 7.5,
                                                 temperature = 15,
                                                 n_molecules = 500,
                                                 time_step_const = 1,
                                                 use_markov = TRUE)

    head(theo_spectra)
    #>    Exposure  PH Intensity       Mz Charge       Sequence  PF
    #> 1:        0 7.5 0.3519156 586.6118      3 CHERICHERILADY 100
    #> 2:        0 7.5 0.3519156 352.3700      5 CHERICHERILADY 100
    #> 3:        0 7.5 0.3231638 586.6118      3 CHERICHERILADY 100
    #> 4:        0 7.5 0.3231638 352.3700      5 CHERICHERILADY 100
    #> 5:        0 7.5 0.1934355 586.6118      3 CHERICHERILADY 100
    #> 6:        0 7.5 0.1934355 352.3700      5 CHERICHERILADY 100

Such a result can be also displayed on the plot as shown below.

    plot_spectra(theo_spectra)

### Replicated spectra

#### one/all states

To generate replications of the experiment of hydrogen-deuterium exchange the function `add_noise_to_spectra` can be used. We need to evaluate `get_undeuterated_mass` and `get_spectra_list` first as in the code below. By setting `compare_pairs = FALSE` we do not pair the spectra by protection factors (in the case of our example we did not provide more than one value of protection factor yet).

    undeuterated_mass = get_undeuterated_mass(theo_spectra)
    spectra = get_spectra_list(theo_spectra)
    replicated_spectra = add_noise_to_spectra(spectra,
                                              undeuterated_mass = undeuterated_mass,
                                              n_experiments = 2)
    replicated_spectra
    #> [[1]]
    #> [[1]][[1]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.4957      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.4599      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.7029      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.2874      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.7346      3 CHERICHERILADY 100
    #>  ---
    #> 228:        5 7.5 0.0184176796 353.7023      5 CHERICHERILADY 100
    #> 229:        5 7.5 0.0062067650 353.7496      5 CHERICHERILADY 100
    #> 230:        5 7.5 0.0018599905 354.1177      5 CHERICHERILADY 100
    #> 231:        5 7.5 0.0004938085 354.2318      5 CHERICHERILADY 100
    #> 232:        5 7.5 0.0001104587 354.4601      5 CHERICHERILADY 100
    #>      Experimental_state Rep
    #>   1:          State_100   1
    #>   2:          State_100   1
    #>   3:          State_100   1
    #>   4:          State_100   1
    #>   5:          State_100   1
    #>  ---
    #> 228:          State_100   4
    #> 229:          State_100   4
    #> 230:          State_100   4
    #> 231:          State_100   4
    #> 232:          State_100   4
    #>
    #> [[1]][[2]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.5470      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.4298      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.6087      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.3265      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.5233      3 CHERICHERILADY 100
    #>  ---
    #> 228:        5 7.5 0.0184176796 353.5442      5 CHERICHERILADY 100
    #> 229:        5 7.5 0.0062067650 353.7953      5 CHERICHERILADY 100
    #> 230:        5 7.5 0.0018599905 353.9036      5 CHERICHERILADY 100
    #> 231:        5 7.5 0.0004938085 354.1517      5 CHERICHERILADY 100
    #> 232:        5 7.5 0.0001104587 354.3799      5 CHERICHERILADY 100
    #>      Experimental_state Rep
    #>   1:          State_100   1
    #>   2:          State_100   1
    #>   3:          State_100   1
    #>   4:          State_100   1
    #>   5:          State_100   1
    #>  ---
    #> 228:          State_100   4
    #> 229:          State_100   4
    #> 230:          State_100   4
    #> 231:          State_100   4
    #> 232:          State_100   4

The output of the function `add_noise_to_spectra` is adapted to the power calculations. Therefore, it is a list of two elements: the first one is correspondent to the pair of protection factors (in the case when `compare_pairs = FALSE` we consider all protection factors jointly) and the second is correspondent to the repetitions of the whole experiment (used for the needs of power calculations). By setting the number of experiments `n_experiments = 2` we simulate two experiments, that is (by default) 4 replicates of measurements for given time points, duplicated. The mentioned replicates are defined in the column `Rep`.

#### paired states

There is an option of generation noisy spectra such that they are prepared for the pairwise testing procedure (for paired states). To take a look at such an example, let us use `theo_spectra` generated previously for `protection factor = 100` and simulate theoretical spectra at state `protection factor = 200` using the function `simulate_theoretical_spectra`:

    theo_spectra_pf_100 <- theo_spectra
    theo_spectra_pf_200 <- simulate_theoretical_spectra(sequence = "CHERICHERILADY",
                                                        charge = c(3, 5),
                                                        protection_factor = 200,
                                                        times = c(0.167, 5),
                                                        pH = 7.5,
                                                        temperature = 15,
                                                        n_molecules = 500,
                                                        time_step_const = 1,
                                                        use_markov = TRUE)

    theo_spectra_two_states <- rbind(theo_spectra_pf_100, theo_spectra_pf_200)

A data table of spectra at different states (`theo_spectra_two_states` here) can be used as the argument in the functions responsible for adding noise. As explained before, we use the functions `get_undeuterated_mass` and `get_spectra_list` first. We specify the need for the data grouped pairwise in the function `get_spectra_list` by setting `compare_pairs = TRUE` and `reference = "all"` as below

    undeuterated_mass = get_undeuterated_mass(theo_spectra_two_states)
    spectra = get_spectra_list(theo_spectra_two_states,
                               compare_pairs = TRUE,
                               reference = "all")
    replicated_spectra_paired = add_noise_to_spectra(spectra,
                                                     undeuterated_mass = undeuterated_mass,
                                                     n_experiments = 2)
    replicated_spectra_paired
    #> [[1]]
    #> [[1]][[1]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.7370      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.4086      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.6778      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.3025      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.4973      3 CHERICHERILADY 100
    #>  ---
    #> 452:        5 7.5 0.0352195664 353.2925      5 CHERICHERILADY 200
    #> 453:        5 7.5 0.0124630617 353.4778      5 CHERICHERILADY 200
    #> 454:        5 7.5 0.0038328707 353.8688      5 CHERICHERILADY 200
    #> 455:        5 7.5 0.0010409430 354.1951      5 CHERICHERILADY 200
    #> 456:        5 7.5 0.0002418826 354.1752      5 CHERICHERILADY 200
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 452:                  B   4
    #> 453:                  B   4
    #> 454:                  B   4
    #> 455:                  B   4
    #> 456:                  B   4
    #>
    #> [[1]][[2]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.4083      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.4195      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.6470      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.4269      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.5192      3 CHERICHERILADY 100
    #>  ---
    #> 452:        5 7.5 0.0352195664 353.4370      5 CHERICHERILADY 200
    #> 453:        5 7.5 0.0124630617 353.4969      5 CHERICHERILADY 200
    #> 454:        5 7.5 0.0038328707 353.7006      5 CHERICHERILADY 200
    #> 455:        5 7.5 0.0010409430 354.0913      5 CHERICHERILADY 200
    #> 456:        5 7.5 0.0002418826 354.2725      5 CHERICHERILADY 200
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 452:                  B   4
    #> 453:                  B   4
    #> 454:                  B   4
    #> 455:                  B   4
    #> 456:                  B   4
    #>
    #>
    #> [[2]]
    #> [[2]][[1]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.7216      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.3303      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.5394      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.4421      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.6901      3 CHERICHERILADY 100
    #>  ---
    #> 460:        5 7.5 0.0184176796 353.7459      5 CHERICHERILADY 100
    #> 461:        5 7.5 0.0062067650 353.9221      5 CHERICHERILADY 100
    #> 462:        5 7.5 0.0018599905 354.0662      5 CHERICHERILADY 100
    #> 463:        5 7.5 0.0004938085 354.1538      5 CHERICHERILADY 100
    #> 464:        5 7.5 0.0001104587 354.4298      5 CHERICHERILADY 100
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 460:                  B   4
    #> 461:                  B   4
    #> 462:                  B   4
    #> 463:                  B   4
    #> 464:                  B   4
    #>
    #> [[2]][[2]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.5392      3 CHERICHERILADY 100
    #>   2:        0 7.5 0.3519156204 352.5052      5 CHERICHERILADY 100
    #>   3:        0 7.5 0.3231637738 586.5200      3 CHERICHERILADY 100
    #>   4:        0 7.5 0.3231637738 352.2501      5 CHERICHERILADY 100
    #>   5:        0 7.5 0.1934355070 586.5751      3 CHERICHERILADY 100
    #>  ---
    #> 460:        5 7.5 0.0184176796 353.5050      5 CHERICHERILADY 100
    #> 461:        5 7.5 0.0062067650 353.7317      5 CHERICHERILADY 100
    #> 462:        5 7.5 0.0018599905 353.9752      5 CHERICHERILADY 100
    #> 463:        5 7.5 0.0004938085 354.2930      5 CHERICHERILADY 100
    #> 464:        5 7.5 0.0001104587 354.4625      5 CHERICHERILADY 100
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 460:                  B   4
    #> 461:                  B   4
    #> 462:                  B   4
    #> 463:                  B   4
    #> 464:                  B   4
    #>
    #>
    #> [[3]]
    #> [[3]][[1]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.5642      3 CHERICHERILADY 200
    #>   2:        0 7.5 0.3519156204 352.2645      5 CHERICHERILADY 200
    #>   3:        0 7.5 0.3231637738 586.6306      3 CHERICHERILADY 200
    #>   4:        0 7.5 0.3231637738 352.4414      5 CHERICHERILADY 200
    #>   5:        0 7.5 0.1934355070 586.6002      3 CHERICHERILADY 200
    #>  ---
    #> 444:        5 7.5 0.0352195664 353.3482      5 CHERICHERILADY 200
    #> 445:        5 7.5 0.0124630617 353.4801      5 CHERICHERILADY 200
    #> 446:        5 7.5 0.0038328707 353.7377      5 CHERICHERILADY 200
    #> 447:        5 7.5 0.0010409430 354.0588      5 CHERICHERILADY 200
    #> 448:        5 7.5 0.0002418826 354.2376      5 CHERICHERILADY 200
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 444:                  B   4
    #> 445:                  B   4
    #> 446:                  B   4
    #> 447:                  B   4
    #> 448:                  B   4
    #>
    #> [[3]][[2]]
    #>      Exposure  PH    Intensity       Mz Charge       Sequence  PF
    #>   1:        0 7.5 0.3519156204 586.6821      3 CHERICHERILADY 200
    #>   2:        0 7.5 0.3519156204 352.5324      5 CHERICHERILADY 200
    #>   3:        0 7.5 0.3231637738 586.6122      3 CHERICHERILADY 200
    #>   4:        0 7.5 0.3231637738 352.3069      5 CHERICHERILADY 200
    #>   5:        0 7.5 0.1934355070 586.7892      3 CHERICHERILADY 200
    #>  ---
    #> 444:        5 7.5 0.0352195664 353.2613      5 CHERICHERILADY 200
    #> 445:        5 7.5 0.0124630617 353.5934      5 CHERICHERILADY 200
    #> 446:        5 7.5 0.0038328707 353.8038      5 CHERICHERILADY 200
    #> 447:        5 7.5 0.0010409430 353.9717      5 CHERICHERILADY 200
    #> 448:        5 7.5 0.0002418826 354.1598      5 CHERICHERILADY 200
    #>      Experimental_state Rep
    #>   1:                  A   1
    #>   2:                  A   1
    #>   3:                  A   1
    #>   4:                  A   1
    #>   5:                  A   1
    #>  ---
    #> 444:                  B   4
    #> 445:                  B   4
    #> 446:                  B   4
    #> 447:                  B   4
    #> 448:                  B   4

As we can see, we obtained the output adapted to the pairwise comparison - each element of a list is a list of data tables (according to the argument `n_experiments`) for paired states. In our example, we get three pairs: 100 vs. 200 for power estimation and 100 vs. 100, 200 vs, 200 for type I error estimation.

#### deuteration curves from spectra

Having noisy mass spectra simulated by the function `add_noise_to_spectra` as shown in the previous sections we can use the function `get_deuteration_curves_from_spectra` to calculate deuterium uptake as follows:

    deuteration_curves <- get_deuteration_curves_from_spectra(replicated_spectra)
    deuteration_curves
    #> [[1]]
    #> [[1]][[1]]
    #>     Exposure  PH Charge       Sequence  PF Experimental_state Rep     Mass
    #>  1:    0.000 7.5      3 CHERICHERILADY 100          State_100   1 1756.877
    #>  2:    0.000 7.5      5 CHERICHERILADY 100          State_100   1 1757.043
    #>  3:    0.000 7.5      3 CHERICHERILADY 100          State_100   2 1756.888
    #>  4:    0.000 7.5      5 CHERICHERILADY 100          State_100   2 1756.976
    #>  5:    0.000 7.5      3 CHERICHERILADY 100          State_100   3 1756.869
    #>  6:    0.000 7.5      5 CHERICHERILADY 100          State_100   3 1756.964
    #>  7:    0.000 7.5      3 CHERICHERILADY 100          State_100   4 1756.732
    #>  8:    0.000 7.5      5 CHERICHERILADY 100          State_100   4 1756.731
    #>  9:    0.167 7.5      3 CHERICHERILADY 100          State_100   1 1758.086
    #> 10:    0.167 7.5      5 CHERICHERILADY 100          State_100   1 1758.149
    #> 11:    0.167 7.5      3 CHERICHERILADY 100          State_100   2 1758.032
    #> 12:    0.167 7.5      5 CHERICHERILADY 100          State_100   2 1758.247
    #> 13:    0.167 7.5      3 CHERICHERILADY 100          State_100   3 1757.928
    #> 14:    0.167 7.5      5 CHERICHERILADY 100          State_100   3 1758.456
    #> 15:    0.167 7.5      3 CHERICHERILADY 100          State_100   4 1757.913
    #> 16:    0.167 7.5      5 CHERICHERILADY 100          State_100   4 1758.034
    #> 17:    5.000 7.5      3 CHERICHERILADY 100          State_100   1 1758.950
    #> 18:    5.000 7.5      5 CHERICHERILADY 100          State_100   1 1759.048
    #> 19:    5.000 7.5      3 CHERICHERILADY 100          State_100   2 1759.271
    #> 20:    5.000 7.5      5 CHERICHERILADY 100          State_100   2 1758.711
    #> 21:    5.000 7.5      3 CHERICHERILADY 100          State_100   3 1758.791
    #> 22:    5.000 7.5      5 CHERICHERILADY 100          State_100   3 1758.703
    #> 23:    5.000 7.5      3 CHERICHERILADY 100          State_100   4 1759.277
    #> 24:    5.000 7.5      5 CHERICHERILADY 100          State_100   4 1759.155
    #>     Exposure  PH Charge       Sequence  PF Experimental_state Rep     Mass
    #>
    #> [[1]][[2]]
    #>     Exposure  PH Charge       Sequence  PF Experimental_state Rep     Mass
    #>  1:    0.000 7.5      3 CHERICHERILADY 100          State_100   1 1756.698
    #>  2:    0.000 7.5      5 CHERICHERILADY 100          State_100   1 1756.690
    #>  3:    0.000 7.5      3 CHERICHERILADY 100          State_100   2 1756.934
    #>  4:    0.000 7.5      5 CHERICHERILADY 100          State_100   2 1756.727
    #>  5:    0.000 7.5      3 CHERICHERILADY 100          State_100   3 1756.560
    #>  6:    0.000 7.5      5 CHERICHERILADY 100          State_100   3 1757.230
    #>  7:    0.000 7.5      3 CHERICHERILADY 100          State_100   4 1756.910
    #>  8:    0.000 7.5      5 CHERICHERILADY 100          State_100   4 1756.577
    #>  9:    0.167 7.5      3 CHERICHERILADY 100          State_100   1 1757.889
    #> 10:    0.167 7.5      5 CHERICHERILADY 100          State_100   1 1758.118
    #> 11:    0.167 7.5      3 CHERICHERILADY 100          State_100   2 1758.136
    #> 12:    0.167 7.5      5 CHERICHERILADY 100          State_100   2 1758.097
    #> 13:    0.167 7.5      3 CHERICHERILADY 100          State_100   3 1757.922
    #> 14:    0.167 7.5      5 CHERICHERILADY 100          State_100   3 1758.285
    #> 15:    0.167 7.5      3 CHERICHERILADY 100          State_100   4 1757.953
    #> 16:    0.167 7.5      5 CHERICHERILADY 100          State_100   4 1758.229
    #> 17:    5.000 7.5      3 CHERICHERILADY 100          State_100   1 1758.956
    #> 18:    5.000 7.5      5 CHERICHERILADY 100          State_100   1 1758.982
    #> 19:    5.000 7.5      3 CHERICHERILADY 100          State_100   2 1759.049
    #> 20:    5.000 7.5      5 CHERICHERILADY 100          State_100   2 1758.665
    #> 21:    5.000 7.5      3 CHERICHERILADY 100          State_100   3 1759.001
    #> 22:    5.000 7.5      5 CHERICHERILADY 100          State_100   3 1759.295
    #> 23:    5.000 7.5      3 CHERICHERILADY 100          State_100   4 1758.946
    #> 24:    5.000 7.5      5 CHERICHERILADY 100          State_100   4 1758.728
    #>     Exposure  PH Charge       Sequence  PF Experimental_state Rep     Mass

As we can see, we obtain the output analogous to the output of `add_noise_to_spectra` but containing deuterium uptake curves instead of mass spectra.

## Noisy deuteration curves

We can also simulate noisy deuteration curves using the direct output of `simulate_theoretical_spectra`. As mentioned before, we specify the number of technical replicates and executions of the experiment using the arguments `n_replicates` and `n_experiments`. An example for the case when one/“all” states are considered is shown in the following code:

    get_noisy_deuteration_curves(theo_spectra,
                                 n_replicates = 4,
                                 n_experiments = 2,
                                 compare_pairs = FALSE)
    #> [[1]]
    #> [[1]][[1]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3          State_100
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5          State_100
    #>  3: CHERICHERILADY   1   100    0.167 1.0217790      3          State_100
    #>  4: CHERICHERILADY   1   100    0.167 1.1115481      5          State_100
    #>  5: CHERICHERILADY   1   100    5.000 2.2000449      3          State_100
    #>  6: CHERICHERILADY   1   100    5.000 2.4815535      5          State_100
    #>  7: CHERICHERILADY   2   100    0.000 0.0000000      3          State_100
    #>  8: CHERICHERILADY   2   100    0.000 0.0000000      5          State_100
    #>  9: CHERICHERILADY   2   100    0.167 0.9464547      3          State_100
    #> 10: CHERICHERILADY   2   100    0.167 0.8102006      5          State_100
    #> 11: CHERICHERILADY   2   100    5.000 2.1403363      3          State_100
    #> 12: CHERICHERILADY   2   100    5.000 1.8741435      5          State_100
    #> 13: CHERICHERILADY   3   100    0.000 0.0000000      3          State_100
    #> 14: CHERICHERILADY   3   100    0.000 0.0000000      5          State_100
    #> 15: CHERICHERILADY   3   100    0.167 1.0501886      3          State_100
    #> 16: CHERICHERILADY   3   100    0.167 1.5787876      5          State_100
    #> 17: CHERICHERILADY   3   100    5.000 2.0908309      3          State_100
    #> 18: CHERICHERILADY   3   100    5.000 2.1018103      5          State_100
    #> 19: CHERICHERILADY   4   100    0.000 0.0000000      3          State_100
    #> 20: CHERICHERILADY   4   100    0.000 0.0000000      5          State_100
    #> 21: CHERICHERILADY   4   100    0.167 1.4237105      3          State_100
    #> 22: CHERICHERILADY   4   100    0.167 0.8013307      5          State_100
    #> 23: CHERICHERILADY   4   100    5.000 2.0033885      3          State_100
    #> 24: CHERICHERILADY   4   100    5.000 2.5667487      5          State_100
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #> [[1]][[2]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3          State_100
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5          State_100
    #>  3: CHERICHERILADY   1   100    0.167 1.2843118      3          State_100
    #>  4: CHERICHERILADY   1   100    0.167 1.2523143      5          State_100
    #>  5: CHERICHERILADY   1   100    5.000 2.2997912      3          State_100
    #>  6: CHERICHERILADY   1   100    5.000 2.4740207      5          State_100
    #>  7: CHERICHERILADY   2   100    0.000 0.0000000      3          State_100
    #>  8: CHERICHERILADY   2   100    0.000 0.0000000      5          State_100
    #>  9: CHERICHERILADY   2   100    0.167 1.2818168      3          State_100
    #> 10: CHERICHERILADY   2   100    0.167 1.2974389      5          State_100
    #> 11: CHERICHERILADY   2   100    5.000 1.8699221      3          State_100
    #> 12: CHERICHERILADY   2   100    5.000 2.6689255      5          State_100
    #> 13: CHERICHERILADY   3   100    0.000 0.0000000      3          State_100
    #> 14: CHERICHERILADY   3   100    0.000 0.0000000      5          State_100
    #> 15: CHERICHERILADY   3   100    0.167 0.7400186      3          State_100
    #> 16: CHERICHERILADY   3   100    0.167 0.4871051      5          State_100
    #> 17: CHERICHERILADY   3   100    5.000 1.7770345      3          State_100
    #> 18: CHERICHERILADY   3   100    5.000 1.9142936      5          State_100
    #> 19: CHERICHERILADY   4   100    0.000 0.0000000      3          State_100
    #> 20: CHERICHERILADY   4   100    0.000 0.0000000      5          State_100
    #> 21: CHERICHERILADY   4   100    0.167 1.5793063      3          State_100
    #> 22: CHERICHERILADY   4   100    0.167 1.4803818      5          State_100
    #> 23: CHERICHERILADY   4   100    5.000 2.2572368      3          State_100
    #> 24: CHERICHERILADY   4   100    5.000 2.0599348      5          State_100
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state

The case when the pairwise comparisons are considered requires providing the data simulated for different protection factors. Let us take a look at the results for `theo_spectra_two_states` simulated in the previous section:

    deuteration_curves_paired_states <- get_noisy_deuteration_curves(theo_spectra_two_states,
                                                                     n_replicates = 4,
                                                                     n_experiments = 2,
                                                                     compare_pairs = TRUE,
                                                                     reference = "all")
    deuteration_curves_paired_states
    #> [[1]]
    #> [[1]][[1]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   100    0.167 1.5207689      3                  A
    #>  4: CHERICHERILADY   1   100    0.167 0.7352172      5                  A
    #>  5: CHERICHERILADY   1   100    5.000 2.1869179      3                  A
    #>  6: CHERICHERILADY   1   100    5.000 1.8464555      5                  A
    #>  7: CHERICHERILADY   1   200    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   200    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   200    0.167 1.2827260      3                  B
    #> 10: CHERICHERILADY   1   200    0.167 1.0469703      5                  B
    #> 11: CHERICHERILADY   1   200    5.000 1.7941624      3                  B
    #> 12: CHERICHERILADY   1   200    5.000 1.7559851      5                  B
    #> 13: CHERICHERILADY   2   100    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   100    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   100    0.167 1.0475764      3                  A
    #> 16: CHERICHERILADY   2   100    0.167 1.9204614      5                  A
    #> 17: CHERICHERILADY   2   100    5.000 1.9722249      3                  A
    #> 18: CHERICHERILADY   2   100    5.000 2.6312181      5                  A
    #> 19: CHERICHERILADY   2   200    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   200    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   200    0.167 1.4472922      3                  B
    #> 22: CHERICHERILADY   2   200    0.167 1.1995781      5                  B
    #> 23: CHERICHERILADY   2   200    5.000 1.9419813      3                  B
    #> 24: CHERICHERILADY   2   200    5.000 2.0305247      5                  B
    #> 25: CHERICHERILADY   3   100    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   100    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   100    0.167 1.0726453      3                  A
    #> 28: CHERICHERILADY   3   100    0.167 1.2602940      5                  A
    #> 29: CHERICHERILADY   3   100    5.000 2.3765079      3                  A
    #> 30: CHERICHERILADY   3   100    5.000 1.9773408      5                  A
    #> 31: CHERICHERILADY   3   200    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   200    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   200    0.167 1.0148760      3                  B
    #> 34: CHERICHERILADY   3   200    0.167 1.8425044      5                  B
    #> 35: CHERICHERILADY   3   200    5.000 1.8452257      3                  B
    #> 36: CHERICHERILADY   3   200    5.000 1.9145016      5                  B
    #> 37: CHERICHERILADY   4   100    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   100    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   100    0.167 1.4018812      3                  A
    #> 40: CHERICHERILADY   4   100    0.167 1.4990865      5                  A
    #> 41: CHERICHERILADY   4   100    5.000 2.1589545      3                  A
    #> 42: CHERICHERILADY   4   100    5.000 2.0232537      5                  A
    #> 43: CHERICHERILADY   4   200    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   200    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   200    0.167 0.9609064      3                  B
    #> 46: CHERICHERILADY   4   200    0.167 1.1868611      5                  B
    #> 47: CHERICHERILADY   4   200    5.000 1.8657509      3                  B
    #> 48: CHERICHERILADY   4   200    5.000 2.0116651      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #> [[1]][[2]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   100    0.167 1.6781217      3                  A
    #>  4: CHERICHERILADY   1   100    0.167 0.4808957      5                  A
    #>  5: CHERICHERILADY   1   100    5.000 2.6580429      3                  A
    #>  6: CHERICHERILADY   1   100    5.000 1.9883399      5                  A
    #>  7: CHERICHERILADY   1   200    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   200    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   200    0.167 1.3999345      3                  B
    #> 10: CHERICHERILADY   1   200    0.167 1.1900220      5                  B
    #> 11: CHERICHERILADY   1   200    5.000 2.1148292      3                  B
    #> 12: CHERICHERILADY   1   200    5.000 1.7987158      5                  B
    #> 13: CHERICHERILADY   2   100    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   100    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   100    0.167 1.3323371      3                  A
    #> 16: CHERICHERILADY   2   100    0.167 1.3423614      5                  A
    #> 17: CHERICHERILADY   2   100    5.000 2.4359630      3                  A
    #> 18: CHERICHERILADY   2   100    5.000 2.5127416      5                  A
    #> 19: CHERICHERILADY   2   200    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   200    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   200    0.167 1.1928251      3                  B
    #> 22: CHERICHERILADY   2   200    0.167 1.1177404      5                  B
    #> 23: CHERICHERILADY   2   200    5.000 1.9404736      3                  B
    #> 24: CHERICHERILADY   2   200    5.000 1.7554388      5                  B
    #> 25: CHERICHERILADY   3   100    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   100    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   100    0.167 1.1646453      3                  A
    #> 28: CHERICHERILADY   3   100    0.167 1.0842386      5                  A
    #> 29: CHERICHERILADY   3   100    5.000 2.0189018      3                  A
    #> 30: CHERICHERILADY   3   100    5.000 1.8269066      5                  A
    #> 31: CHERICHERILADY   3   200    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   200    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   200    0.167 1.0505442      3                  B
    #> 34: CHERICHERILADY   3   200    0.167 1.0031656      5                  B
    #> 35: CHERICHERILADY   3   200    5.000 1.9077371      3                  B
    #> 36: CHERICHERILADY   3   200    5.000 1.9325159      5                  B
    #> 37: CHERICHERILADY   4   100    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   100    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   100    0.167 1.1083388      3                  A
    #> 40: CHERICHERILADY   4   100    0.167 0.9574459      5                  A
    #> 41: CHERICHERILADY   4   100    5.000 1.7538790      3                  A
    #> 42: CHERICHERILADY   4   100    5.000 2.3883536      5                  A
    #> 43: CHERICHERILADY   4   200    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   200    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   200    0.167 1.1834793      3                  B
    #> 46: CHERICHERILADY   4   200    0.167 1.2435665      5                  B
    #> 47: CHERICHERILADY   4   200    5.000 2.0890209      3                  B
    #> 48: CHERICHERILADY   4   200    5.000 1.7799847      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #>
    #> [[2]]
    #> [[2]][[1]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   100    0.167 1.3770517      3                  A
    #>  4: CHERICHERILADY   1   100    0.167 1.0946753      5                  A
    #>  5: CHERICHERILADY   1   100    5.000 2.2676963      3                  A
    #>  6: CHERICHERILADY   1   100    5.000 2.1869644      5                  A
    #>  7: CHERICHERILADY   1   100    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   100    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   100    0.167 1.4280720      3                  B
    #> 10: CHERICHERILADY   1   100    0.167 0.6347083      5                  B
    #> 11: CHERICHERILADY   1   100    5.000 2.2459142      3                  B
    #> 12: CHERICHERILADY   1   100    5.000 1.7591879      5                  B
    #> 13: CHERICHERILADY   2   100    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   100    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   100    0.167 0.8076238      3                  A
    #> 16: CHERICHERILADY   2   100    0.167 0.4181348      5                  A
    #> 17: CHERICHERILADY   2   100    5.000 1.9222855      3                  A
    #> 18: CHERICHERILADY   2   100    5.000 2.0144909      5                  A
    #> 19: CHERICHERILADY   2   100    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   100    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   100    0.167 1.3234358      3                  B
    #> 22: CHERICHERILADY   2   100    0.167 1.0481475      5                  B
    #> 23: CHERICHERILADY   2   100    5.000 2.1908907      3                  B
    #> 24: CHERICHERILADY   2   100    5.000 2.3685638      5                  B
    #> 25: CHERICHERILADY   3   100    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   100    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   100    0.167 0.9039832      3                  A
    #> 28: CHERICHERILADY   3   100    0.167 1.0006418      5                  A
    #> 29: CHERICHERILADY   3   100    5.000 1.7835761      3                  A
    #> 30: CHERICHERILADY   3   100    5.000 1.7206495      5                  A
    #> 31: CHERICHERILADY   3   100    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   100    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   100    0.167 1.4370787      3                  B
    #> 34: CHERICHERILADY   3   100    0.167 0.9982968      5                  B
    #> 35: CHERICHERILADY   3   100    5.000 1.8583631      3                  B
    #> 36: CHERICHERILADY   3   100    5.000 2.1806191      5                  B
    #> 37: CHERICHERILADY   4   100    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   100    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   100    0.167 1.4723786      3                  A
    #> 40: CHERICHERILADY   4   100    0.167 0.9099599      5                  A
    #> 41: CHERICHERILADY   4   100    5.000 2.2107337      3                  A
    #> 42: CHERICHERILADY   4   100    5.000 1.6726933      5                  A
    #> 43: CHERICHERILADY   4   100    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   100    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   100    0.167 1.5922112      3                  B
    #> 46: CHERICHERILADY   4   100    0.167 1.0559666      5                  B
    #> 47: CHERICHERILADY   4   100    5.000 2.8185554      3                  B
    #> 48: CHERICHERILADY   4   100    5.000 2.2032581      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #> [[2]][[2]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   100    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   100    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   100    0.167 1.1539172      3                  A
    #>  4: CHERICHERILADY   1   100    0.167 1.5709964      5                  A
    #>  5: CHERICHERILADY   1   100    5.000 2.1800052      3                  A
    #>  6: CHERICHERILADY   1   100    5.000 2.8243194      5                  A
    #>  7: CHERICHERILADY   1   100    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   100    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   100    0.167 1.1454261      3                  B
    #> 10: CHERICHERILADY   1   100    0.167 0.9793045      5                  B
    #> 11: CHERICHERILADY   1   100    5.000 2.2666683      3                  B
    #> 12: CHERICHERILADY   1   100    5.000 2.3877039      5                  B
    #> 13: CHERICHERILADY   2   100    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   100    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   100    0.167 1.3112611      3                  A
    #> 16: CHERICHERILADY   2   100    0.167 1.4761010      5                  A
    #> 17: CHERICHERILADY   2   100    5.000 2.3261447      3                  A
    #> 18: CHERICHERILADY   2   100    5.000 2.5973632      5                  A
    #> 19: CHERICHERILADY   2   100    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   100    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   100    0.167 1.2893253      3                  B
    #> 22: CHERICHERILADY   2   100    0.167 1.0561114      5                  B
    #> 23: CHERICHERILADY   2   100    5.000 2.4315334      3                  B
    #> 24: CHERICHERILADY   2   100    5.000 2.2832633      5                  B
    #> 25: CHERICHERILADY   3   100    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   100    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   100    0.167 1.0852956      3                  A
    #> 28: CHERICHERILADY   3   100    0.167 1.7403264      5                  A
    #> 29: CHERICHERILADY   3   100    5.000 1.6813097      3                  A
    #> 30: CHERICHERILADY   3   100    5.000 2.0703185      5                  A
    #> 31: CHERICHERILADY   3   100    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   100    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   100    0.167 1.4077223      3                  B
    #> 34: CHERICHERILADY   3   100    0.167 1.4689478      5                  B
    #> 35: CHERICHERILADY   3   100    5.000 2.5328115      3                  B
    #> 36: CHERICHERILADY   3   100    5.000 2.1029809      5                  B
    #> 37: CHERICHERILADY   4   100    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   100    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   100    0.167 0.9259389      3                  A
    #> 40: CHERICHERILADY   4   100    0.167 1.4567690      5                  A
    #> 41: CHERICHERILADY   4   100    5.000 2.1933157      3                  A
    #> 42: CHERICHERILADY   4   100    5.000 2.2186362      5                  A
    #> 43: CHERICHERILADY   4   100    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   100    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   100    0.167 1.1325609      3                  B
    #> 46: CHERICHERILADY   4   100    0.167 1.4687089      5                  B
    #> 47: CHERICHERILADY   4   100    5.000 2.2201589      3                  B
    #> 48: CHERICHERILADY   4   100    5.000 2.6779419      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #>
    #> [[3]]
    #> [[3]][[1]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   200    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   200    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   200    0.167 0.9192103      3                  A
    #>  4: CHERICHERILADY   1   200    0.167 1.3795445      5                  A
    #>  5: CHERICHERILADY   1   200    5.000 1.6738519      3                  A
    #>  6: CHERICHERILADY   1   200    5.000 2.0097934      5                  A
    #>  7: CHERICHERILADY   1   200    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   200    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   200    0.167 1.3003182      3                  B
    #> 10: CHERICHERILADY   1   200    0.167 1.6588773      5                  B
    #> 11: CHERICHERILADY   1   200    5.000 1.8973142      3                  B
    #> 12: CHERICHERILADY   1   200    5.000 1.9998967      5                  B
    #> 13: CHERICHERILADY   2   200    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   200    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   200    0.167 1.5072892      3                  A
    #> 16: CHERICHERILADY   2   200    0.167 1.3773792      5                  A
    #> 17: CHERICHERILADY   2   200    5.000 2.0170342      3                  A
    #> 18: CHERICHERILADY   2   200    5.000 1.9735832      5                  A
    #> 19: CHERICHERILADY   2   200    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   200    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   200    0.167 1.2415880      3                  B
    #> 22: CHERICHERILADY   2   200    0.167 0.8160180      5                  B
    #> 23: CHERICHERILADY   2   200    5.000 1.9620370      3                  B
    #> 24: CHERICHERILADY   2   200    5.000 1.5091585      5                  B
    #> 25: CHERICHERILADY   3   200    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   200    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   200    0.167 1.1402270      3                  A
    #> 28: CHERICHERILADY   3   200    0.167 1.3932776      5                  A
    #> 29: CHERICHERILADY   3   200    5.000 1.8251330      3                  A
    #> 30: CHERICHERILADY   3   200    5.000 2.2904576      5                  A
    #> 31: CHERICHERILADY   3   200    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   200    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   200    0.167 1.4656616      3                  B
    #> 34: CHERICHERILADY   3   200    0.167 1.1774973      5                  B
    #> 35: CHERICHERILADY   3   200    5.000 2.0786363      3                  B
    #> 36: CHERICHERILADY   3   200    5.000 1.6740664      5                  B
    #> 37: CHERICHERILADY   4   200    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   200    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   200    0.167 0.7852231      3                  A
    #> 40: CHERICHERILADY   4   200    0.167 1.5536717      5                  A
    #> 41: CHERICHERILADY   4   200    5.000 1.4398432      3                  A
    #> 42: CHERICHERILADY   4   200    5.000 2.0938878      5                  A
    #> 43: CHERICHERILADY   4   200    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   200    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   200    0.167 1.1391676      3                  B
    #> 46: CHERICHERILADY   4   200    0.167 0.9436166      5                  B
    #> 47: CHERICHERILADY   4   200    5.000 1.9333818      3                  B
    #> 48: CHERICHERILADY   4   200    5.000 1.9133177      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>
    #> [[3]][[2]]
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state
    #>  1: CHERICHERILADY   1   200    0.000 0.0000000      3                  A
    #>  2: CHERICHERILADY   1   200    0.000 0.0000000      5                  A
    #>  3: CHERICHERILADY   1   200    0.167 1.2889882      3                  A
    #>  4: CHERICHERILADY   1   200    0.167 0.6497663      5                  A
    #>  5: CHERICHERILADY   1   200    5.000 2.2352366      3                  A
    #>  6: CHERICHERILADY   1   200    5.000 1.7340315      5                  A
    #>  7: CHERICHERILADY   1   200    0.000 0.0000000      3                  B
    #>  8: CHERICHERILADY   1   200    0.000 0.0000000      5                  B
    #>  9: CHERICHERILADY   1   200    0.167 1.0475158      3                  B
    #> 10: CHERICHERILADY   1   200    0.167 1.2707170      5                  B
    #> 11: CHERICHERILADY   1   200    5.000 1.5745761      3                  B
    #> 12: CHERICHERILADY   1   200    5.000 1.9409744      5                  B
    #> 13: CHERICHERILADY   2   200    0.000 0.0000000      3                  A
    #> 14: CHERICHERILADY   2   200    0.000 0.0000000      5                  A
    #> 15: CHERICHERILADY   2   200    0.167 0.9468887      3                  A
    #> 16: CHERICHERILADY   2   200    0.167 1.3770209      5                  A
    #> 17: CHERICHERILADY   2   200    5.000 1.7767978      3                  A
    #> 18: CHERICHERILADY   2   200    5.000 2.1329732      5                  A
    #> 19: CHERICHERILADY   2   200    0.000 0.0000000      3                  B
    #> 20: CHERICHERILADY   2   200    0.000 0.0000000      5                  B
    #> 21: CHERICHERILADY   2   200    0.167 1.3397511      3                  B
    #> 22: CHERICHERILADY   2   200    0.167 0.6677473      5                  B
    #> 23: CHERICHERILADY   2   200    5.000 1.7203313      3                  B
    #> 24: CHERICHERILADY   2   200    5.000 1.4457426      5                  B
    #> 25: CHERICHERILADY   3   200    0.000 0.0000000      3                  A
    #> 26: CHERICHERILADY   3   200    0.000 0.0000000      5                  A
    #> 27: CHERICHERILADY   3   200    0.167 1.1518489      3                  A
    #> 28: CHERICHERILADY   3   200    0.167 1.0544928      5                  A
    #> 29: CHERICHERILADY   3   200    5.000 1.8950090      3                  A
    #> 30: CHERICHERILADY   3   200    5.000 1.7786260      5                  A
    #> 31: CHERICHERILADY   3   200    0.000 0.0000000      3                  B
    #> 32: CHERICHERILADY   3   200    0.000 0.0000000      5                  B
    #> 33: CHERICHERILADY   3   200    0.167 1.3907501      3                  B
    #> 34: CHERICHERILADY   3   200    0.167 1.0546782      5                  B
    #> 35: CHERICHERILADY   3   200    5.000 2.1036419      3                  B
    #> 36: CHERICHERILADY   3   200    5.000 2.1847686      5                  B
    #> 37: CHERICHERILADY   4   200    0.000 0.0000000      3                  A
    #> 38: CHERICHERILADY   4   200    0.000 0.0000000      5                  A
    #> 39: CHERICHERILADY   4   200    0.167 1.5362964      3                  A
    #> 40: CHERICHERILADY   4   200    0.167 1.1456876      5                  A
    #> 41: CHERICHERILADY   4   200    5.000 2.0304707      3                  A
    #> 42: CHERICHERILADY   4   200    5.000 1.9172427      5                  A
    #> 43: CHERICHERILADY   4   200    0.000 0.0000000      3                  B
    #> 44: CHERICHERILADY   4   200    0.000 0.0000000      5                  B
    #> 45: CHERICHERILADY   4   200    0.167 1.2819903      3                  B
    #> 46: CHERICHERILADY   4   200    0.167 0.9935587      5                  B
    #> 47: CHERICHERILADY   4   200    5.000 2.2534796      3                  B
    #> 48: CHERICHERILADY   4   200    5.000 1.3380264      5                  B
    #>           Sequence Rep State Exposure      Mass Charge Experimental_state

## Power estimation

The package `powerHaDeX` provides a possibility of the estimation of rejection rate in pairwise testing of differences in deuteration levels.

The tests available in the package are:

- `test_semiparametric` - Semiparametric test,

- `test_houde` - Damian Houde’s confidence intervals test (Houde, Berkowitz, and Engen 2011),

- `test_hdx_analyzer` - HDX-Analyzer model (Liu et al. 2011),

- `test_memhdx_model` - MEMHDX model (Hourdel et al. 2016).

We can use the function `calculate_hdx_power` to execute the testing procedure on the data simulated by `get_noisy_deuteration_curves`. Example usage of the function is shown below

    calculate_hdx_power(deuteration_curves_paired_states,
                        tests = list(test_houde),
                        summarized = FALSE)
    #>          Sequence Num_replicates Num_states Num_timepoints  Test State_1
    #> 1: CHERICHERILADY              4          2              3 Houde     100
    #> 2: CHERICHERILADY              4          2              3 Houde     100
    #> 3: CHERICHERILADY              4          2              3 Houde     100
    #> 4: CHERICHERILADY              4          2              3 Houde     100
    #> 5: CHERICHERILADY              4          2              3 Houde     200
    #> 6: CHERICHERILADY              4          2              3 Houde     200
    #>    State_2 Test_statistic P_value Significant_difference Time Transformation
    #> 1:     200             NA      NA                  FALSE   NA             NA
    #> 2:     200             NA      NA                  FALSE   NA             NA
    #> 3:     100             NA      NA                  FALSE   NA             NA
    #> 4:     100             NA      NA                  FALSE   NA             NA
    #> 5:     200             NA      NA                  FALSE   NA             NA
    #> 6:     200             NA      NA                  FALSE   NA             NA
    #>    AIC logLik
    #> 1:  NA     NA
    #> 2:  NA     NA
    #> 3:  NA     NA
    #> 4:  NA     NA
    #> 5:  NA     NA
    #> 6:  NA     NA

The summarized result is following

    calculate_hdx_power(deuteration_curves_paired_states,
                        tests = list(test_houde),
                        summarized = TRUE)
    #>          Sequence Num_replicates Num_states Num_timepoints  Test Transformation
    #> 1: CHERICHERILADY              4          2              3 Houde             NA
    #> 2: CHERICHERILADY              4          2              3 Houde             NA
    #> 3: CHERICHERILADY              4          2              3 Houde             NA
    #>    Time State_1 State_2 Power
    #> 1:   NA     100     200     0
    #> 2:   NA     100     100     0
    #> 3:   NA     200     200     0

There is a possibility of simulate the rejection rate of another test using an external implementation. Such a test function for pairwise testing should be of specific shape as below:

    example_test <- function(data, significance_level) {
      States = unique(data$State)

      # testing procedure here

      return(data.table::data.table(Test = "Example test",
                                    State_1 = States[1],
                                    State_2 = States[2],
                                    Test_statistic = NA,
                                    P_value = NA,
                                    Significant_difference = #TRUE or FALSE,
                                      Time = NA,
                                    Transformation = NA,
                                    AIC = NA,
                                    logLik = NA))
    }

where the parameter `data` is one experiment, that is one data table obtained from the function `get_noisy_deuteration_curves`. In order to add such a test to the simulation, we should set `tests = list(houde, example_test)`.