Remove cardinal biases

remove_cardinal_biases(
  err,
  x,
  space = "180",
  bias_type = "fit",
  do_plot = FALSE,
  poly_deg = 4,
  var_sigma = TRUE,
  var_sigma_poly_deg = 4,
  reassign_at_boundaries = TRUE,
  reassign_range = 2,
  debug = FALSE
)

Arguments

err

a vector of errors, deviations of response from the true stimuli

x

a vector of true stimuli in degrees (see space)

space

circular space to use (a string: '180' or '360')

bias_type

bias type to use ('fit', 'card', or 'obl', see details)

do_plot

show plots (default: False)

poly_deg

degree of the fitted polynomials for each bin (default: 4)

var_sigma

allow standard deviation (width) of the fitted response distribution to vary as a function of distance to the nearest cardinal (default: True)

var_sigma_poly_deg

degree of the fitted polynomials for each bin for the first approximation for the response distribution to select the best fitting model (default: 4)

reassign_at_boundaries

select the bin for the observations at the boundaries between bins based on the best-fitting polynomial (default: True)

reassign_range

maximum distance to the boundary at which reassignment can occur (default: 2 degrees)

debug

print some extra info (default: False)

Value

a list with the follwing elements:

  • is_outlier - 0 for outliers (defined as ±3*pred_sigma for the model with varying sigma or as ±3\*SD for the simple model)

  • pred predicted error

  • be_c error corrected for biases (be_c = observed error - pred)

  • which_bin the numeric ID of the bin that the stimulus belong to

  • bias the bias computed as described above

  • bias_typ bias type (cardinal or oblique)

  • pred_lin predicted error for a simple linear model for comparison

  • pred_sigma predicted SD of the error distribution

  • coef_sigma_int, coef_sigma_slope intercept and slope for the sigma prediction

Details

If the bias_type is set to 'fit', the function computes the cardinal biases in the following way:

  1. Create two sets of bins, splitting the stimuli vector into bins centered at cardinal and at oblique directions.

  2. For each set of bins, fit a nth-degree polynomial for the responses in each bin, optionally allowing the distribution of responses to vary in width as a function of distance to the nearest cardinal (regardless of whether the bins are centered at the cardinal or at the oblique, the width of the response distribution usually increases as the distance to cardinals increase).

  3. Choose the best-fitting model between the one using cardinal and the one using oblique bins.

  4. Compute the residuals of the best-fitting model - that's your bias-corrected error - and the biases (see below).

The bias is computed by flipping the sign of errors when the average predicted error is negative, so, that, for example, if on average the responses are shifted clockwise relative to the true values, the trial-by-trial error would count as bias when it is also shifted clockwise.

If bias_type is set to 'obl' or 'card', only one set of bins is used, centred at cardinal or oblique angles, respectively.

Examples


# Data in orientation domain from Pascucci et al. (2019, PLOS Bio),
# https://doi.org/10.5281/zenodo.2544946

Pascucci_et_al_2019_data[observer==4, remove_cardinal_biases(err, orientation, do_plot = TRUE)]
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  

#>      is_outlier        pred        be_c which_bin bias bias_type    pred_lin
#>   1:          0  7.61511861  -4.6151186         2    3       obl   7.8012240
#>   2:          0  0.01464459   0.9853554         2    1       obl  -0.4583498
#>   3:          0  1.57619824  -4.5761982         2   -3       obl   0.6074016
#>   4:          0 -7.99617928   9.9961793         1   -2       obl  -9.7661382
#>   5:          0 -9.02293124   1.0229312         2    8       obl  -6.3199829
#>  ---                                                                        
#> 436:          0 -3.77707309   2.7770731         1    1       obl  -1.2667688
#> 437:          0 -8.73979472 -10.2602053         2   19       obl -11.3823023
#> 438:          1 -8.00644915  22.0064492         2  -14       obl  -5.5206693
#> 439:          0  1.94308815  -2.9430882         2   -1       obl   0.8738395
#> 440:          0 -1.66717180   0.6671718         2    1       obl  -1.5241013
#>      pred_sigma coef_sigma_int coef_sigma_slope
#>   1:   6.512993       1.797793     0.0050670450
#>   2:   7.543931       1.797793     0.0050670450
#>   3:   7.467866       1.797793     0.0050670450
#>   4:   6.259090       1.831048     0.0004266147
#>   5:   6.748150       1.797793     0.0050670450
#>  ---                                           
#> 436:   6.331603       1.831048     0.0004266147
#> 437:   6.128773       1.797793     0.0050670450
#> 438:   6.851513       1.797793     0.0050670450
#> 439:   7.430121       1.797793     0.0050670450
#> 440:   7.392568       1.797793     0.0050670450

# Data in motion domain from Bae & Luck (2018, Neuroimage), https://osf.io/2h6w9/
Bae_Luck_2018_data[subject_Num == unique(subject_Num)[5],
remove_cardinal_biases(err, TargetDirection, space = '360', do_plot = TRUE)]
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  
#> Warning: There is a discrepancy  between the original and the re-fit 
#>  used to achieve 'safe' predictions 
#>  

#>       is_outlier       pred         be_c which_bin    bias bias_type  pred_lin
#>    1:          1 -9.3654115  178.7654115         1 -169.40       obl -4.721015
#>    2:          0 -2.9754759   -3.0245241         1    6.00       obl -4.189975
#>    3:          1 -5.0711403  182.6211403         1 -177.55       obl -3.757276
#>    4:          0 -9.6351780  -31.3648220         1   41.00       obl -4.957033
#>    5:          1 -4.6613521 -170.2886479         4  174.95       obl -8.544710
#>   ---                                                                         
#> 1276:          0 -5.4649867   -0.5350133         4    6.00       obl -2.399848
#> 1277:          0 -1.2347871    3.2347871         3   -2.00       obl -1.006986
#> 1278:          0 -0.6550139  -12.6449861         3   13.30       obl -3.046211
#> 1279:          0 -2.3714867    9.3714867         1   -7.00       obl -3.914621
#> 1280:          1  3.7430472 -179.9430472         2 -176.20       obl 10.585121
#>       pred_sigma coef_sigma_int coef_sigma_slope
#>    1:   13.15107       2.738580     -0.004502117
#>    2:   13.69488       2.738580     -0.004502117
#>    3:   15.12076       2.738580     -0.004502117
#>    4:   13.88111       2.738580     -0.004502117
#>    5:   14.58627       2.675535      0.002272586
#>   ---                                           
#> 1276:   15.47410       2.675535      0.002272586
#> 1277:   27.72277       2.502993      0.021616388
#> 1278:   13.46733       2.502993      0.021616388
#> 1279:   14.58585       2.738580     -0.004502117
#> 1280:   13.88315       2.548749      0.013654507