basics

We are going to analize the data set qpdat, which is included in quickpsy. It has a tidy form: each column corresponds to a variable and each row to an observation.

To fit the psychometric functions (the default shape is the cumulative normal function), we use the main function of quickpsy, which has the name of the package. We introduce the data, the name of the explanatory variable, the name of the response variable and the name of the grouping variables.

library(quickpsy)

fit <- quickpsy(qpdat, phase, resp, grouping = c("participant", "cond")) 

quickpsy creates a object of class quickpsy with a list of data frames with all the results. We can use names to see the names of the output data frames

names(fit)
#>  [1] "x"                    "k"                    "n"                   
#>  [4] "guess"                "lapses"               "averages"            
#>  [7] "groups"               "funname"              "log"                 
#> [10] "psyfunguesslapses"    "limits"               "pariniset"           
#> [13] "parini"               "optimization"         "par"                 
#> [16] "pariniset"            "ypred"                "curves"              
#> [19] "sse"                  "thresholds"           "logliks"             
#> [22] "loglikssaturated"     "deviance"             "avbootstrap"         
#> [25] "parbootstrap"         "logliksboot"          "logliksbootsaturated"
#> [28] "devianceboot"         "aic"                  "parcomparisons"      
#> [31] "curvesbootstrap"      "thresholdsbootstrap"  "thresholdcomparisons"

To obtain the thresholds, for example, we can do

fit$thresholds
#>   participant cond      thre prob   threinf   thresup
#> 1          aa   -1 147.35236  0.5 136.70365 157.46304
#> 2          aa    1 114.58814  0.5 103.99970 124.58167
#> 3          bb   -1 162.26353  0.5 153.11444 172.99970
#> 4          bb    1 145.74502  0.5 136.79495 153.02431
#> 5          cc   -1  83.85067  0.5  72.74915  96.14488
#> 6          cc    1  91.49326  0.5  79.43000 102.14614

and to obtain the parameters

fit$par
#> # A tibble: 12 × 6
#> # Groups:   participant, cond [6]
#>    participant  cond parn    par parinf parsup
#>    <fct>       <int> <chr> <dbl>  <dbl>  <dbl>
#>  1 aa             -1 p1    147.   137.   157. 
#>  2 aa             -1 p2    107.    98.2  117. 
#>  3 aa              1 p1    115.   104.   125. 
#>  4 aa              1 p2    106.    93.6  116. 
#>  5 bb             -1 p1    162.   153.   173. 
#>  6 bb             -1 p2     85.7   76.3   93.8
#>  7 bb              1 p1    146.   137.   153. 
#>  8 bb              1 p2     69.3   61.9   75.8
#>  9 cc             -1 p1     83.9   72.7   96.1
#> 10 cc             -1 p2    139.   126.   157. 
#> 11 cc              1 p1     91.5   79.4  102. 
#> 12 cc              1 p2    139.   127.   153.

We can use plot to plot the psychometric curves

plot(fit)
#> Warning in geom_errorbarh(data = qp$thresholds, height = 0.03, aes_string(x =
#> "threinf", : Ignoring unknown aesthetics: x

or if we want to used different colors for the different conditions

plot(fit, color = cond)
#> Warning in geom_errorbarh(data = qp$thresholds, height = 0.03, aes_string(x =
#> "threinf", : Ignoring unknown aesthetics: x

The output plot is a ggplot and we can modify it accordingly. For example

library(ggplot2)

plot(fit, color = cond) +
  labs(y = "Proportion") +
  theme_minimal()
#> Warning in geom_errorbarh(data = qp$thresholds, height = 0.03, aes_string(x =
#> "threinf", : Ignoring unknown aesthetics: x

Of course, we can also use the output data frames to create the plot ourselves

 ggplot() +
  facet_wrap(~ participant) +
  geom_line(data = fit$curvesbootstrap, 
            aes(x = x, y = y, color = cond, 
                group=paste(sample, cond)), lwd = .2, alpha = .4) +
  geom_line(data = fit$curves, aes(x = x, y = y, group = cond)) +
  geom_point(data = fit$averages, aes(x = phase, y = prob), size = 2) +
  geom_point(data = fit$averages, aes(x = phase, y = prob, color = cond))