Skip to content

Commit

Permalink
Work on #11
Browse files Browse the repository at this point in the history
- Include nice HTML table of regression results
  • Loading branch information
Damian-Oswald committed Feb 11, 2024
1 parent e76c2dd commit 2b76b5e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 212 deletions.
4 changes: 2 additions & 2 deletions docs/data-preparation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/introduction.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h3 data-number="2.2.1" class="anchored" data-anchor-id="what-do-the-various-fun
}
return(results)
}
&lt;bytecode: 0x7fee7dc14240&gt;
&lt;bytecode: 0x7fc2e157f440&gt;
&lt;environment: namespace:PRE&gt;</code></pre>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"href": "introduction.html#installation-of-the-r-package-pre",
"title": "2  Introduction",
"section": "2.2 Installation of the R package PRE",
"text": "2.2 Installation of the R package PRE\nAll functions that are used repeatedly throughout this projec are implemented in an R package called PRE. The source code of this package is stored in a publically accessible way on GitHub. You can install the package directly from GitHub using the install_github function from the remotes package.\n\ninstall.packages(\"remotes\")\nremotes::install_github(\"https://github.com/Damian-Oswald/PRE\")\n\nAlternatively, you could download the GitHub repository and manually install the PRE package locally. Once the package is installed, you can attach it to the search path in the usual way.\n\nlibrary(PRE)\n\n\n2.2.1 What do the various functions do?\nThe R code shown on this project help page is extremely simplified. If you want want to understand what a specific function of the PRE package does, simple visit the corresponding R help page. For example, you could read on the function crossValidate by using one of the the following commands.\n\nhelp(\"crossValidate\", package = \"PRE\")\n?crossValidate\n\nIf you want to jump really deep into a function, you could print it out in your console.\n\nprint(crossValidate)\n\nfunction (FUN, x, y, k = nrow(x), r = 1, hyperparameter = NULL) \n{\n results &lt;- data.frame()\n for (R in 1:r) {\n I &lt;- matrix(c(sample(1:nrow(x)), rep(NA, k - nrow(x)%%k)), \n ncol = k, byrow = TRUE)\n for (K in 1:k) {\n i &lt;- na.omit(I[, K])\n result &lt;- cbind(cost = FUN(x_train = x[-i, ], y_train = y[-i, \n ], x_test = x[i, ], y_test = y[i, ], hyperparameter = hyperparameter), \n r = R, k = K)\n results &lt;- rbind(results, result)\n }\n }\n return(results)\n}\n&lt;bytecode: 0x7fee7dc14240&gt;\n&lt;environment: namespace:PRE&gt;\n\n\nNote this function source code output is lacking any comments. Those were automatically removed when compiling the R package. To see the commented source code, you’ll have to jump into the package files, or visit the GitHub page. Simply use the following URL:\nhttps://github.com/Damian-Oswald/PRE/blob/main/R/crossValidate.R\nNotice how the base name (the last part of the URL) matches the function name. You can replace that by any function name of your liking."
"text": "2.2 Installation of the R package PRE\nAll functions that are used repeatedly throughout this projec are implemented in an R package called PRE. The source code of this package is stored in a publically accessible way on GitHub. You can install the package directly from GitHub using the install_github function from the remotes package.\n\ninstall.packages(\"remotes\")\nremotes::install_github(\"https://github.com/Damian-Oswald/PRE\")\n\nAlternatively, you could download the GitHub repository and manually install the PRE package locally. Once the package is installed, you can attach it to the search path in the usual way.\n\nlibrary(PRE)\n\n\n2.2.1 What do the various functions do?\nThe R code shown on this project help page is extremely simplified. If you want want to understand what a specific function of the PRE package does, simple visit the corresponding R help page. For example, you could read on the function crossValidate by using one of the the following commands.\n\nhelp(\"crossValidate\", package = \"PRE\")\n?crossValidate\n\nIf you want to jump really deep into a function, you could print it out in your console.\n\nprint(crossValidate)\n\nfunction (FUN, x, y, k = nrow(x), r = 1, hyperparameter = NULL) \n{\n results &lt;- data.frame()\n for (R in 1:r) {\n I &lt;- matrix(c(sample(1:nrow(x)), rep(NA, k - nrow(x)%%k)), \n ncol = k, byrow = TRUE)\n for (K in 1:k) {\n i &lt;- na.omit(I[, K])\n result &lt;- cbind(cost = FUN(x_train = x[-i, ], y_train = y[-i, \n ], x_test = x[i, ], y_test = y[i, ], hyperparameter = hyperparameter), \n r = R, k = K)\n results &lt;- rbind(results, result)\n }\n }\n return(results)\n}\n&lt;bytecode: 0x7fc2e157f440&gt;\n&lt;environment: namespace:PRE&gt;\n\n\nNote this function source code output is lacking any comments. Those were automatically removed when compiling the R package. To see the commented source code, you’ll have to jump into the package files, or visit the GitHub page. Simply use the following URL:\nhttps://github.com/Damian-Oswald/PRE/blob/main/R/crossValidate.R\nNotice how the base name (the last part of the URL) matches the function name. You can replace that by any function name of your liking."
},
{
"objectID": "data-preparation.html#description-of-the-measurements",
Expand Down Expand Up @@ -116,7 +116,7 @@
"href": "sensitivity-analysis.html#what-effect-does-the-bulk-density-have",
"title": "6  Sensitivity Analysis",
"section": "6.4 What effect does the bulk density have?",
"text": "6.4 What effect does the bulk density have?\nFirst, we’ll determine a range of bulk density to be searched.\nBD &lt;- getParameters()$BD + seq(-0.15, 0.15, 0.05)\nNext, we have to construct a function to return the process estimates for a give bulk density x.\nf &lt;- function(x) {\n parameters &lt;- getParameters(BD = x)\n data &lt;- subset(measurements, column==1) |&gt;\n getN2ON(parameters = parameters) |&gt;\n getMissing() |&gt;\n calculateFluxes(parameters = parameters)\n return(longPRE(data, 1, 7.5, n = 15)$processes)\n}\nFinally, we’ll apply said function to all bulk densities in the vector BD.\nresult &lt;- t(sapply(BD, f))\nThis process will return us the data to be analyzed.\n\n\n\nFigure 6.3: Illustration to the sensitivity of estimated process rates to a change in prior bulk density.\n\n\n\n\n\n\n\n\n\n\n\n\nDependent variable:\n\n\n\n\n\n\n\n\n\n\n\n\nNitrification\n\n\nDenitrification\n\n\nReduction\n\n\n\n\n\n\n(1)\n\n\n(2)\n\n\n(3)\n\n\n\n\n\n\n\n\nBD\n\n\n-20.907***\n\n\n-4.672***\n\n\n31.267***\n\n\n\n\n\n\n(0.993)\n\n\n(0.619)\n\n\n(0.926)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nConstant\n\n\n47.404***\n\n\n26.665***\n\n\n-27.614***\n\n\n\n\n\n\n(1.678)\n\n\n(1.045)\n\n\n(1.565)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nObservations\n\n\n7\n\n\n7\n\n\n7\n\n\n\n\nR2\n\n\n0.989\n\n\n0.919\n\n\n0.996\n\n\n\n\nAdjusted R2\n\n\n0.987\n\n\n0.903\n\n\n0.995\n\n\n\n\nResidual Std. Error (df = 5)\n\n\n0.263\n\n\n0.164\n\n\n0.245\n\n\n\n\nF Statistic (df = 1; 5)\n\n\n442.914***\n\n\n57.032***\n\n\n1,139.130***\n\n\n\n\n\n\n\n\nNote:\n\n\np&lt;0.1; p&lt;0.05; p&lt;0.01\n\n\n\n\n\n\n\n\nBates, D., M. Mächler, B. Bolker, and S. Walker. 2014. Fitting linear mixed-effects models using lme4. arXiv preprint arXiv:1406.5823.\n\n\nDecock, C., and J. Six. 2013. On the potential of \\(\\delta\\) 18O and \\(\\delta\\) 15N to assess N2O reduction to N2 in soil. European journal of soil science 64:610–620.\n\n\nDenk, T. R., J. Mohn, C. Decock, D. Lewicka-Szczebak, E. Harris, K. Butterbach-Bahl, R. Kiese, and B. Wolf. 2017. The nitrogen cycle: A review of isotope effects and isotope modeling approaches. Soil Biology and Biochemistry 105:121–137.\n\n\nLewicka-Szczebak, D., J. Augustin, A. Giesemann, and R. Well. 2017. Quantifying N₂O reduction to N₂ based on N₂O isotopocules – validation with independent methods (helium incubation and ¹⁵N gas flux method). Biogeosciences 14:711–732.\n\n\nSobol’, I. M. 1990. On sensitivity estimation for nonlinear mathematical models. Matematicheskoe modelirovanie 2:112–118.\n\n\nWell, R., and H. Flessa. 2008. Isotope fractionation factors of N₂O diffusion. Rapid Communications in Mass Spectrometry: An International Journal Devoted to the Rapid Dissemination of Up-to-the-Minute Research in Mass Spectrometry 22:2621–2628.\n\n\nWickham, H. 2011. The split-apply-combine strategy for data analysis. Journal of statistical software 40:1–29."
"text": "6.4 What effect does the bulk density have?\nFirst, we’ll determine a range of bulk density to be searched.\nBD &lt;- getParameters()$BD + seq(-0.15, 0.15, 0.05)\nNext, we have to construct a function to return the process estimates for a give bulk density x.\nf &lt;- function(x) {\n parameters &lt;- getParameters(BD = x)\n data &lt;- subset(measurements, column==1) |&gt;\n getN2ON(parameters = parameters) |&gt;\n getMissing() |&gt;\n calculateFluxes(parameters = parameters)\n return(longPRE(data, 1, 7.5, n = 15)$processes)\n}\nFinally, we’ll apply said function to all bulk densities in the vector BD.\nresult &lt;- t(sapply(BD, f))\nThis process will return us the data to be analyzed.\n\n\n\nFigure 6.3: Illustration to the sensitivity of estimated process rates to a change in prior bulk density.\n\n\n\n\n\n\n \nNitrification\nDenitrification\nReduction\n\n\nPredictors\nEstimates\np\nEstimates\np\nEstimates\np\n\n\n(Intercept)\n47.4\n&lt;0.001\n26.7\n&lt;0.001\n-27.6\n&lt;0.001\n\n\nBD\n-20.9\n&lt;0.001\n-4.7\n0.001\n31.3\n&lt;0.001\n\n\nObservations\n7\n7\n7\n\n\nR2 / R2 adjusted\n0.989 / 0.987\n0.919 / 0.903\n0.996 / 0.995\n\n\n\n\n\n\n\n\n\n\nBates, D., M. Mächler, B. Bolker, and S. Walker. 2014. Fitting linear mixed-effects models using lme4. arXiv preprint arXiv:1406.5823.\n\n\nDecock, C., and J. Six. 2013. On the potential of \\(\\delta\\) 18O and \\(\\delta\\) 15N to assess N2O reduction to N2 in soil. European journal of soil science 64:610–620.\n\n\nDenk, T. R., J. Mohn, C. Decock, D. Lewicka-Szczebak, E. Harris, K. Butterbach-Bahl, R. Kiese, and B. Wolf. 2017. The nitrogen cycle: A review of isotope effects and isotope modeling approaches. Soil Biology and Biochemistry 105:121–137.\n\n\nLewicka-Szczebak, D., J. Augustin, A. Giesemann, and R. Well. 2017. Quantifying N₂O reduction to N₂ based on N₂O isotopocules – validation with independent methods (helium incubation and ¹⁵N gas flux method). Biogeosciences 14:711–732.\n\n\nSobol’, I. M. 1990. On sensitivity estimation for nonlinear mathematical models. Matematicheskoe modelirovanie 2:112–118.\n\n\nWell, R., and H. Flessa. 2008. Isotope fractionation factors of N₂O diffusion. Rapid Communications in Mass Spectrometry: An International Journal Devoted to the Rapid Dissemination of Up-to-the-Minute Research in Mass Spectrometry 22:2621–2628.\n\n\nWickham, H. 2011. The split-apply-combine strategy for data analysis. Journal of statistical software 40:1–29."
},
{
"objectID": "references.html",
Expand Down
250 changes: 46 additions & 204 deletions docs/sensitivity-analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -705,217 +705,59 @@ <h2 data-number="6.4" class="anchored" data-anchor-id="what-effect-does-the-bulk
<figcaption class="figure-caption">Figure&nbsp;6.3: Illustration to the sensitivity of estimated process rates to a change in prior bulk density.</figcaption>
</figure>
</div>

<table style="text-align:center">
<tbody><tr>
<td colspan="4" style="border-bottom: 1px solid black">
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td colspan="3">
<em>Dependent variable:</em>
</td>
</tr>
<tr>
<td>
</td>
<td colspan="3" style="border-bottom: 1px solid black">
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
Nitrification
</td>
<td>
Denitrification
</td>
<td>
Reduction
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
(1)
</td>
<td>
(2)
</td>
<td>
(3)
</td>
</tr>
<tr>
<td colspan="4" style="border-bottom: 1px solid black">
</td>
</tr>
<tr>
<td style="text-align:left">
BD
</td>
<td>
-20.907<sup>***</sup>
</td>
<td>
-4.672<sup>***</sup>
</td>
<td>
31.267<sup>***</sup>
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
(0.993)
</td>
<td>
(0.619)
</td>
<td>
(0.926)
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td style="text-align:left">
Constant
</td>
<td>
47.404<sup>***</sup>
</td>
<td>
26.665<sup>***</sup>
</td>
<td>
-27.614<sup>***</sup>
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
(1.678)
</td>
<td>
(1.045)
</td>
<td>
(1.565)
</td>
</tr>
<tr>
<td style="text-align:left">
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="4" style="border-bottom: 1px solid black">
</td>
</tr>
<tr>
<td style="text-align:left">
Observations
</td>
<td>
7
</td>
<td>
7
</td>
<td>
7
</td>
</tr>
<tr>
<td style="text-align:left">
R<sup>2</sup>
</td>
<td>
0.989
</td>
<td>
0.919
</td>
<td>
0.996
</td>
<div class="cell-output-display">
<table data-quarto-postprocess="true" class="table">
<tbody>
<tr class="odd">
<td data-quarto-table-cell-role="th" style="text-align: center; border-top: double; font-style: normal; font-weight: bold; padding: 0.2cm;">&nbsp;</td>
<td colspan="2" data-quarto-table-cell-role="th" style="text-align: center; border-top: double; font-style: normal; font-weight: bold; padding: 0.2cm;">Nitrification</td>
<td colspan="2" data-quarto-table-cell-role="th" style="text-align: center; border-top: double; font-style: normal; font-weight: bold; padding: 0.2cm;">Denitrification</td>
<td colspan="2" data-quarto-table-cell-role="th" style="text-align: center; border-top: double; font-style: normal; font-weight: bold; padding: 0.2cm;">Reduction</td>
</tr>
<tr>
<td style="text-align:left">
Adjusted R<sup>2</sup>
</td>
<td>
0.987
</td>
<td>
0.903
</td>
<td>
0.995
</td>
<tr class="even">
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">Predictors</td>
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">Estimates</td>
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">p</td>
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">Estimates</td>
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">p</td>
<td style="text-align: center; border-bottom: 1px solid; font-style: italic; font-weight: normal;">Estimates</td>
<td style="text-align: center;">p</td>
</tr>
<tr>
<td style="text-align:left">
Residual Std. Error (df = 5)
</td>
<td>
0.263
</td>
<td>
0.164
</td>
<td>
0.245
</td>
<tr class="odd">
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">(Intercept)</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">47.4</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;"><strong>&lt;0.001</strong></td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">26.7</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;"><strong>&lt;0.001</strong></td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">-27.6</td>
<td style="text-align: center;"><strong>&lt;0.001</strong></td>
</tr>
<tr>
<td style="text-align:left">
F Statistic (df = 1; 5)
</td>
<td>
442.914<sup>***</sup>
</td>
<td>
57.032<sup>***</sup>
</td>
<td>
1,139.130<sup>***</sup>
</td>
<tr class="even">
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">BD</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">-20.9</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;"><strong>&lt;0.001</strong></td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">-4.7</td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;"><strong>0.001</strong></td>
<td style="text-align: left; padding: 0.2cm; vertical-align: top;">31.3</td>
<td style="text-align: center;"><strong>&lt;0.001</strong></td>
</tr>
<tr>
<td colspan="4" style="border-bottom: 1px solid black">
</td>
<tr class="odd">
<td style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm; border-top: 1px solid;">Observations</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm; border-top: 1px solid;">7</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm; border-top: 1px solid;">7</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm; border-top: 1px solid;">7</td>
</tr>
<tr>
<td style="text-align:left">
<em>Note:</em>
</td>
<td colspan="3" style="text-align:right">
<sup><em></em></sup><em>p&lt;0.1; <sup><strong></strong></sup><strong>p&lt;0.05; <sup></sup></strong></em>p&lt;0.01
</td>
<tr class="even">
<td style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm;">R<sup>2</sup> / R<sup>2</sup> adjusted</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm;">0.989 / 0.987</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm;">0.919 / 0.903</td>
<td colspan="2" style="text-align: left; padding: 0.2cm; vertical-align: top; padding-top: 0.1cm; padding-bottom: 0.1cm;">0.996 / 0.995</td>
</tr>
</tbody>
</table>

</tbody></table>

</div>


<div id="refs" class="references csl-bib-body hanging-indent" data-line-spacing="2" role="list" style="display: none">
Expand Down
6 changes: 5 additions & 1 deletion scripts/sensitivity-analysis/04-bulk-density.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# attach packages to search path
library(PRE)

# determine a range of bulk density to be searched
BD <- getParameters()$BD + seq(-0.15, 0.15, 0.05)

Expand All @@ -9,7 +12,8 @@ f <- function(x) {
getN2ON(parameters = parameters) |>
getMissing() |>
calculateFluxes(parameters = parameters)
return(longPRE(data, 1, 7.5, n = 15)$processes)
result <- t(sapply(getParameters()$depth, function(d) longPRE(data, 1, d, n = 3)$processes))
return(data.frame(depth = getParameters()$depth, result))
}

# apply said function to all bulk densities
Expand Down
5 changes: 3 additions & 2 deletions sensitivity-analysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,6 @@ data <- read.csv(file.path("scripts","sensitivity-analysis","output","bulk-densi
m1 <- lm(Nitrification ~ BD, data)
m2 <- lm(Denitrification ~ BD, data)
m3 <- lm(Reduction ~ BD, data)
stargazer::stargazer(m1, m2, m3, type = "html")
```
#table <- stargazer::stargazer(m1, m2, m3, type = "html")
sjPlot::tab_model(m1, m2, m3, show.p = TRUE, digits = 1, show.ci = FALSE)
```

0 comments on commit 2b76b5e

Please sign in to comment.