-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
161 lines (125 loc) · 6.5 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
output: github_document
---
<!-- badges: start -->
[](https://github.com/soylentOrange/sdarr/actions/workflows/R-CMD-check.yaml)
<!-- [](https://cran.r-project.org/package=sdarr) -->
<!-- badges: end -->
<!-- README.md is generated from README.Rmd. Please edit only README.Rmd -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# sdarr
The sdarr-package provides a R implementation of the algorithm for Slope Determination by Analysis of Residuals (SDAR) as standardized in [ASTM E3076-18](https://doi.org/10.1520/E3076-18).
It allows for automated and objective linear-fitting of mechanical test-data. See a detailed description of the algorithm in the [NIST Technical Note 2050 by E. Lucon](https://doi.org/10.6028/NIST.TN.2050) or in [Graham & Adler (2011)](https://doi.org/10.1520/JTE103038).
As the SDAR-algorithm, implemented in `sdar()`, heavily uses linear regressions, a faster version `sdar_lazy()` was implemented, which finds the optimum region for the final linear regression by random sub-sampling within the normalized range of the test-data.
## Installation
You can install the latest release version of sdarr from [GitHub](https://github.com/soylentOrange/sdarr/releases/) with:
```r
# install.packages("devtools")
devtools::install_github("soylentOrange/sdarr@*release")
```
You can install the development version of sdarr from [GitHub](https://github.com/soylentOrange/sdarr/) with:
```r
# install.packages("devtools")
devtools::install_github("soylentOrange/sdarr")
```
## Examples
### Standard SDAR-algorithm
A basic example of using `sdar()` on a synthetic data set, which is based on the properties of aluminium (EN AW-6060-T66).
A toe-region and a non-zero intercept are added to make the test data less boring.
`sdar()` analyzes the data and will give a small report as a message.
It should confirm the Young's-modulus of 69 GPa and an intercept of 10 MPa.
To make use of multi-core processing, configure [furrr](https://furrr.futureverse.org/) to use a multi-session strategy.
```{r example-sdar}
library(sdarr)
# setup multisession calculations with a maximum of 8 cores
# (or however many cores are available...)
future::plan(future::multisession,
workers = min(c(parallelly::availableCores(), 8))
)
# Synthesize a test record resembling EN AW-6060-T66
Al_6060_T66 <- synthesize_test_data(
slope = 69000, yield.y = 160,
ultimate.y = 215, ultimate.x = 0.08,
offset = 10,
toe.start.y = 3, toe.end.y = 15,
toe.start.slope = 13600
)
# Analyze the test record
Al_6060_T66.result <- sdar(Al_6060_T66,
x = strain, y = stress)
```
### Random sub-sampling modification of the SDAR-algorithm
A basic example of `sdar_lazy()`, a random sub-sampling modification of the SDAR-algorithm on a synthetic data set, which is based on the properties of aluminium (EN AW-6060-T66).
A toe-region and a non-zero intercept are added to make the test data less boring (see above).
`sdar_lazy()` analyzes the data for the optimum size of the fitting region via random sub-sampling. It will give a small report as a message after finding the optimum fit.
It should confirm the Young's-modulus of 69 GPa and an intercept of 10 MPa.
As the synthetic data set is noise-free (except for quantization-noise), only one random sub-sampling run will do.
To make use of multicore processing, configure [furrr](https://furrr.futureverse.org/) to use a multisession strategy (see above).
```{r example-sdar_lazy}
# set a random seed
set.seed(50041180)
# Analyze the test record
# (with enforced random sub-sampling)
Al_6060_T66.result_lazy <- sdar_lazy(Al_6060_T66,
x = strain, y = stress, plot = FALSE, enforce_subsampling = TRUE)
```
### Plot Functions
`sdar()` and `sdar_lazy()` will create diagnostic plots throughout calculations, which will only be shown when requested (i.e. set `plot = TRUE` for showing a plot of the final fit, or `plot.all = TRUE` for showing all additional diagnostic plots). To have a plot drawn later, you can call the provided plot-function from the results.
The plot-functions are [crated](https://github.com/r-lib/carrier), so you can easily tap their environment to convert it into e.g. a [ggplot2-graphic](https://ggplot2.tidyverse.org/).
```{r example-plot-fun}
# show plot of final fit using the plot function from the result (see above)
Al_6060_T66.result_lazy$plots$final.fit()
```
```{r example-plot-fun-gg}
# satisfy pipe addiction...
library(magrittr)
# make nice and shiny graphics with ggplot2...
library(ggplot2)
# plot the final fit using ggplot2
Al_6060_T66.result_lazy %>% {
# tap the environment of the crated plot-function
plot.env <- rlang::fn_env(.$plots$final.fit)
# get data and labels
plot.data <- plot.env$plot.data
plot.main <- plot.env$plot.main
plot.xlab <- plot.env$plot.xlab
plot.ylab <- plot.env$plot.ylab
plot.y.data.max <- plot.data$y.data %>% max()
plot.y.lowerBound <- plot.env$y.lowerBound
plot.y.upperBound <- plot.env$y.upperBound
# create the ggplot2
plot.data %>% ggplot(aes(x = x.data, y = y.data,
color = "Test data\n(EN AW-6060-T66)")) +
geom_line() +
geom_line(data = plot.data %>%
dplyr::filter(y.fit <= plot.y.data.max),
aes(x = x.data, y = y.fit, color = "fit (sdar_lazy)")) +
geom_hline(aes(color = "fit range",
yintercept = plot.y.lowerBound),
linetype = "dashed", show.legend = TRUE) +
geom_hline(aes(color = "fit range",
yintercept = plot.y.upperBound),
linetype = "dashed",show.legend = TRUE) +
theme_bw() +
labs(title = plot.main,
x = plot.xlab,
y = plot.ylab,
caption = paste0("Result of the random sub-sampling SDAR-algorithm:",
"\n\nFinal Slope: ",
round(.$sdar$finalSlope / 1000, 1), " GPa",
"\nTrue Intercept: ",
round(.$sdar$trueIntercept, 1), " MPa","
\n\nFit Range: ",
round(plot.y.lowerBound, 1), " MPa - ",
round(plot.y.upperBound, 1), " MPa"))
}
```
# Acknowledgements
The sdarr-package was created for the analysis of mechanical test data for the project LOBio, which is funded by the German ministry of education and research (BMBF) under grant number 13XP5174C.