Warning Message from cv.glmnet
The issue seems to be the user-supplied lambda sequence tripping up the algorithm. This sequence is producing the same results/error for each lambda (as seen in the cvm
vector in the cv.glmnet
object).
If you need a user-supplied sequence, I'd suggest guiding the algorithm to create it using the nlambda
and lambda.min.ratio
arguments in your call to the function. Something like the below, changing the parameters to suit your purposes.
cv.glmnet(x, y, alpha = 1, nlambda = 500, lambda.min.ratio = 10^(-2))
For what it's worth, the warning message itself is related to an internally called stats::regularize.values
function, itself called from an approx
function. It seems to be a symptom of the issue with the lambda sequence, not a problem in and of itself.
What does collapsing to unique 'x' values mean in this example?
@teunbrand confirmed my hypothesis that
ecdf <- stats::approxfun(dens, data$y)
(https://github.com/tidyverse/ggplot2/blob/cc3951cd942d/R/geom-violin.r#L200) is to blame.
Zeros in the density
of the data$y
translate into equal values ("ties") in the cumulative density dens
- hence the warning.
These zeros can be avoided by adjust
ing the bandwidth of the density (here, slightly - in my example, I need to use a value as large as 3
):
df <- data.frame(x = 1, y = c(0, 0.25, 0.5, 0.75, 5))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), adjust=1.1)
Note: that code is hard to read due to niceties such as using dens
for the cumulative density.
But stats::regularize.values
is not necessarily better:
x <- xy.coords(x, y) # -> (x,y) numeric of same length
y <- x$y
x <- x$x
The problem also can be fixed by
ecdf <- stats::approxfun(dens, data$y, ties = "ordered")
as in this monkey patch:
create_quantile_segment_frame <- function(data, draw_quantiles) {
dens <- cumsum(data$density) / sum(data$density)
ecdf <- stats::approxfun(dens, data$y, ties = "ordered")
ys <- ecdf(draw_quantiles) # these are all the y-values for quantiles
# Get the violin bounds for the requested quantiles.
violin.xminvs <- (stats::approxfun(data$y, data$xminv))(ys)
violin.xmaxvs <- (stats::approxfun(data$y, data$xmaxv))(ys)
# We have two rows per segment drawn. Each segment gets its own group.
ggplot2:::new_data_frame(list(
x = ggplot2:::interleave(violin.xminvs, violin.xmaxvs),
y = rep(ys, each = 2),
group = rep(ys, each = 2)
))
}
assignInNamespace("create_quantile_segment_frame", create_quantile_segment_frame, "ggplot2")
df <- data.frame(x = 1, y = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10))
ggplot2::ggplot(df, ggplot2::aes(x = x, y = y)) +
ggplot2::geom_violin(draw_quantiles = c(0.5), bw = 0.1)
Suppress C warning messages in R
The function uses stdio instead of Rprintf
/REprintf
or warning
which is why re-direction of the R output won't work. The proper solution is to fix the calls in libsvm
to use R output instead.
Hacking the stdio output is possible - you can re-direct the output to your own pipe and do what you want with it, but a) it's a bit of work in C and b) it's dangerous because you need to restore the standard behavior after you're done with the function - even if it errors out and c) in may interact with R output if used on a shell.
If you want a really whacky, dirty yet quick solution, run your function in collect(parallel(..., silent=TRUE))[[1]]
from multicore
- it suppresses stdout (you can add multicore:::closeStderr()
if you want to suppress stderr as well).
Is it possible to use an old version of 'stats' package in R?
You can try this:
assignInNamespace("regularize.values", regularize.values.OV,
ns="stats", envir = as.environment("package:stats"))
However, it will only work if the error is not thrown by a package that depends on the already-loaded stats
Therefore, a working solution should be:
assignInNamespace("regularize.values", function(x, y, ties) {
x <- xy.coords(x, y)
y <- x$y
x <- x$x
if(any(na <- is.na(x) | is.na(y))) {
ok <- !na
x <- x[ok]
y <- y[ok]
}
nx <- length(x)
if (!identical(ties, "ordered")) {
o <- order(x)
x <- x[o]
y <- y[o]
if (length(ux <- unique(x)) < nx) {
# if (missing(ties))
# warning("collapsing to unique 'x' values")
y <- as.vector(tapply(y,match(x,x),ties))
x <- ux
stopifnot(length(y) == length(x))
}
}
list(x=x, y=y)
}, ns="stats", envir = as.environment("package:stats"))
Related Topics
Installing Package from a Local .Tar.Gz File on Linux
How to Deploy Shiny App That Uses Local Data
Knn in R: 'Train and Class Have Different Lengths'
Extract Certain Files from .Zip
Stacked Bar Chart, Reorder by Total (Sum Up of Values) Instead of Value Ggplot2 + Dplyr
Keep Only Groups of Data with Multiple Observations
Ggplot Legend - Scale_Colour_Manual Not Working
Predict X Values from Simple Fitting and Annoting It in the Plot
Write.Table Writes Unwanted Leading Empty Column to Header When Has Rownames
Convert a Mm-Yy String "Jan-01" into Date Format
How to 'Unlist' a Column in a Data.Table
How to Replace Certain Values in a Specific Rows and Columns with Na in R
How to Calculate Confidence Intervals for Nonlinear Least Squares in R