# DAL ToolBox
# version 1.0.777
source("https://raw.githubusercontent.com/cefet-rj-dal/daltoolbox/main/jupyter.R")
#loading DAL
load_library("daltoolbox")
#for ploting
load_library("ggplot2")
load_library("dplyr")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform Loading required package: ggplot2 Loading required package: dplyr Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union
If the curve is decreasing, use maximum curvature analysis. It brings a trade-off between having lower x values (with not so low y values) and having higher x values (not having to much decrease in y values).
x <- seq(from=1,to=10,by=0.5)
dat <- data.frame(x = x, value = -log(x), variable = as.factor("log"))
myfit <- fit_curvature_max()
res <- transform(myfit, dat$value)
head(res)
x | y | yfit | |
---|---|---|---|
<int> | <dbl> | <dbl> | |
1 | 9 | -1.609438 | 9.224359e-08 |
grf <- plot_scatter(dat, label_x = "dimensions", label_y = "cumulative variance", colors="black") +
theme(text = element_text(size=16))
plot(grf + geom_vline(xintercept = dat$x[res$x], linetype="dashed", color = "red", size=0.5))
Warning message:
“Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.”