Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

NAs are not allowed in subscripted assignments

Hi! I am analyzing my data from a web experiment, and when I try to run this command:

sst_mt <- mt_import_mousetrap(df_sst, xpos_label = 'mouse_sst.x', ypos_label = 'mouse_sst.y', timestamps_label = 'mouse_sst.time')
sst_mt$data$pos_var <- apply(sst_mt$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(sst_mt$trajectories[,,"ypos"],1,var,na.rm=TRUE)
# Check if there are trials with 0 variance (i.e., all positions are identical)
table(sst_mt$data$pos_var==0)
# Only keep trials where positions varied
sst_mt <- mt_subset(sst_mt, pos_var>0)
sst_mt <- mt_time_normalize(sst_mt)
sst_mt <- mt_align_start(sst_mt)
sst_mt <- mt_derivatives(sst_mt)
sst_mt <- mt_measures(sst_mt)

I get the following error message:

Error in current_dev_ideal[to_flip_dev_ideal] <- -current_dev_ideal[to_flip_dev_ideal] : 
  NAs are not allowed in subscripted assignments

as you can see, I have eliminated trials with no movement. Any help would be greatly appreciated!

Comments

  • Hello,

    I think you have to remove all the NA values in your data set. Are you sure you have removed all of the NA variables? If so, there should be no problem. 😊

  • Hello

    Despite removing all positions as spesified above like a.g.leontiev did I'm getting the same error. Can you explain how remove all the NAs from the mousetrap object @GoSugar please? Any help would be greatly appreciated!

  • Hi there,

    I also would speculate that the problem is due to missing values (NAs), probably missing values that are already occurring in the raw dataset (df_sst).

    Usually, mt_import_mousetrap should to a good job at checking for missing values and throwing warning messages if there are any. Do you get any warning messages after running mt_import_mousetrap with your dataset and, if so, could you post them here?

    Best,

    Pascal

  • I have re-run everything and it worked smoothly without throwing any error. I guess i just had to restart R?


    I also have an (unrelated) question. Is there a way to calculate measures not over ALL trials, but let's say first half of the trials? Thank you so much!

  • Great to hear things are running smoothly now!

    Currently, there is no option in mousetrap that can calculate measures for only parts of the trial. However, depending on what measure you are interested in, functions like mt_deviations and mt_derivatives calculate deviatons from the idealized trajectory and velocity/accelerations for each time point, so you might use this as a starting point if you want to calculate a measure for a certain time point / part of the trial.

  • edited August 24

    Hi Pascal thanks for getting back to me. This task is a flanker task run in Qualtrics, where the participants have to press start at the bottom of the screen then click on the top left or right depending which way the middle arrow is facing. I had to do a lot of preprocessing to get it into a format that is importable to mousetrap. I'm having issues with my code. When I just do mt_align there are no errors but the agregate trajectories aren't right:

    mt_data <- mt_import_wide(mt_data1)

    mt_data <- mt_count(mt_data, save_as = "data")

    # Look at number of of recorded positions

    table(mt_data$data$nobs)

    # Only keep trials with more than 2 recorded positions

    mt_data <- mt_subset(mt_data, nobs > 2)

    # Calculate variance of positions for each trial

    mt_data$data$pos_var <- apply(mt_data$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(mt_data$trajectories[,,"ypos"],1,var,na.rm=TRUE)

    # Check if there are trials with 0 variance (i.e., all positions are identical)

    table(mt_data$data$pos_var==0)

    # Only keep trials where positions varied

    mt_data <- mt_subset(mt_data, pos_var>0)

    mt_data <- mt_derivatives(mt_data)

    mt_data<-mt_measures(mt_data, use = "trajectories",save_as="measures",

                dimensions = c("xpos", "ypos"), timestamps = "timestamps",

                verbose = FALSE)

    mt_data <- mt_time_normalize(mt_data)

    mt_data <- mt_spatialize(mt_data)

    mt_data$trajectories[,,"ypos"] <- (-mt_data$trajectories[,,"ypos"])

    mtdata1<-mt_align(mt_data)

    mt_plot(mtdata1, use="trajectories", color="subj")

    mt_plot_aggregate(mt_data, use="sp_trajectories", color="condition")


    However as you can see this isn't right. If I just do mt_plot_aggregate(mt_data, use="trajectories", color="condition")

    If I try to specify the start and end to something meaningful from the first figure :

     mtdata1<-mt_align_start_end(mt_data, use = "trajectories", save_as = use,

    dimensions = c("xpos", "ypos"), start = c(1250, -1250), end = c(0,0),

    verbose = FALSE)

    I get the following error:

    Error in create_results(data = data, results = trajectories, use = use, :  object 'use' not found

    In addition: Warning message: In mt_align_start_end(mt_data, use = "trajectories", save_as = use, : NaN/Inf/-Inf values returned in some trials for the dimension xpos as their start and end coordinate was identical.

    Where as if I just specify mt_align further mtdata<-mt_align( mt_data, use = "trajectories", save_as = use, dimensions = c("xpos", "ypos"), coordinates = c(-1200,1200,-2500,0), align_start = TRUE, align_end = TRUE, align_side = "left", verbose = FALSE)

    Error in trajectories[flip, , dimensions[1]] <- ((trajectories[flip, , :  NAs are not allowed in subscripted assignments

    How can I still have NAs when I've removed trials without variance or <2positions? And why does mt_align work but not mt_align_start(end)

    I really appreciate all your help. Thanks so much,

    Polly

  • I meant not in the first part of a trial, but let's say first 100 of ALL trials :)

  • Oh Sorry there isn't an obvious error on import

     >mt_data <- mt_import_wide(mt_data1)

    No mt_id_label provided. A new trial identifying variable called mt_id was created.

    No pos_ids provided. The following variables were found using grep:

    397 variables found for timestamps.

    397 variables found for xpos.

    397 variables found for ypos.

  • edited August 28

    Regarding @a.g.leontiev's question:

    I am not completely sure what you mean with "I meant not in the first part of a trial, but let's say first 100 of ALL trials".

    Do you mean you would only like to select a subset of trials for your analysis? If so, you could do this either using the basic R subset function before importing your data into mousetrap or using mt_subset afterwards. Assuming you have a variable that is your trial count (e.g., "count_trial"), the command would simply look like:

    raw_data <- subset(raw_data, count_trial<=100)

    or:

    mt_data a- mt_subset(mt_data, count_trial<=100)

  • edited August 28

    Regarding @P_Barr's question:

    I think that there are still some problematic trials in your dataset that need to be excluded. Specifically, there is the above warning that you quote:

    In addition: Warning message: In mt_align_start_end(mt_data, use = "trajectories", save_as = use, : NaN/Inf/-Inf values returned in some trials for the dimension xpos as their start and end coordinate was identical.

    The warning suggest that in some trials the start and end point is identical which, if I understand your setup correctly, should not be possible (if participants click a start button at the bottom and then one of the response buttons at the top of the screen). One explanation for this that I can think of is that your task uses a time limit after which a trial is automatically aborted (i.e., there are trials without response possible). If so, these trials need to be excluded before importing them into mousetrap.

  • Hi Pascal,

    You are correct its not possible to have the same start and end position as they have to click start in the bottom center of the screen and then a left or right button at the top corners.

    I don't think we included a timeout- participants are forced to click a response button to see the next trial. We did include an error message after they clicked a response button if they started too late (>800ms) or responded too late (>5000ms). I have excluded these prior to import (wide) and now the trajectories seem to automatically have an aligned start and end but I'm still having weird aggregate plotting issues:

    mt_data1<-read.csv ("MT_data5.csv", header = TRUE, sep = ',')

    # remove too long/timeout responses prior to import(https://forum.cogsci.nl/discussion/comment/20455#Comment_20455)

    mt_data1 <- mt_data1[ which(mt_data1$init.time <800 & mt_data1$response_latency2<5000), ]

    #import to MT

    mt_data <- mt_import_wide(mt_data1)

    mt_data <- mt_count(mt_data, save_as = "data")

    # Look at number of of recorded positions

    table(mt_data$data$nobs)

    # Only keep trials with more than 2 recorded positions

    mt_data <- mt_subset(mt_data, nobs > 2)

    # Calculate variance of positions for each trial

    mt_data$data$pos_var <- apply(mt_data$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(mt_data$trajectories[,,"ypos"],1,var,na.rm=TRUE)

    # Check if there are trials with 0 variance (i.e., all positions are identical)

    table(mt_data$data$pos_var==0)

    # Only keep trials where positions varied

    mt_data <- mt_subset(mt_data, pos_var>0)

    mt_data$trajectories[,,"ypos"] <- (-mt_data$trajectories[,,"ypos"])

    mt_data <- mt_derivatives(mt_data)

    mt_data<-mt_measures(mt_data, use = "trajectories",save_as="measures", dimensions = c("xpos", "ypos"), timestamps = "timestamps", verbose = FALSE)

    mt_data <- mt_time_normalize(mt_data)

    mt_data <- mt_spatialize(mt_data)

    mt_plot(mt_data, use="trajectories", color="condition")

    (as you can see it seems to be more aligned now)


    mt_plot_aggregate(mt_data, use="sp_trajectories",color="condition")



    mt_plot_aggregate(mt_data, use="trajectories",+          color="condition")

    Warning message:

    In mt_reshape(data = data, use = use, use_variables = use_variables, :

     Trajectories differ in the number of logs. Aggregate trajectory data may be incorrect

    If I try and do align_start_end (which I don't think I need to as it seems to be aligned) I get the same error message:

    mtdata1<-mt_align_start_end(mt_data, use = "trajectories", save_as = use,dimensions = c("xpos", "ypos"), start = c(1250, -1250), end = c(0,0), verbose = FALSE)

    Error in create_results(data = data, results = trajectories, use = use, :  object 'use' not found

    In addition: Warning message:

    In mt_align_start_end(mt_data, use = "trajectories", save_as = use, : NaN/Inf/-Inf values returned in some trials for the dimension xpos as their start and end coordinate was identical.


    As always I really appreciate your help and any ideas

  • Hi there,

    I have the following ideas regarding the issues you mentioned above:

    1) Flipping trajectories

    In your preprocessing code, I did not see a step where you flip trajectories that ended on the right option to the left. If you do not do this, the resulting aggregate trajectory plot might be misleading as it aggregates trajectories that end on the left and end on the right option.

    2) Aggregate trajectory plot:

    To create the aggregate trajectory plot, you use:

    mt_plot_aggregate(mt_data, use="trajectories", color="condition")

    However, when plotting aggregate trajectories, you usually cannot use the raw trajectories as the number of recorded positions varies between trajectories (which is also why you get the warning message you quoted above: "Trajectories differ in the number of logs. Aggregate trajectory data may be incorrect"). Therefore, the resulting plot looks quite weird. Instead, you could use the time-normalized trajectories:

    mt_plot_aggregate(mt_data, use="tn_trajectories", color="condition")

    3) Start end alignment

    The warning message you quoted "NaN/Inf/-Inf values returned in some trials for the dimension xpos as their start and end coordinate was identical." suggests that in some trials the x coordinate of the start and end position was identical (the y coordinate might vary). In this case, the function cannot normalize the trajectory start and end points. I don't know if an identical start and end x coordinate is possible in your setup, but if so, it might not make sense to use this function.

  • Hi!

    I am unfortunately having this issue again:#### 100 ms ####

    m100msstop <- subset(mydata, vol == 1 & ssd == 0.1)
    
    mt_sst <- mt_import_mousetrap(
    
    +   m100msstop,
    
    +   xpos_label = "mouse_sst.x",
    
    +   ypos_label = "mouse_sst.y",
    
    +   timestamps_label = "mouse_sst.time"
    
    +  
    
    + )
    
    There were 22 warnings (use warnings() to see them)
    
    table(mt_sst$data$nobs)
    
    mt_sst <- mt_count(mt_sst, save_as = "data")
    
    table(mt_sst$data$nobs)
    
     
    
     10  13  14  16  18  19  20  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50
    
      2   1   1   1   4   1   5   2   3   1   8  11   8   6   9   9  10   6  10  13  19  20  17  14  28  12  20  20   8  20  17  18  21  23  15  16
    
     51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86
    
     24  19  16  22  23  15   6  15   7  12  10   7   9   7   4   5   6   3   5   3   4   2   3   6   6   1   3   4   8   4   4   9   5   8   5  12
    
     87  88  89  90  91  98  99 109 212 214 215
    
     15   7  62 732   1   1   1   1   1   6  39
    
    
    mt_sst <- mt_subset(mt_sst, nobs > 2)
    
    mt_sst$data$pos_var <- apply(mt_sst$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(mt_sst$trajectories[,,"ypos"],1,var,na.rm=TRUE)
    
    > table(mt_sst$data$pos_var==0)
    
     
    
    FALSE  TRUE
    
     1453   114
    
    mt_sst <- mt_subset(mt_sst, pos_var>0)
    
    # Calculate mouse-tracking derivatives for each position (distance, velocity, acceleration)
    mt_sst <- mt_derivatives(mt_sst)
    
    
    # Calculate standard mouse-tracking measures
    
    > mt_sst <- mt_measures(mt_sst)
    
    Error in current_dev_ideal[to_flip_dev_ideal] <- -current_dev_ideal[to_flip_dev_ideal] :
    
      NAs are not allowed in subscripted assignments
    
    
    # Demonstrate that sum of distances corresponds to total_dist measure
    
    table(rowSums(mt_sst$trajectories[,,"dist"],na.rm=TRUE)-mt_sst$measures$total_dist)
    
    < table of extent 0 >
    
    
    
    # Set distances for timestamps beyond 600 ms to 0
    
    mt_sst$trajectories[,,"dist"][mt_sst$trajectories[,,"timestamps"]<0.1] <- 0
    
    mt_sst$measures$total_dist_100 <- rowSums(mt_sst$trajectories[,,"dist"],na.rm=TRUE)
    
    stop_distance_100 <- mt_aggregate_per_subject(
    
    +   mt_sst,
    
    +   use="measures",
    
    +   use_variables=c("total_dist_100"),
    
    +   subject_id="File"
    
    + )
    
    Error in dataset[, mt_id] <- rownames(dataset) :
    
      incorrect number of subscripts on matrix
    

    Any help would be greatly appreciated @Pascal . As you can see above, I tried removing trials with no movement, but I still get the same problem.

  • Hi!

    I am unfortunately having this issue again:#### 100 ms ####

    m100msstop <- subset(mydata, vol == 1 & ssd == 0.1)
    
    mt_sst <- mt_import_mousetrap(
    
    +   m100msstop,
    
    +   xpos_label = "mouse_sst.x",
    
    +   ypos_label = "mouse_sst.y",
    
    +   timestamps_label = "mouse_sst.time"
    
    +  
    
    + )
    
    There were 22 warnings (use warnings() to see them)
    
    table(mt_sst$data$nobs)
    
    mt_sst <- mt_count(mt_sst, save_as = "data")
    
    table(mt_sst$data$nobs)
    
     
    
     10  13  14  16  18  19  20  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50
    
      2   1   1   1   4   1   5   2   3   1   8  11   8   6   9   9  10   6  10  13  19  20  17  14  28  12  20  20   8  20  17  18  21  23  15  16
    
     51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86
    
     24  19  16  22  23  15   6  15   7  12  10   7   9   7   4   5   6   3   5   3   4   2   3   6   6   1   3   4   8   4   4   9   5   8   5  12
    
     87  88  89  90  91  98  99 109 212 214 215
    
     15   7  62 732   1   1   1   1   1   6  39
    
    
    mt_sst <- mt_subset(mt_sst, nobs > 2)
    
    mt_sst$data$pos_var <- apply(mt_sst$trajectories[,,"xpos"],1,var,na.rm=TRUE) + apply(mt_sst$trajectories[,,"ypos"],1,var,na.rm=TRUE)
    
    > table(mt_sst$data$pos_var==0)
    
     
    
    FALSE  TRUE
    
     1453   114
    
    mt_sst <- mt_subset(mt_sst, pos_var>0)
    
    # Calculate mouse-tracking derivatives for each position (distance, velocity, acceleration)
    mt_sst <- mt_derivatives(mt_sst)
    
    
    # Calculate standard mouse-tracking measures
    
    > mt_sst <- mt_measures(mt_sst)
    
    Error in current_dev_ideal[to_flip_dev_ideal] <- -current_dev_ideal[to_flip_dev_ideal] :
    
      NAs are not allowed in subscripted assignments
    
    
    # Demonstrate that sum of distances corresponds to total_dist measure
    
    table(rowSums(mt_sst$trajectories[,,"dist"],na.rm=TRUE)-mt_sst$measures$total_dist)
    
    < table of extent 0 >
    
    
    
    # Set distances for timestamps beyond 600 ms to 0
    
    mt_sst$trajectories[,,"dist"][mt_sst$trajectories[,,"timestamps"]<0.1] <- 0
    
    mt_sst$measures$total_dist_100 <- rowSums(mt_sst$trajectories[,,"dist"],na.rm=TRUE)
    
    stop_distance_100 <- mt_aggregate_per_subject(
    
    +   mt_sst,
    
    +   use="measures",
    
    +   use_variables=c("total_dist_100"),
    
    +   subject_id="File"
    
    + )
    
    Error in dataset[, mt_id] <- rownames(dataset) :
    
      incorrect number of subscripts on matrix
    

    Any help would be greatly appreciated @Pascal . As you can see above, I tried removing trials with no movement, but I still get the same problem.

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games