Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major and minor tweaks #46

Merged
merged 7 commits into from
Sep 15, 2024
Merged

Conversation

RLumSK
Copy link
Collaborator

@RLumSK RLumSK commented Sep 14, 2024

This PR tackles major and minor issues in the package. I'm sorry for not splitting it into separate pull requests; the problems were related.

Description

This pull request addresses the following issues:

  • The calculation of the uncertainty of the signal integral was somewhat odd, adding a factor of 2 to the uncertainty var(2 * sum(E_i)) instead of var(sum(E_i)) assuming Poisson statistics. I also found this factor in the old Excel sheet; however, it lacks justification. Suppose it is intended as an additional overdispersion value. In that case, it should appear outside, not inside, and better be addressed with the (already existing) epsilon parameter. Given that this was unexpected, I've updated the documentation for the current calculation.
  • I have added a Monte Carlo simulation approach to calculate the uncertainty of the gamma dose rate. This is more realistic than the current approach because it considers all parameters. The uncertainty becomes only slightly larger, but as said, it seems more realistic. The new function argument in predict_dose() is called use_MC and is set to FALSE by default so as not to break the old code.
  • Along the way, I've updated the documentation accordingly and added a few more tests covering the new MC simulation and checking for regression. The MC simulation test is not called on CRAN to avoid overstretching their resources.
  • Minor issue: The axis labelling was only Signal ..., I changed it Integrated signal ... rendering more straightforward to understand. This changed required an update of the plot output snapshots

Related Issue

Not applicable

Example

## Import CNF files
## Spectra
spc_dir <- system.file("extdata/BDX_LaBr_1/calibration", package = "gamma")
spc <- read(spc_dir)

## Background

### Code
bkg_dir <- system.file("extdata/BDX_LaBr_1/background", package = "gamma")
bkg <- read(bkg_dir)

## Get dose rate values
data("clermont")
(doses <- clermont[, c("gamma_dose", "gamma_error")])

## Build the calibration curve
calib_curve <- dose_fit(spc, bkg, doses,
                        range_Ni = c(300, 2800),
                        range_NiEi = c(165, 2800))

## Plot the curve
plot(calib_curve, threshold = "Ni")

## Estimate gamma dose rates
dose_predict(calib_curve, spc, use_MC = TRUE)

Output use_MC = FALSE (default)

> dose_predict(calib_curve, spc)
   names signal_Ni signal_err_Ni   dose_Ni dose_err_Ni signal_NiEi signal_err_NiEi dose_NiEi dose_err_NiEi dose_final dose_err_final
1 BRIQUE  67.56799     0.1088753 1953.8126    51.04781    64025.06        3.453506 1946.9570      49.02259  1950.3848       70.77024
2   C341  28.93445     0.2321450  844.2413    23.03416    27700.15        7.462936  843.0632      21.22872   843.6523       31.32285
3   C347  48.95519     0.3204599 1419.2451    38.15865    46110.29       10.141403 1402.5373      35.31587  1410.8912       51.97214
4    GOU  55.16875     0.2796524 1597.7011    42.44396    52563.01        8.865474 1598.6316      40.25289  1598.1664       58.49693
5    LMP  21.85261     0.2236734  640.8480    17.95295    20987.25        7.236250  639.0619      16.09246   639.9549       24.10606
6    MAZ  39.23547     0.2551738 1140.0909    30.64143    37607.71        8.156462 1144.1487      28.80962  1142.1198       42.06299
7    PEP  84.50625     0.4606470 2440.2863    65.01209    80089.25       14.465409 2435.1387      61.31599  2437.7125       89.36030

Output use_MC = TRUE (new)

   names signal_Ni signal_err_Ni   dose_Ni dose_err_Ni signal_NiEi signal_err_NiEi dose_NiEi dose_err_NiEi dose_final dose_err_final
1 BRIQUE  67.56799     0.1088753 1953.8126    57.00860    64025.06        3.453506 1946.9570      54.84062  1950.3848       79.09917
2   C341  28.93445     0.2321450  844.2413    34.44022    27700.15        7.462936  843.0632      32.47541   843.6523       47.33498
3   C347  48.95519     0.3204599 1419.2451    45.86641    46110.29       10.141403 1402.5373      43.02511  1410.8912       62.86741
4    GOU  55.16875     0.2796524 1597.7011    49.48437    52563.01        8.865474 1598.6316      47.16220  1598.1664       68.36013
5    LMP  21.85261     0.2236734  640.8480    31.29961    20987.25        7.236250  639.0619      29.37842   639.9549       42.92368
6    MAZ  39.23547     0.2551738 1140.0909    39.88503    37607.71        8.156462 1144.1487      37.86666  1142.1198       55.00260
7    PEP  84.50625     0.4606470 2440.2863    69.72009    80089.25       14.465409 2435.1387      66.06489  2437.7125       96.04396

This output depends slightly on the set random seed.

+ up xaxis label default for more clarity.
+ up signal_integrate
+ ad additional documentation
+ up NEWS
+ up manual
+ ad NEWS
+ ad code running the MC simulation in predict_york()
+ ad new parameter use_MC
+ up documentation with information
+ ad more tests
+ up manual
+ ad NEWS
+ ad skip of certain tests on CRAN
@nfrerebeau nfrerebeau merged commit 7119566 into crp2a:master Sep 15, 2024
7 checks passed
@RLumSK RLumSK deleted the major_and_minor_tweaks branch September 15, 2024 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants