Psychometric Function

There are several packages to fit the psychometric function in R, for the single subject analysis. Among others: psyphy, quickpsy, MPDiR. See CRAN Task View: Psychometric Models and Methods for an overview of the different packages. Now, I also included a simple function for the analysis of single subject data in MERpsychophysics.

The function is called psych.function. Model fitting is based on glm. The function plot the fitted model on an existing plot and provides an estimate of the PSE, the JND and the related confidence intervals. These estimates are computed via delta method. I chose to add the fitted model to an existing plot, so that the user can customize the plot layout using par. Several participant and/or conditions can be added to the plot by recursive usage of the function (see the example below).


#this ensure that your output will match mine

#this is to simulate data (one subject)
datafr.S1 <- MERsimulate(fixeff = c(-7.5, 0.0875), nsubject = 1,
                         constant = T)     

#psychometric function to fit single-subject data
plot(Longer/Total ~ X, data = datafr.S1)
fit.S1 = psych.function(ps.formula = cbind(Longer, Total - Longer) ~ X,
               = "probit", = datafr.S1,
                        x.range = c(40, 120), ps.lines = T)

#this simulates a second participant
datafr.S2 <- MERsimulate(fixeff = c(-6.8, 0.0875), nsubject = 1,
                         constant = T)     
points(Longer/Total ~ X, data = datafr.S2, col = "red")
fit.S2 = psych.function(ps.formula = cbind(Longer, Total - Longer) ~ X,
               = "probit", = datafr.S2, 
                         x.range = c(40, 120), ps.lines = T,
                         ps.col = "red")

This is the plot generated by the R code above (see also MERdemo.R). Each participant is plotted in a different color. The line segment on the curve is the 95% confidence interval of the PSE estimated via delta method. For the moment it only works with uni-variable models, you can use the standard R function glm to fit multivariable models.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: