Angelr
2012-Jul-10 00:55 UTC
[R] Why 95% "quantile" empty in R or why 95% "quantile" = 1 with data values between 0 and 1?
I am calling quantiles as follows. I don't understand why sometimes the columns (data values) above 95% are returned as "NULL"!! When I drop the percentile down to 92%, I see colums appearing. Why would any quantile be empty? I see sometimes that 95% percentile is being chosen as "1" for my data between 0 and 1, where obviously there's no column value equal to 1. But why would 95% of a data be = 1 when there's clearly no value=1? Thanks. makeQuantiles <- function(x) { t(apply(x, 1, function(row) { quantile(row, probs = c(0.50,0.75, 0.90, 0.91,0.92,0.93,0.94,0.95,0.96,0.97,0.98) ) })) } colsGTQuantile <- function(x, qs, q) { sapply(rownames(x), function(rn) { cat(sprintf("*** row name = %s, q = %s, val = %f\n", rn, q, qs[rn, q])) names(x[rn, x[rn,] > qs[rn, q]]) }, simplify = TRUE) } df4 <- colsGTQuantile(km$points, qs, "95%") -- View this message in context: http://r.789695.n4.nabble.com/Why-95-quantile-empty-in-R-or-why-95-quantile-1-with-data-values-between-0-and-1-tp4635934.html Sent from the R help mailing list archive at Nabble.com.
Uwe Ligges
2012-Jul-11 10:26 UTC
[R] Why 95% "quantile" empty in R or why 95% "quantile" = 1 with data values between 0 and 1?
On 10.07.2012 02:55, Angelr wrote:> I am calling quantiles as follows. I don't understand why sometimes the > columns (data values) above 95% are returned as "NULL"!! When I drop the > percentile down to 92%, I see colums appearing. Why would any quantile be > empty? I see sometimes that 95% percentile is being chosen as "1" for my > data between 0 and 1, where obviously there's no column value equal to 1. > But why would 95% of a data be = 1 when there's clearly no value=1?Depends on the definition of "quantile" which is not unique, and hence R knows t least 9 definitions in the quatile() function. See ?quantile and choose a definition that fits your expectation. Best, Uwe Ligges> Thanks. > > makeQuantiles <- function(x) { > t(apply(x, 1, function(row) { quantile(row, probs = c(0.50,0.75, 0.90, > 0.91,0.92,0.93,0.94,0.95,0.96,0.97,0.98) > ) })) > } > colsGTQuantile <- function(x, qs, q) { > sapply(rownames(x), function(rn) { > cat(sprintf("*** row name = %s, q = %s, val = %f\n", rn, q, qs[rn, q])) > names(x[rn, x[rn,] > qs[rn, q]]) > }, simplify = TRUE) > } > > > df4 <- colsGTQuantile(km$points, qs, "95%") > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Why-95-quantile-empty-in-R-or-why-95-quantile-1-with-data-values-between-0-and-1-tp4635934.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >