psyfun.2asym: Fit Psychometric Functions and Upper and Lower Asymptotes

View source: R/psyfun.2asym.R

psyfun.2asymR Documentation

Fit Psychometric Functions and Upper and Lower Asymptotes

Description

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.

Usage

psyfun.2asym(formula, data, link = logit.2asym, init.g = 0.01, 
	init.lam = 0.01, trace = FALSE, tol = 1e-06, 
	mxNumAlt = 50, ...)

Arguments

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 glm and optim steps to perform if minimum not reached.

...

additional arguments passed to glm

Details

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.

Value

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 optim. The optimization is done on the value transformed by the function plogis and the value is stored in on this scale

SEgam

numeric indicating standard error estimate for gam estimated in the same fashion as SElambda

If a diagonal element of the Hessian is sufficiently close to 0, NA is returned.

Note

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.

Author(s)

Kenneth Knoblauch

References

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.

See Also

glm, optim, glm.lambda, mafc

Examples

#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)

psyphy documentation built on Aug. 19, 2023, 5:07 p.m.