Author: Nicholas Maxwell, Erin Buchanan
Date: 2021-12-06

# Cued Recall Example

#### Nicholas Maxwell, Erin Buchanan

#### 2021-12-06

# Libraries and Data

Please see manuscript for a long description of the following data. We will load the example data, and you can use the `?` with the dataset name to learn more about the data.

    library(lrd)
    #>
    #> Attaching package: 'lrd'
    #> The following object is masked from 'package:base':
    #>
    #>     kappa
    data("cued_recall_manuscript")
    head(cued_recall_manuscript)
    #>   Sub.ID Trial_num          Cue      Target      Answer
    #> 1      1         1 chlorination ideological ideological
    #> 2      1         2        bendy   financial   financial
    #> 3      1         3   topography     editing     editing
    #> 4      1         4      enquiry     buzzing     buzzing
    #> 5      1         5    draconian   statistic   statistic
    #> 6      1         6    speedball   stopwatch   stopwatch
    #?cued_recall_manuscript

# Data Cleanup

Scoring in `lrd` is case sensitive, so we will use `tolower()` to lower case all correct answers and participant answers.

    cued_recall_manuscript$Target <- tolower(cued_recall_manuscript$Target)
    cued_recall_manuscript$Answer <- tolower(cued_recall_manuscript$Answer)

# Score the Data

You should define the following:

- data = dataframe of participant responses
- responses = column name of the participant answers
- key = column name of the answer key
- key.trial = column name of the trial id code
- id = column name of the participant id number
- id.trial = column name of the trial id within the participant data
- cutoff = the Levenshtein distance value you want to use for scoring (0 no changes exactly the same, higher numbers allow more variance in the word)
- flag = calculate z scores for outliers (TRUE/FALSE)
- group.by = column name(s) for grouping variables

Note that the answer key can be in a separate dataframe, use something like `answer_key$answer` for the key argument and `answer_key$id_num` for the trial number. Fill in `answer_key` with your dataframe name and the column name for those columns after the `$`.

    cued_output <- prop_correct_cued(data = cued_recall_manuscript,
                                     responses = "Answer",
                                     key = "Target",
                                     key.trial = "Trial_num",
                                     id = "Sub.ID",
                                     id.trial = "Trial_num",
                                     cutoff = 1,
                                     flag = TRUE,
                                     group.by = NULL)

    str(cued_output)
    #> List of 2
    #>  $ DF_Scored     :'data.frame':  120 obs. of  7 variables:
    #>   ..$ Trial.ID : int [1:120] 1 1 1 1 1 1 2 2 2 2 ...
    #>   ..$ Sub.ID   : int [1:120] 1 3 5 2 4 6 6 5 2 1 ...
    #>   ..$ Cue      : chr [1:120] "chlorination" "chlorination" "chlorination" "chlorination" ...
    #>   ..$ Target   : chr [1:120] "ideological" "ideological" "ideological" "ideological" ...
    #>   ..$ Responses: chr [1:120] "ideological" "ideological" "ideological" "idological" ...
    #>   ..$ Answer   : chr [1:120] "ideological" "ideological" "ideological" "ideological" ...
    #>   ..$ Scored   : num [1:120] 1 1 1 1 1 0 0 0 1 1 ...
    #>  $ DF_Participant:'data.frame':  6 obs. of  3 variables:
    #>   ..$ Sub.ID             : int [1:6] 1 2 3 4 5 6
    #>   ..$ Proportion.Correct : num [1:6] 1 0.8 0.85 0.95 0.75 0.45
    #>   ..$ Z.Score.Participant: num [1:6, 1] 1.026 0 0.256 0.769 -0.256 ...
    #>   .. ..- attr(*, "scaled:center")= num 0.8
    #>   .. ..- attr(*, "scaled:scale")= num 0.195

# Output

We can use `DF_Scored` to see the original dataframe with our new scored column - also to check if our answer key and participant answers matched up correctly! The `DF_Participant` can be used to view a participant level summary of the data. Last, if a grouping variable is used, we can use `DF_Group` to see that output.

    #Overall
    cued_output$DF_Scored
    #>     Trial.ID Sub.ID              Cue       Target    Responses       Answer
    #> 1          1      1     chlorination  ideological  ideological  ideological
    #> 2          1      3     chlorination  ideological  ideological  ideological
    #> 3          1      5     chlorination  ideological  ideological  ideological
    #> 4          1      2     chlorination  ideological   idological  ideological
    #> 5          1      4     chlorination  ideological  ideologicel  ideological
    #> 6          1      6     chlorination  ideological               ideological
    #> 7          2      6            bendy    financial        money    financial
    #> 8          2      5            bendy    financial        money    financial
    #> 9          2      2            bendy    financial    financial    financial
    #> 10         2      1            bendy    financial    financial    financial
    #> 11         2      3            bendy    financial    financial    financial
    #> 12         2      4            bendy    financial    finenciel    financial
    #> 13         3      5       topography      editing      editing      editing
    #> 14         3      3       topography      editing     editting      editing
    #> 15         3      6       topography      editing      editing      editing
    #> 16         3      1       topography      editing      editing      editing
    #> 17         3      4       topography      editing      editing      editing
    #> 18         3      2       topography      editing       diting      editing
    #> 19         4      5          enquiry      buzzing      buzzing      buzzing
    #> 20         4      3          enquiry      buzzing      buzzing      buzzing
    #> 21         4      6          enquiry      buzzing      buzzing      buzzing
    #> 22         4      1          enquiry      buzzing      buzzing      buzzing
    #> 23         4      4          enquiry      buzzing      buzzing      buzzing
    #> 24         4      2          enquiry      buzzing      buzzing      buzzing
    #> 25         5      5        draconian    statistic    statistic    statistic
    #> 26         5      3        draconian    statistic sttattisttic    statistic
    #> 27         5      6        draconian    statistic         math    statistic
    #> 28         5      1        draconian    statistic    statistic    statistic
    #> 29         5      4        draconian    statistic    stetistic    statistic
    #> 30         5      2        draconian    statistic    statistic    statistic
    #> 31         6      3        speedball    stopwatch  sttopwattch    stopwatch
    #> 32         6      4        speedball    stopwatch    stopwetch    stopwatch
    #> 33         6      6        speedball    stopwatch        watch    stopwatch
    #> 34         6      5        speedball    stopwatch    stopwatch    stopwatch
    #> 35         6      2        speedball    stopwatch    stopwatch    stopwatch
    #> 36         6      1        speedball    stopwatch    stopwatch    stopwatch
    #> 37         7      1        valueless          did          did          did
    #> 38         7      3        valueless          did          did          did
    #> 39         7      5        valueless          did         done          did
    #> 40         7      2        valueless          did          did          did
    #> 41         7      4        valueless          did          did          did
    #> 42         7      6        valueless          did         done          did
    #> 43         8      6         grievous  numerically  numerically  numerically
    #> 44         8      3         grievous  numerically  numerically  numerically
    #> 45         8      5         grievous  numerically  numerically  numerically
    #> 46         8      2         grievous  numerically   numrically  numerically
    #> 47         8      1         grievous  numerically  numerically  numerically
    #> 48         8      4         grievous  numerically  numericelly  numerically
    #> 49         9      6        melatonin      bloated      bloated      bloated
    #> 50         9      1        melatonin      bloated      bloated      bloated
    #> 51         9      5        melatonin      bloated      bloated      bloated
    #> 52         9      4        melatonin      bloated      bloeted      bloated
    #> 53         9      3        melatonin      bloated     bloatted      bloated
    #> 54         9      2        melatonin      bloated       bloatd      bloated
    #> 55        10      6             dose       domain         area       domain
    #> 56        10      5             dose       domain         area       domain
    #> 57        10      4             dose       domain       domein       domain
    #> 58        10      3             dose       domain       domain       domain
    #> 59        10      2             dose       domain       domain       domain
    #> 60        10      1             dose       domain       domain       domain
    #> 61        11      6     dynastically     steadily                  steadily
    #> 62        11      5     dynastically     steadily     steadily     steadily
    #> 63        11      4     dynastically     steadily     steedily     steadily
    #> 64        11      3     dynastically     steadily    stteadily     steadily
    #> 65        11      2     dynastically     steadily      stadily     steadily
    #> 66        11      1     dynastically     steadily     steadily     steadily
    #> 67        12      5          staffer     withdraw     withdraw     withdraw
    #> 68        12      4          staffer     withdraw     withdrew     withdraw
    #> 69        12      3          staffer     withdraw    witthdraw     withdraw
    #> 70        12      2          staffer     withdraw     withdraw     withdraw
    #> 71        12      6          staffer     withdraw     withdraw     withdraw
    #> 72        12      1          staffer     withdraw     withdraw     withdraw
    #> 73        13      3 institutionalism       beside       beside       beside
    #> 74        13      6 institutionalism       beside       beside       beside
    #> 75        13      5 institutionalism       beside       beside       beside
    #> 76        13      2 institutionalism       beside         bsid       beside
    #> 77        13      4 institutionalism       beside       beside       beside
    #> 78        13      1 institutionalism       beside       beside       beside
    #> 79        14      1        dollhouse       doodle       doodle       doodle
    #> 80        14      3        dollhouse       doodle       doodle       doodle
    #> 81        14      5        dollhouse       doodle         draw       doodle
    #> 82        14      2        dollhouse       doodle        doodl       doodle
    #> 83        14      4        dollhouse       doodle       doodle       doodle
    #> 84        14      6        dollhouse       doodle         draw       doodle
    #> 85        15      6           bolero     membrane     membrane     membrane
    #> 86        15      5           bolero     membrane     membrane     membrane
    #> 87        15      2           bolero     membrane       mmbran     membrane
    #> 88        15      1           bolero     membrane     membrane     membrane
    #> 89        15      3           bolero     membrane     membrane     membrane
    #> 90        15      4           bolero     membrane     membrene     membrane
    #> 91        16      5         soulless unofficially unofficially unofficially
    #> 92        16      3         soulless unofficially unofficially unofficially
    #> 93        16      6         soulless unofficially              unofficially
    #> 94        16      1         soulless unofficially unofficially unofficially
    #> 95        16      4         soulless unofficially unofficielly unofficially
    #> 96        16      2         soulless unofficially unofficially unofficially
    #> 97        17      5         uncurled    vibration    vibration    vibration
    #> 98        17      3         uncurled    vibration   vibrattion    vibration
    #> 99        17      6         uncurled    vibration    vibration    vibration
    #> 100       17      1         uncurled    vibration    vibration    vibration
    #> 101       17      4         uncurled    vibration    vibretion    vibration
    #> 102       17      2         uncurled    vibration    vibration    vibration
    #> 103       18      5         giveaway    permitted    permitted    permitted
    #> 104       18      3         giveaway    permitted  permitttted    permitted
    #> 105       18      6         giveaway    permitted      granted    permitted
    #> 106       18      1         giveaway    permitted    permitted    permitted
    #> 107       18      4         giveaway    permitted    permitted    permitted
    #> 108       18      2         giveaway    permitted      prmittd    permitted
    #> 109       19      3      origination        sleek        sleek        sleek
    #> 110       19      4      origination        sleek        sleek        sleek
    #> 111       19      6      origination        sleek        shiny        sleek
    #> 112       19      5      origination        sleek        shiny        sleek
    #> 113       19      2      origination        sleek          slk        sleek
    #> 114       19      1      origination        sleek        sleek        sleek
    #> 115       20      1        iconology    ignorance    ignorance    ignorance
    #> 116       20      3        iconology    ignorance    ignorance    ignorance
    #> 117       20      5        iconology    ignorance    ignorance    ignorance
    #> 118       20      2        iconology    ignorance     ignoranc    ignorance
    #> 119       20      4        iconology    ignorance    ignorence    ignorance
    #> 120       20      6        iconology    ignorance    ignorance    ignorance
    #>     Scored
    #> 1        1
    #> 2        1
    #> 3        1
    #> 4        1
    #> 5        1
    #> 6        0
    #> 7        0
    #> 8        0
    #> 9        1
    #> 10       1
    #> 11       1
    #> 12       0
    #> 13       1
    #> 14       1
    #> 15       1
    #> 16       1
    #> 17       1
    #> 18       1
    #> 19       1
    #> 20       1
    #> 21       1
    #> 22       1
    #> 23       1
    #> 24       1
    #> 25       1
    #> 26       0
    #> 27       0
    #> 28       1
    #> 29       1
    #> 30       1
    #> 31       0
    #> 32       1
    #> 33       0
    #> 34       1
    #> 35       1
    #> 36       1
    #> 37       1
    #> 38       1
    #> 39       0
    #> 40       1
    #> 41       1
    #> 42       0
    #> 43       1
    #> 44       1
    #> 45       1
    #> 46       1
    #> 47       1
    #> 48       1
    #> 49       1
    #> 50       1
    #> 51       1
    #> 52       1
    #> 53       1
    #> 54       1
    #> 55       0
    #> 56       0
    #> 57       1
    #> 58       1
    #> 59       1
    #> 60       1
    #> 61       0
    #> 62       1
    #> 63       1
    #> 64       1
    #> 65       1
    #> 66       1
    #> 67       1
    #> 68       1
    #> 69       1
    #> 70       1
    #> 71       1
    #> 72       1
    #> 73       1
    #> 74       1
    #> 75       1
    #> 76       0
    #> 77       1
    #> 78       1
    #> 79       1
    #> 80       1
    #> 81       0
    #> 82       1
    #> 83       1
    #> 84       0
    #> 85       1
    #> 86       1
    #> 87       0
    #> 88       1
    #> 89       1
    #> 90       1
    #> 91       1
    #> 92       1
    #> 93       0
    #> 94       1
    #> 95       1
    #> 96       1
    #> 97       1
    #> 98       1
    #> 99       1
    #> 100      1
    #> 101      1
    #> 102      1
    #> 103      1
    #> 104      0
    #> 105      0
    #> 106      1
    #> 107      1
    #> 108      0
    #> 109      1
    #> 110      1
    #> 111      0
    #> 112      0
    #> 113      0
    #> 114      1
    #> 115      1
    #> 116      1
    #> 117      1
    #> 118      1
    #> 119      1
    #> 120      1

    #Participant
    cued_output$DF_Participant
    #>   Sub.ID Proportion.Correct Z.Score.Participant
    #> 1      1               1.00           1.0259784
    #> 2      2               0.80           0.0000000
    #> 3      3               0.85           0.2564946
    #> 4      4               0.95           0.7694838
    #> 5      5               0.75          -0.2564946
    #> 6      6               0.45          -1.7954621