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

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/psyfun.2asym.R

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

1
2
3
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) = γ + (1 - γ - λ) p(x)

where γ 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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)

Example output

lambda = 	 0.03925493 	 gamma =  0.03493802 
+/-SE(lambda) = 	( 0.02934807 0.05232571 )
+/-SE(gamma) = 	( 0.02279067 0.05320733 )
lambda = 	 0.03714186 	 gamma =  0.02783269 
+/-SE(lambda) = 	( 0.02736269 0.05023549 )
+/-SE(gamma) = 	( 0.01607455 0.04777402 )
lambda = 	 0.04019859 	 gamma =  0.05260859 
+/-SE(lambda) = 	( 0.03024818 0.05324256 )
+/-SE(gamma) = 	( 0.03972724 0.06936494 )
lambda = 	 2.967282e-11 	 gamma =  4.009714e-16 
+/-SE(lambda) = 	( NA NA )
+/-SE(gamma) = 	( NA NA )

Call:
glm(formula = formula, family = binomial(probit.2asym(g = p[1], 
    lam = p[2])), data = data)

Deviance Residuals: 
      1        2        3        4        5        6  
-0.6125   0.9416  -0.1750  -0.4253   1.0013  -0.6723  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -2.6647     0.2069  -12.88   <2e-16 ***
cnt          76.0351     6.4397   11.81   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 642.5813  on 5  degrees of freedom
Residual deviance:   2.9279  on 2  degrees of freedom
AIC: 33.717

Number of Fisher Scoring iterations: 8

lambda	 0.0393 	gamma	 0.0349 
+/-SE(lambda) = 	( 0.02934807 0.05232571 )
+/-SE(gamma) = 	( 0.02279067 0.05320733 )

psyphy documentation built on Nov. 10, 2020, 3:49 p.m.