Creating a Variable of TimeHello All,
I am relatively new to the JMP world and am trying to work through a dataset.
I am in the midst of trying to create a way to measure time within a trial within my data. To do so I have created a Lag variable, which tells me when a new trial starts. I have now been attempting to create a variable that will give me the number of presentations of the manipulation within each trial so that I can then use this to eventually get the measure of time within each trial. I have set this process up as an if, then statement thinking that would work, but I have had no luck getting to the desired end point yet. The current code is below.
If( :Lag1 == 1, 1,
:Lag1 == 0, Empty () )
I want the new variable to be equal to 1 when the Lag1 variable is equal to 1. When Lag1 is equal to 0 I want it to count up until it gets to the next lag1 == 1, in which is should start over with a new counting sequence. I have tried many different functions within the JMP scripts and have lucked out so far.
Any help is greatly appreciated!
Re: Creating a Variable of Time
Okay. So when looking at the selected area only. I would want:
Nback#=1, duration=14303912, Cumulative Duration=0
Nback#=2, duration=14305914, Cumulative Duration=2002
Nback#=3, duration=14307916, Cumulative Duration=4004
Nback#=4, duration=14309965, Cumulative Duration=6053
Nback#=5, duration=14312015, Cumulative Duration=8103
Nback#=6, duration=14314051, Cumulative Duration=10139
Hopefully this helps make everything more clear. This is what I would ideally want within this new column creation.
Re: Creating a Variable of TimeThere is a duration for that first case. So what should this look like when Nback# is 2? The sum of the duration for 1 and for 2?
Do you want this column to be the cumulative duration? Is there a duration when Nback# is 1?
Maybe you need to add an Nback# 0 row for each instance, where the duration is zero.
Your request is not clear. Create a 5 row example of Nback#, duration and this Cumulative Duration, so it is clear what is needed.
Re: Creating a Variable of TimeI do want the value for Nback # of Letters Presented ==1 to be 0. The current column measuring Nback Start is a cumulative total, but I want to know how much time has elasped for each nback presentation within that trial. To do this I would like the start of each to be 0 so that I can make comparisons across multiple trials as well.
Re: Creating a Variable of TimeI don't think you want 0 when Nback # of Letters Presented ==1. Don't you want the duration for that row? Here is a screenshot, and the formula


If( :Nback # of Letters Presented == 1,
:Duration,
Lag( :Cumulative Duration, 1 ) + :Duration
)
Re: Creating a Variable of TimeI have a second issue while creating this overall measure of time. I have attached a screenshot that shows what the data looks like thus far. I need to now create a variable that is called "time in trial" where I basically take the "Nback start" minus the "Nback stop."
More specifically I would need several things to happen.
1. When "Nback # of letters presented" equals 1 the "time in trial" should equal 0. Then as the "Nback # of letters presented" increases the "time in trial" should also increase.
2. This increase should stop when I reach another 1 in "Nback # of letters presented" and start back over at 0 for "time in trial."
Any guidance would be greatly appreciated. 
Re: Creating a Variable of TimeMy data was set up like the image on the right and just like you said that script you gave me did work!
Thank you so much for your help. I greatly appreciate it!
Re: Creating a Variable of TimeYour data looks sorted. There must be some column that represents a unique trial, the start and the end. If your data looks like the left picture, that is what I meant maybe I should have called it intermixed trials.
If your data looks like the left would row 8 an A trial have a 1? If yes, does that trial last only 1 period or shoudl the count of As continue?
If your data looks like the table on the right, then the function I sent works as you described it, and is displayed in the screenshot
Not sorted by TrialNot sorted by Trial
Sorted by trials and functionSorted by trials and function
Re: Creating a Variable of TimeI am using a lag function to identify the beginning and ending of each of the trials. Each subject will have 4 trials each, and the 1s and 0s are not separated out from eachother, they are intertwined within the overal subject data. The lenght of each trial will vary depending on the lenght of that specific trial and is not the same for each participant.
Due to this I am not sure that what you have suggested will completly work for the dataset that I have. There is an example of what I mean by my 0s and 1s being intertwined within my dataset, if that is helpful.
Thank you for the reply!

Re: Creating a Variable of TimeCreate a new column, here I called it :Group Order, here is the function. Note JMP has a function called lag() just in case you are not familiar with it.
If( row()==1 | :Lag1==1, 1,
:Lag1==0, lag(:Group Order)+1
)
This of course assumes your table is sorted. Here is a script, that starts by changing Big Class to have a layout like your table with :Lag1. Then creates the column with the function above.
Names default to here(1);
dt = Open("$sample_data/big class.jmp");
dt << sort( By(:sex, :age), Replace Table);
//needs to be sorted so 1's and 0's are not mixed
dt << New Column("Lag1", numeric, <<SET each="" value=""></SET>