A: An A function

View source: R/A.R

AR Documentation

An A function

Description

This function allows you to calculate A from from a vector hits and a vector a false alarms.

Usage

A(data, h, f)

Arguments

data

A data frame.

h

A vector of hits (0 = miss, 1 = hit).

f

A vector of false alarms (0 = correct rejection, 1 = false alarm).

Examples

# Create some data
set.seed(1); library(dplyr)
axb <- data.frame(subj = sort(rep(1:10, each = 20, times = 10)),
                  group = gl(2, 1000, labels = c("g1", "g2")),
                  hit = c(rbinom(1000, size = c(0, 1), prob = .8), 
                          rbinom(1000, size = c(0, 1), prob = .6)),
                  fa =  c(rbinom(1000, size = c(0, 1), prob = .3), 
                          rbinom(1000, size = c(0, 1), prob = .4))
)

# Calculate A on entire data frame
A(axb, hit, fa)

# Calculate A for each subject
# by group, plot it, and run a 
# linear model
axb %>%
  group_by(subj, group) %>%
  summarize(A = A(., hit, fa)) %T>%
 {
  plot(A ~ as.numeric(group), data = ., 
       main = "A as a function of group", xaxt = "n", 
       xlab = "Group", ylab = "A")
  axis(1, at = 1:2, labels = c("g1", "g2"))
  abline(lm(A ~ as.numeric(group), data = .), col = "red")
 } %>%
 lm(A ~ group, data = .) %>%
 summary()

jvcasill/lingStuff documentation built on Jan. 5, 2025, 6:32 a.m.