quickpsy
fits, by direct maximization of the likelihood
(Prins and Kingdom, 2010; Knoblauch and Maloney, 2012),
psychometric functions of the form
$$\psi(x) = \gamma + (1 - \gamma - \lambda) * fun(x)$$
where \(\gamma\) is the guess rate, \(\lambda\) is the lapse rate and
\(fun\) is a sigmoidal-shape function with asymptotes at 0 and 1.
quickpsy(d, x = x, k = k, n = n, grouping, random, within, between,
xmin = NULL, xmax = NULL, log = FALSE, fun = cum_normal_fun,
parini = NULL, guess = 0, lapses = 0, prob = NULL, thresholds = T,
bootstrap = "parametric", B = 100, ci = 0.95, optimization = "optim")
Data frame with the results of a Yes-No experiment to fit. It should have a tidy form in which each column corresponds to a variable and each row is an observation.
Name of the explanatory variable.
Name of the response variable. The response variable could be the number of trials in which a yes-type response was given or a vector of 0s (or -1s; no-type response) and 1s (yes-type response) indicating the response on each trial.
Only necessary if k
refers to the number of trials
in which a yes-type response was given. It corresponds to the name of the
variable indicating the total number of trials.
Name of the grouping variables. It should be specified as
grouping = .(variable_name1, variable_name2)
.
Name of the random variable. It should be specified as
random = .(variable_name1, variable_name2)
. In the current version
of quickpsy, the random variable has not special treatment. It does the
same as grouping
.
Name of the within variable. It should be specified as
within = .(variable_name1, variable_name2)
. In the current version
of quickpsy, the within variable has not special treatment. It does the
same as grouping
.
Name of the between variable. It should be specified as
between = .(variable_name1, variable_name2)
. In the current version
of quickpsy, the between variable has not special treatment. It does the
same as grouping
.
Minimum value of the explanatory variable for which the curves should be calculated (the default is the minimum value of the explanatory variable).
Maximum value of the explanatory variable for which the curves should be calculated (the default is the maximum value of the explanatory variable).
If TRUE
, the logarithm of the explanatory variable is used
to fit the curves (default is FALSE
).
Name of the shape of the curve to fit. It could be a predefined
shape (cum_normal_fun
, logistic_fun
, weibull_fun
)
or the name of a function introduced by the user
(default is cum_normal_fun
).
Initial parameters. quickpsy calculates default
initial parameters using probit analysis, but it is also possible to
specify a vector of initial parameters or a list of the form
list(c(par1min, par1max), c(par2min, par2max))
to
constraint the lower and upper bounds of the parameters (when
optimization = 'DE'
, parini should be also a list).
Value indicating the guess rate \(\gamma\) (default is 0). If
TRUE
, the guess rate is estimated as the i + 1 paramEter where
i corresponds to the number of parameters of fun
. If, for
example, fun
is a predefined shape with parameters p1 and p2,
then the guess rate corresponds to parameter p3.
Value indicating the lapse rate \(\lambda\) (default is 0).
If TRUE
, the lapse rate is estimated as the i + 1 parameter where
i corresponds to the number of parameters of fun
plus one if
the guess rate is estimated. If, for example, fun
is a
predefined shape with parameters p1 and p2,
then the lapse rate corresponds to parameter p3. If the guess rate is also
estimated, p3 will be the guess rate and p4 the lapse rate.
Probability to calculate the threshold (default is
guess + .5 * (1 - guess)
).
If FALSE
, thresholds are not calculated
(default is TRUE
).
'parametric'
performs parametric bootstrap;
'nonparametric'
performs non-parametric bootstrap;
'none'
does not perform bootstrap (default is 'parametric'
).
number of bootstrap samples (default is 100 ONLY).
Confidence intervals level based on percentiles (default is .95).
Method used for optimization. The default is 'optim' which uses
the optim
function. It can also be 'DE'
which uses de function
DEoptim
from the package DEoptim, which performs differential
evolution optimization. By using DEoptim
, it is less likely that the
optimization finishes in a local minimum, but the optimization is slow.
When 'DE'
is used, parini
should be specified as a list with
lower and upper bounds.
A list containing the following components:
x, k, n
groups
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.
optimization
Method to optimize.
pariniset
FALSE
if initial parameters are not given.
ypred
Predicted probabilities at the values of the explanatory
variable.
curves
Curves.
par
Fitted parameters and its confidence intervals.
curvesbootstrap
Bootstrap curves.
thresholds
Thresholds.
thresholdsci
Confidence intervals for 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
bootstraping.
aic
AIC of the model defined as $$ - 2 * loglik + 2 *k$$
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.
# NOT RUN {
# make sure that all the requires packages are installed
# and loaded; instructions at https://github.com/danilinares/quickpsy
library(MPDiR) # contains the Vernier data; use ?Vernier for the reference
fit <- quickpsy(Vernier, Phaseshift, NumUpward, N,
grouping = .(Direction, WaveForm, TempFreq), B = 10)
plotcurves(fit)
plotpar(fit)
plotthresholds(fit, geom = 'point')
# }
Run the code above in your browser using DataLab