turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Creating Time Variable

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted
##
##### Creating Time Variable

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 11, 2018 4:59 PM
(714 views)

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

I need to make this final column as a measure of time. Any guidance would be greatly appreciated.

7 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

This script might be what you need. Data set as the attchment.

```
dt = Current Data Table();
//dt << New Column( "Delta", numeric );
dt << New Column( "Cumulative", numeric );
dt << Sort( By( :Category, :Time ), Order( Ascending, Ascending ), Replace table );
For( i = 1, i <= N Rows( dt ), i++,
If( :Time[i] == Min( :Time[dt << get rows where( :Category == :Category[i] )] ),
//dt:Delta[i] = 0;
dt:Cumulative[i] = 0;
,
//dt:Delta[i] = dt:Time[i] - dt:Time[i - 1];
dt:Cumulative[i] = dt:Cumulative[i-1]+ (dt:Time[i] - dt:Time[i - 1]);
)
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Here is a way to do this with just column formulas. I'm not sure which column you are using to indicate the time reset, so I included

- A method to do this from either a column whose values changes for each new group, and
- A method based on a column that indicates a reset in time.

```
Names default to here ( 1 );
//Table with data similar to yours
dt = New Table( "Data",
Add Rows( 40 ),
New Column( "Space", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( Round( Random Uniform( 1, 5 ), 0 ) )
),
New Column( "Duration", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( Round( Random Uniform( 1998, 2002 ), 0 ) )
),
New Column( "Start", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( If( Row() == 1, :Space, :Space + Lag( :Start, 1 ) + Lag( :Duration, 1 ) ) )
),
New Column( "End", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :Start + :Duration )
),
New Column( "Period Indication", Character, "Nominal",
Formula( If( Row() < 15, "One", "Two" ) )
),
New Column( "Indication of Time Reset Pulse", Numeric, "Nominal",
Formula( If( Row() == 10, 1, . ) )
)
);
//New Column - subtract the current end time from the first end time in
//the group. Use this if the column :summary_image_end" tells you when
//to start a new group
dt << New Column( "Time In Group", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :End - Col Min( :Start, :Period Indication ) )
);
//Make a New Column indicating the period for a pulse signal, use this if
//the column Lag1 tells you when to start a new group
dt << New Column( "Period Indication from Pulse", Numeric, "Nominal",
Format( "Best", 12 ),
Formula(
If(
Row() == 1,
1,
Lag( :Period Indication from Pulse, 1 ) +
If(
Is Missing( :Indication of Time Reset Pulse ),
0,
1
)
)
)
);
//Once the group column is made then calculate the duration
dt << New Column( "Time In Group - Pulse", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :End - Col Min( :Start, :Period Indication from Pulse ) )
);
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

So upon looking at the data that I have I realized that I have a 'Nback Duration' Column. I was wondering if there would be an easier way to get to the desired end result using this column and the lag1 column.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

You could sum up the durations however you might miss the time between rows. In my opinion using the Start and End Times (Nback Start and Nback Stop and summary_image_end) is fairly succinct. The formula should just have to be as shown below. You would use *either* the blue columns (if you care about summary_image_end) or the red columns (if you care about Lag1).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

So, this works technically. It does give me values, but it does not rest at the beginning of each trial. This is an important step in this process so that I am able to compare across each individual trial. The current script allows me to compare overtime generally, not within each of the individual trials. This is why I would like to have each new trial start at 0 time.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Maybe you want to start counting from the end time of the first row in each period?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

So, making this small change still produces the same sort of output for my new variable.