| Title: | Fits Psychometric Functions for Multiple Groups |
|---|---|
| Description: | Quickly fits and plots psychometric functions (normal, logistic, Weibull or any function defined by the user) for multiple groups. |
| Authors: | Daniel Linares [aut, cre], Joan López-Moliner [aut] |
| Maintainer: | Daniel Linares <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-05-28 07:58:34 UTC |
| Source: | https://github.com/danilinares/quickpsy |
akaike calculates the loglikelihoods.Calculates the Akaike Information Criterion
akaike calculates the loglikelihoods.
akaike(logliks)akaike(logliks)
logliks |
The |
avbootstrap creates bootstrap samples
avbootstrap(averages, ypred, bootstrap, B)avbootstrap(averages, ypred, bootstrap, B)
averages |
The |
ypred |
The |
bootstrap |
|
B |
number of bootstrap samples (default is 100 ONLY). |
create_psy_fun creates the psychometric functionCreates the psychometric function
create_psy_fun creates the psychometric function
create_psy_fun(psy_fun, guess, lapses)create_psy_fun(psy_fun, guess, lapses)
psy_fun |
The shape of the function without guesses and lapses. |
guess |
Value indicating the guess rate (leftward asymptote) |
lapses |
Value indicating the lapse rate (rightward asymptote) |
Cumulative normal function.
cum_normal_fun(x, p)cum_normal_fun(x, p)
x |
Vector of values of the explanatory variable. |
p |
Vector of parameters |
Probability at each x.
library(ggplot2) xseq <- seq(0,4,.01) yseq <- cum_normal_fun(xseq, c(2, .5)) curve <- data.frame(x = xseq, y = yseq) ggplot2::ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) xseq <- seq(0,4,.01) yseq <- cum_normal_fun(xseq, c(2, .5)) curve <- data.frame(x = xseq, y = yseq) ggplot2::ggplot(curve, aes(x = x, y = y)) + geom_line()
devi calculates the deviance
devi(logliks, loglikssaturated, grouping_without_fun)devi(logliks, loglikssaturated, grouping_without_fun)
logliks |
The |
loglikssaturated |
The |
grouping_without_fun |
The |
getfunctions lists the predefined functions in quickpsy.
get_functions()get_functions()
cum_normal_fun,
logistic_fun,
weibull_fun
Inverse cumulative normal function
inv_cum_normal_fun(prob, p)inv_cum_normal_fun(prob, p)
prob |
Vector of probabilities. |
p |
Vector of parameters |
x at each probability.
#' @seealso cum_normal_fun
library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_cum_normal_fun(yseq, c(2, .5)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_cum_normal_fun(yseq, c(2, .5)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()
Inverse logistic function
inv_logistic_fun(q, p)inv_logistic_fun(q, p)
q |
Vector of probabilities. |
p |
Vector of parameters |
x at each probability.
library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_logistic_fun(yseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_logistic_fun(yseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()
Inverse Weibull function
inv_weibull_fun(q, p)inv_weibull_fun(q, p)
q |
Vector of probabilities. |
p |
Vector of parameters p = c(alpha, beta). |
x at each probability.
library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_weibull_fun(yseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) yseq <- seq(0, 1, .01) xseq <- inv_weibull_fun(yseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()
Logistic function of the form
logistic_fun(x, p)logistic_fun(x, p)
x |
Vector of values of the explanatory variable. |
p |
Vector of parameters |
Probability at each x.
library(ggplot2) xseq <- seq(0, 4, .01) yseq <- logistic_fun(xseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) xseq <- seq(0, 4, .01) yseq <- logistic_fun(xseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()
logliks calculates the loglikelihoods.Calculates the loglikelihoods
logliks calculates the loglikelihoods.
logliks(nll_fun, param, grouping_without_fun)logliks(nll_fun, param, grouping_without_fun)
nll_fun |
The |
param |
The |
grouping_without_fun |
The |
logliks calculates the saturatedloglikelihoods.Calculates the saturated loglikelihoods
logliks calculates the saturatedloglikelihoods.
loglikssaturated(nll_fun_saturated, averages, grouping_without_fun)loglikssaturated(nll_fun_saturated, averages, grouping_without_fun)
nll_fun_saturated |
The |
averages |
The |
grouping_without_fun |
The |
The p indicates the relative probability of the models.
model_selection_aic(aic1, aic2)model_selection_aic(aic1, aic2)
aic1 |
The |
aic2 |
The |
Select models using the likelihood ratio test
model_selection_lrt(loglik1, loglik2, alpha = 0.05)model_selection_lrt(loglik1, loglik2, alpha = 0.05)
loglik1 |
The |
loglik2 |
The |
alpha |
The significance level. |
plotcurves plot the curves.
plotcurves( qp, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, averages = TRUE, curves = TRUE, thresholds = TRUE, ci = TRUE )plotcurves( qp, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, averages = TRUE, curves = TRUE, thresholds = TRUE, ci = TRUE )
qp |
output from quickpsy |
panel |
Name of the variable to be split in panels. |
xpanel |
Name of the variable to be split in horizontal panels. |
ypanel |
Name of the variable to be split in vertical panels. |
color |
Name of the variable codded by color. |
averages |
If |
curves |
If |
thresholds |
If |
ci |
If |
plotpar plot the values of the parameters.
plotpar( qp, x = NULL, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, geom = "bar", ci = T )plotpar( qp, x = NULL, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, geom = "bar", ci = T )
qp |
output from quickpsy. |
x |
Name of the variable to displayed in the x-axis. |
panel |
Name of the variable to be split in panels. |
xpanel |
Name of the variable to be split in horizontal panels. |
ypanel |
Name of the variable to be split in vertical panels. |
color |
Name of the variable codded by color. |
geom |
If |
ci |
If |
fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plot(fit) plot(fit, color = cond) plotpar(fit) plotthresholds(fit, geom = "point")fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plot(fit) plot(fit, color = cond) plotpar(fit) plotthresholds(fit, geom = "point")
plotthresholds plot the thresholds.
plotthresholds( qp, x = NULL, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, geom = "bar", ci = T, sizeerrorbar = 0.5 )plotthresholds( qp, x = NULL, panel = NULL, xpanel = NULL, ypanel = NULL, color = NULL, geom = "bar", ci = T, sizeerrorbar = 0.5 )
qp |
output from quickpsy. |
x |
Name of the variable to displayed in the x-axis. |
panel |
Name of the variable to be split in panels. |
xpanel |
Name of the variable to be split in horizontal panels. |
ypanel |
Name of the variable to be split in vertical panels. |
color |
Name of the variable codded by color. |
geom |
If |
ci |
If |
sizeerrorbar |
Line width of the error bars.
If |
fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plotthresholds(fit)fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plotthresholds(fit)
Print quickpsy objects
## S3 method for class 'quickpsy' print(x, ...)## S3 method for class 'quickpsy' print(x, ...)
x |
A quickpsy object. |
... |
Other arguments |
The data set is part of the data associated with the paper "Linares, D., & Lopez-Moliner, J. (2006). Perceptual asynchrony between color and motion with a single direction change. Journal of Vision, 6(9), 10-10".
qpdatqpdat
An object of class tbl_df (inherits from tbl, data.frame) with 1280 rows and 5 columns.
quickpsy fits, by direct maximization of the likelihood
(Prins and Kingdom, 2010; Knoblauch and Maloney, 2012),
psychometric functions of the form
where is the guess rate, is the lapse rate and
is a sigmoidal-shape function with asymppotes at 0 and 1.
quickpsy( d, x = x, k = k, n = NULL, grouping = c(), xmin = NULL, xmax = NULL, log = FALSE, fun = cum_normal_fun, parini = NULL, guess = 0, lapses = 0, prob = NULL, thresholds = TRUE, bootstrap = "parametric", B = 100, ci = 0.95, control = NULL, parinivector = NULL, paircomparisons = FALSE )quickpsy( d, x = x, k = k, n = NULL, grouping = c(), xmin = NULL, xmax = NULL, log = FALSE, fun = cum_normal_fun, parini = NULL, guess = 0, lapses = 0, prob = NULL, thresholds = TRUE, bootstrap = "parametric", B = 100, ci = 0.95, control = NULL, parinivector = NULL, paircomparisons = FALSE )
d |
Data frame with a tidy form in which each column corresponds to a variable and each row is an observation. |
x |
Name of the explanatory variable. |
k |
Name of the response variable. It could be the number of trials in which a yes-type response was given or a vector of 0s (no-type response) and 1s (yes-type response) indicating the response on each trial. |
n |
Only necessary if |
grouping |
Name of the grouping variables. It should be specified as
|
xmin |
Minimum value of the explanatory variable for which the curves should be calculated (the default is the minimum value of the explanatory variable). |
xmax |
Maximum value of the explanatory variable for which the curves should be calculated (the default is the maximum value of the explanatory variable). |
log |
If |
fun |
Name of the shape of the curve to fit. It could be a predefined
shape ( |
parini |
Initial parameters. quickpsy calculates default
initial parameters for the predefined functions by linear modelling of
the probit-transformed data. Otherwise,
|
guess |
Value indicating the guess rate (leftward asymptote) |
lapses |
Value indicating the lapse rate (rightward asymptote) |
prob |
Probability to calculate the threshold (default is
|
thresholds |
If |
bootstrap |
|
B |
number of bootstrap samples (default is 100 ONLY). |
ci |
Bootstrap confidence intervals level based on percentiles (default is .95). |
control |
|
parinivector |
A optional vector of initials parameters when the lower and the upper bounds of the parameter are specified. |
paircomparisons |
If |
A list containing the following components:
x, k, n
grouping The grouping variables.
funname String with the name of the shape of the curve.
psyfunguesslapses Curve including guess and lapses.
limits Limits of the curves.
parini Initial parameters.
ypred Predicted probabilities at the values of the explanatory
variable.
curves Psychometric curves.
par Fitted parameters and its confidence intervals.
parcomnparisons Pair-wise comparisons of the parameters
to assess whether two parameters are significantly different
using bootstrap. Specifically, the parameter bootstrap samples for each of
the two conditions are substrated and then it is considered whether zero
was within the confidence interval level of the distributions of differences.
curvesbootstrap Bootstrap psychometric curves.
thresholds Thresholds and its confidence intervals.
thresholdscomparisons Pair-wise comparisons of the thresholds.
logliks Log-likelihoods of the model.
loglikssaturated Log-likelihoods of the saturated model.
deviance Deviance of the model and the p-value calculated by
using the chi-square distribution and bootstraping.
aic AIC of the model defined as
where k is the number of parameters of the model.
Burnham, K. P., & Anderson, D. R. (2003). Model selection and multimodel inference: a practical information-theoretic approach. Springer Science & Business Media.
Knoblauch, K., & Maloney, L. T. (2012). Modeling Psychophysical Data in R. New York: Springer.
Prins, N., & Kingdom, F. A. A. (2016). Psychophysics: a practical introduction. London: Academic Press.
library(quickpsy) fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plot(fit) plot(fit, color = cond) plotpar(fit) plotthresholds(fit, geom = "point")library(quickpsy) fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond"), bootstrap = "none") plot(fit) plot(fit, color = cond) plotpar(fit) plotthresholds(fit, geom = "point")
quickreadfiles builts a data frame from several txt files. It
assumes that in each file, the first row has the names of the variables.
quickreadfiles(path = getwd(), extension = "txt", ...)quickreadfiles(path = getwd(), extension = "txt", ...)
path |
Path of the file (default is the working directory). |
extension |
Specify whether the file extension is 'txt' or 'csv'. |
... |
arguments of the form name_var = c('value1', 'value2',..). A new column with variable name name_var is addes to the data frame. |
# download the 3 files in # https://github.com/danilinares/quickpsy/tree/master/inst/extdata/example1 # and add them to your working directory # dat <- quickreadfiles(subject = c('aa', 'bb', 'cc'), session = c('1', '2')) # fit <- quickpsy(dat, phase, resp, grouping=.(subject), lapses = T, guess = T) # plotcurves(fit)# download the 3 files in # https://github.com/danilinares/quickpsy/tree/master/inst/extdata/example1 # and add them to your working directory # dat <- quickreadfiles(subject = c('aa', 'bb', 'cc'), session = c('1', '2')) # fit <- quickpsy(dat, phase, resp, grouping=.(subject), lapses = T, guess = T) # plotcurves(fit)
Weibull function of the form
weibull_fun(x, p)weibull_fun(x, p)
x |
Vector of values of the explanatory variable. |
p |
Vector of parameters |
Probability at each x.
library(ggplot2) xseq <- seq(0, 4, .01) yseq <- weibull_fun(xseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()library(ggplot2) xseq <- seq(0, 4, .01) yseq <- weibull_fun(xseq, c(2, 4)) curve <- data.frame(x = xseq, y = yseq) ggplot(curve, aes(x = x, y = y)) + geom_line()
Creates sequences of x's
x_seq(limits, x, grouping)x_seq(limits, x, grouping)
limits |
The |
x |
The |
grouping |
The |
ypred calculates the predicted probabilities at the values of the
explanatory variable.
ypred( averages, param, psych_fun, x_str, log, grouping, grouping_without_fun, grouping_fun, funname, guess, lapses )ypred( averages, param, psych_fun, x_str, log, grouping, grouping_without_fun, grouping_fun, funname, guess, lapses )
averages |
The |
param |
The |
psych_fun |
The |
x_str |
The |
log |
The |
grouping |
The |
grouping_without_fun |
The |
grouping_fun |
The |
funname |
The |
guess |
Argument |
lapses |
Argument |