PDFtoQuantiles | R Documentation |
CDFtoQuantiles
computes quantiles for a given CDF.
PDFtoQuantiles
computes the quantiles for given PDF values within
groups of other variables, if available.
PDFtoQuantiles(pdf_df, p = c(0.1, 0.3, 0.5, 0.7, 0.9), agg_over = NULL,
scaled = FALSE)
CDFtoQuantiles(cdf, x = NULL, p)
pdf_df |
dataframe. Should have at least two columns:
|
p |
numeric vector. Probabilities for returned quantiles. Default: c(.1, .3, .5, .7, .9). |
agg_over |
character. Names of columns in |
scaled |
logical. Indicating whether the pdf values are from a proper probability
distribution. Non-scaled pdfs will scaled to 1. If |
cdf |
numeric. A increasing vector of the same length as |
x |
numeric. A increasing vector of same length as |
For a reasonable accuracy the number of steps in the support column (rt
/x
)
should be high, i.e. the distance between values small.
We recommend, to ensure that the support vector in the input to be equidistant,
i.e. the difference between consecutive support values should be constant, though
this is not required.
If both column names x
and rt
are present in pdf_df
, rt
will be preferred.
Attention should be given to the columns of pdf_df
other than rt
/x
and dens
/pdf
.
The column for the pdf may be scaled to integrate to 1 but do not have to.
dynConfiR
packageAs argument pdf_df
, the outputs of predictRT
and predictRTModels
from the
dynConfiR
package can be used. In the context of confidence models grouping factors
often used are conditions, correct/incorrect answers and confidence ratings.
PDFtoQuantiles
returns a tibble
with columns p and q indicating
probabilities and respective quantiles. Furthermore, the output has grouping columns
identical to the additional columns in the input (without rt
/x
, dens
and densscaled
),
but without the ones in the agg_over
argument. CDFtoQuantiles
returns only a data.frame
with columns p
and q
.
Sebastian Hellmann.
## Demonstrate PDFtoQuantiles
pred <- expand.grid(model = c("dynWEV", "PCRMt"),
rt = seq(0, 15, length.out=1200),
condition = c(1,2,3),
rating = c(1,2))
pred$dens <- dchisq(pred$rt, 3) # pdf may also be used as column name
head(pred)
res <- PDFtoQuantiles(pred, p=c(0.3, 0.5, 0.7))
head(res)
nrow(res) #= 3(quantiles)*2(models)*3(conditions)*2(rating)
# Compare to true quantiles of Chi-square distribution
qchisq(p=c(0.3, 0.5, 0.7), 3)
res$q[1:3]
res2 <- PDFtoQuantiles(pred, p=c(0.3, 0.5, 0.7), agg_over = "model")
nrow(res2) #=18 because res aggregated over models
pred$pdf <- dchisq(pred$rt, 3)
head(pred)
# following call throws a warning, because both columns pdf and dens are present
PDFtoQuantiles(pred, p=c(0.3, 0.5, 0.7), agg_over = "model")
pred2 <- data.frame(rt=seq(0, 7, length.out=100))
pred2$dens <- dchisq(pred2$rt, 5)
# following call throws a warning, because density is assumed to be scaled (scaled=TRUE), i.e.
# integrate to 1, but the .95 quantile is not reached in the rt column
PDFtoQuantiles(pred2, p=c(0.3, 0.5, 0.95), scaled=TRUE) # Gives a warning
## Demonstrate CDFtoQuantiles
X <- seq(-2, 2, length.out=300)
pdf_values <- pnorm(X)
CDFtoQuantiles(pdf_values, X, p=c(0.2, 0.5, 0.8))
qnorm(c(0.2, 0.5, 0.8))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.