psyfun.2asym | R Documentation |
Fits psychometric functions allowing for variation of both upper and lower asymptotes. Uses a procedure that alternates between fitting linear predictor with glm
and estimating the asymptotes with optim
until a minimum in -log likelihood is obtained within a tolerance.
psyfun.2asym(formula, data, link = logit.2asym, init.g = 0.01,
init.lam = 0.01, trace = FALSE, tol = 1e-06,
mxNumAlt = 50, ...)
formula |
a two sided formula specifying the response and the linear predictor |
data |
a data frame within which the formula terms are interpreted |
link |
a link function for the binomial family that allows specifying both upper and lower asymptotes |
init.g |
numeric specifying the initial estimate for the lower asymptote |
init.lam |
numeric specifying initial estimate for 1 - upper asymptote |
trace |
logical indicating whether to show the trace of the minimization of -log likelihood |
tol |
numeric indicating change in -log likelihood as a criterion for stopping iteration. |
mxNumAlt |
integer indicating maximum number of alternations between |
... |
additional arguments passed to |
The function is a wrapper for glm
for fitting psychometric functions with the equation
P(x) = \gamma + (1 - \gamma - \lambda) p(x)
where \gamma
is the lower asymptote and lambda
is 1 -
the upper asymptote, and p(x)
is the base psychometric function, varying between 0 and 1.
list of class ‘lambda’ inheriting from classes ‘glm’ and ‘lm’ and containing additional components
lambda |
numeric indicating 1 - upper asymptote |
gam |
numeric indicating lower asymptote |
SElambda |
numeric indicating standard error estimate for lambda based on the Hessian of the last interation of |
SEgam |
numeric indicating standard error estimate for gam estimated in the same fashion as |
If a diagonal element of the Hessian is sufficiently close to 0, NA
is returned.
The cloglog.2asym
and its alias, weib.2asym
, don't converge on
occasion. This can be observed by using the trace
argument.
One strategy is to modify the initial estimates.
Kenneth Knoblauch
Klein S. A. (2001) Measuring, estimating, and understanding the psychometric function: a commentary. Percept Psychophys., 63(8), 1421–1455.
Wichmann, F. A. and Hill, N. J. (2001) The psychometric function: I.Fitting, sampling, and goodness of fit. Percept Psychophys., 63(8), 1293–1313.
glm
, optim
, glm.lambda
, mafc
#A toy example,
set.seed(12161952)
b <- 3
g <- 0.05 # simulated false alarm rate
d <- 0.03
a <- 0.04
p <- c(a, b, g, d)
num.tr <- 160
cnt <- 10^seq(-2, -1, length = 6) # contrast levels
#simulated Weibull-Quick observer responses
truep <- g + (1 - g - d) * pweibull(cnt, b, a)
ny <- rbinom(length(cnt), num.tr, truep)
nn <- num.tr - ny
phat <- ny/(ny + nn)
resp.mat <- matrix(c(ny, nn), ncol = 2)
ddprob.glm <- psyfun.2asym(resp.mat ~ cnt, link = probit.2asym)
ddlog.glm <- psyfun.2asym(resp.mat ~ cnt, link = logit.2asym)
# Can fit a Weibull function, but use log contrast as variable
ddweib.glm <- psyfun.2asym(resp.mat ~ log(cnt), link = weib.2asym)
ddcau.glm <- psyfun.2asym(resp.mat ~ cnt, link = cauchit.2asym)
plot(cnt, phat, log = "x", cex = 1.5, ylim = c(0, 1))
pcnt <- seq(0.01, 0.1, len = 100)
lines(pcnt, predict(ddprob.glm, data.frame(cnt = pcnt),
type = "response"), lwd = 5)
lines(pcnt, predict(ddlog.glm, data.frame(cnt = pcnt),
type = "response"), lwd = 2, lty = 2, col = "blue")
lines(pcnt, predict(ddweib.glm, data.frame(cnt = pcnt),
type = "response"), lwd = 3, col = "grey")
lines(pcnt, predict(ddcau.glm, data.frame(cnt = pcnt),
type = "response"), lwd = 3, col = "grey", lty = 2)
summary(ddprob.glm)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.