Skip to contents

Delete the data of all participants who did not end the experiment at (a) certain page(s) and/or app(s).

Caution 1: This function does not delete cases from the original CSV and Excel files!

Caution 2: This function does not delete cases from custom exports if the custom exports do not have a variable named participant.code and a variable named session.code!

Caution 3: This function does not delete any data from the $Chats data frame! (As the interpretation of chat data depends on how participants engage with each other, the data must be deleted with more care than deleting data in other apps. Hence, this function does not delete data in this data frame. Please do this manually if necessary!)

Usage

delete_dropouts(
  oTree,
  final_apps = NULL,
  final_pages = NULL,
  saved_vars = NULL,
  inconsistent = NULL,
  reason = "ENC",
  info = FALSE
)

Arguments

oTree

A list of data frames that were created by import_otree

final_apps

Character. The name(s) of the app(s) at which the participants have to finish the experiment.

final_pages

Character. The name(s) of the page(s) at which the participants have to finish the experiment.

saved_vars

Character. The name(s) of variable(s) that need(s) to be stored in the list of information on deleted cases in $info$deleted_cases.

inconsistent

Character. Should the function continue or be stopped if at least one participant has inconsistent end_pages, inconsistent end_apps, or both? To continue, type "yes", to stop the function, type "no".

reason

Character. The reason for deletion that should be stored in the list of information on deleted cases in $info$deleted_cases.

info

Logical. TRUE if a brief information on the dropout deletion process should be printed.

Value

This function returns a duplicate of the original oTree list of data frames but without the deleted cases.

It adds information on the deleted cases to $info$deleted_cases. (This list is also filled by other functions.)

In this list, you can find the following information:

- $full = A data frame that contains information on all participants who did not finish the study; it shows their participant codes, the names of the apps in which they left the experiment, the names of the pages in which they left the experiment, the names of the app data frames in which this information was found, and the dropout reason ("ENC", experiment not completed, combined with the name of the data frame in which the dropout was observed). Because participants usually appear in multiple app data frames, the $info$deleted_cases$full data frame may contain several entries for each person.

- $unique = A data frame that contains similar information as the $full data frame but with only one row per participant and no information on the data frame in which the dropout was observed.

- $all_end = A table that provides information on the app and page combinations where participants ended the experiment. This table also includes information for participants who did not drop out of the experiment. The $all_end table is only shown if an $all_apps_wide data frame exists.

- $codes = A vector containing the participant codes of all deleted participants.

- $count = The number of all deleted participants.

It is important to note that if only the argument final_pages is set, this function does not distinguish between page names that reoccur in different apps.

If the columns end_app and end_page in the output are empty, these variables were not saved by oTree for the specific participants. This could be because empty rows were not deleted. This can be done by using the argument del_empty = TRUE when using import_otree.

Examples

# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree

# First, show some row numbers
print(paste(nrow(oTree$all_apps_wide), nrow(oTree$survey),
nrow(oTree$Time), nrow(oTree$Chats)))
#> [1] "29 25 289 35"

# Delete all cases that didn't end the experiment on the page "Demographics"
# within the app "survey"
oTree2 <- delete_dropouts(oTree,
                         final_apps = c("survey"),
                         final_pages = c("Demographics"))

# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "20 16 248 35"

# Delete all cases that didn't end the experiment on the page "Demographics"
# This page can be in any app
oTree2 <- delete_dropouts(oTree, final_pages = "Demographics")

# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "20 16 248 35"

# Delete all cases that didn't end the experiment on
# any page in the app "survey"
oTree <- delete_dropouts(oTree, final_apps = "survey")

# Show row numbers again
print(paste(nrow(oTree2$all_apps_wide), nrow(oTree2$survey),
nrow(oTree2$Time), nrow(oTree2$Chats)))
#> [1] "20 16 248 35"

# Get list of information on all deleted cases
# (If there is already a list, the new list is added to it!)
oTree2$info$deleted_cases
#> $full
#>    participant.code session.code  end_app        end_page
#> 1          164r1hs4     7bfqtokx  chatapp            chat
#> 2          164r1hs4     7bfqtokx  chatapp            chat
#> 3          164r1hs4     7bfqtokx  chatapp            chat
#> 4          164r1hs4     7bfqtokx  chatapp            chat
#> 5          2scvem7a     vd1h01iv dictator ResultsWaitPage
#> 6          2scvem7a     vd1h01iv dictator ResultsWaitPage
#> 7          2scvem7a     vd1h01iv dictator ResultsWaitPage
#> 8          2scvem7a     vd1h01iv dictator ResultsWaitPage
#> 9          7wa8kk3d     l8ecm1uh dictator    Introduction
#> 10         7wa8kk3d     l8ecm1uh dictator    Introduction
#> 11         7wa8kk3d     l8ecm1uh dictator    Introduction
#> 12         7wa8kk3d     l8ecm1uh dictator    Introduction
#> 13         ao9kqvqn     l8ecm1uh dictator    Introduction
#> 14         ao9kqvqn     l8ecm1uh dictator    Introduction
#> 15         ao9kqvqn     l8ecm1uh dictator    Introduction
#> 16         ao9kqvqn     l8ecm1uh dictator    Introduction
#> 17         d4sq7zio     l8ecm1uh dictator    Introduction
#> 18         d4sq7zio     l8ecm1uh dictator    Introduction
#> 19         d4sq7zio     l8ecm1uh dictator    Introduction
#> 20         d4sq7zio     l8ecm1uh dictator    Introduction
#> 21         jxh15obl     t0rog7nz   survey           Offer
#> 22         jxh15obl     t0rog7nz   survey           Offer
#> 23         jxh15obl     t0rog7nz   survey           Offer
#> 24         jxh15obl     t0rog7nz   survey           Offer
#> 25         ktjz5jli     7bfqtokx dictator ResultsWaitPage
#> 26         ktjz5jli     7bfqtokx dictator ResultsWaitPage
#> 27         ktjz5jli     7bfqtokx dictator ResultsWaitPage
#> 28         ktjz5jli     7bfqtokx dictator ResultsWaitPage
#> 29         vbhvhozv     vd1h01iv dictator ResultsWaitPage
#> 30         vbhvhozv     vd1h01iv dictator ResultsWaitPage
#> 31         vbhvhozv     vd1h01iv dictator ResultsWaitPage
#> 32         vbhvhozv     vd1h01iv dictator ResultsWaitPage
#> 33         znri6myc     l8ecm1uh dictator    Introduction
#> 34         znri6myc     l8ecm1uh dictator    Introduction
#> 35         znri6myc     l8ecm1uh dictator    Introduction
#> 36         znri6myc     l8ecm1uh dictator    Introduction
#>                            reason
#> 1         ENC. Noticed at: survey
#> 2  ENC. Noticed at: all_apps_wide
#> 3        ENC. Noticed at: chatapp
#> 4       ENC. Noticed at: dictator
#> 5  ENC. Noticed at: all_apps_wide
#> 6        ENC. Noticed at: chatapp
#> 7       ENC. Noticed at: dictator
#> 8         ENC. Noticed at: survey
#> 9  ENC. Noticed at: all_apps_wide
#> 10       ENC. Noticed at: chatapp
#> 11      ENC. Noticed at: dictator
#> 12        ENC. Noticed at: survey
#> 13 ENC. Noticed at: all_apps_wide
#> 14       ENC. Noticed at: chatapp
#> 15      ENC. Noticed at: dictator
#> 16        ENC. Noticed at: survey
#> 17       ENC. Noticed at: chatapp
#> 18      ENC. Noticed at: dictator
#> 19        ENC. Noticed at: survey
#> 20 ENC. Noticed at: all_apps_wide
#> 21      ENC. Noticed at: dictator
#> 22        ENC. Noticed at: survey
#> 23 ENC. Noticed at: all_apps_wide
#> 24       ENC. Noticed at: chatapp
#> 25 ENC. Noticed at: all_apps_wide
#> 26       ENC. Noticed at: chatapp
#> 27      ENC. Noticed at: dictator
#> 28        ENC. Noticed at: survey
#> 29 ENC. Noticed at: all_apps_wide
#> 30       ENC. Noticed at: chatapp
#> 31      ENC. Noticed at: dictator
#> 32        ENC. Noticed at: survey
#> 33 ENC. Noticed at: all_apps_wide
#> 34       ENC. Noticed at: chatapp
#> 35      ENC. Noticed at: dictator
#> 36        ENC. Noticed at: survey
#> 
#> $unique
#>    participant.code session.code  end_app        end_page reason
#> 1          164r1hs4     7bfqtokx  chatapp            chat    ENC
#> 5          2scvem7a     vd1h01iv dictator ResultsWaitPage    ENC
#> 9          7wa8kk3d     l8ecm1uh dictator    Introduction    ENC
#> 13         ao9kqvqn     l8ecm1uh dictator    Introduction    ENC
#> 17         d4sq7zio     l8ecm1uh dictator    Introduction    ENC
#> 21         jxh15obl     t0rog7nz   survey           Offer    ENC
#> 25         ktjz5jli     7bfqtokx dictator ResultsWaitPage    ENC
#> 29         vbhvhozv     vd1h01iv dictator ResultsWaitPage    ENC
#> 33         znri6myc     l8ecm1uh dictator    Introduction    ENC
#> 
#> $all_end
#>           
#>            Demographics Introduction Offer ResultsWaitPage chat
#>   chatapp             0            0     0               0    1
#>   dictator            0            4     0               3    0
#>   survey             20            0     1               0    0
#> 
#> $codes
#> [1] "164r1hs4" "2scvem7a" "7wa8kk3d" "ao9kqvqn" "d4sq7zio" "jxh15obl" "ktjz5jli"
#> [8] "vbhvhozv" "znri6myc"
#> 
#> $count
#> [1] 9
#>