<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Find MaxN value (species count) per ID for overlapping time range. in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/486586#M73050</link>
    <description>&lt;P&gt;This post might give some ideas&lt;LI-MESSAGE title="Overlap / Count of periods at the same point of time" uid="482622" url="https://community.jmp.com/t5/Discussions/Overlap-Count-of-periods-at-the-same-point-of-time/m-p/482622#U482622" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One question, if time period is 12:00 - 12:01 and other one is 12:01 - 12:02 is that an overlap or not?&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2022 06:57:56 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-05-13T06:57:56Z</dc:date>
    <item>
      <title>Find MaxN value (species count) per ID for overlapping time range.</title>
      <link>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/486478#M73043</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to find the maximum number of individuals observed in a single video frame.&lt;/P&gt;&lt;P&gt;I have roughly 3000 2min videos with 5000 observations recorded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;For a given ID, what is the greatest value of the sum of&amp;nbsp;&lt;STRONG&gt;Count&lt;/STRONG&gt; for a species (eg. DuCr &amp;amp; ShPe) when the same species has overlapping time_start and time_end&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;example data:&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Species&lt;/TD&gt;&lt;TD&gt;Count&lt;/TD&gt;&lt;TD&gt;time_start&lt;/TD&gt;&lt;TD&gt;time_end&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_1&lt;/TD&gt;&lt;TD&gt;DuCr&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:00&lt;/TD&gt;&lt;TD&gt;12:01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_1&lt;/TD&gt;&lt;TD&gt;ShPe&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:00&lt;/TD&gt;&lt;TD&gt;12:01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_1&lt;/TD&gt;&lt;TD&gt;Shpe&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:05&lt;/TD&gt;&lt;TD&gt;12:06&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_2&lt;/TD&gt;&lt;TD&gt;DuCr&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:00&lt;/TD&gt;&lt;TD&gt;12:01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_2&lt;/TD&gt;&lt;TD&gt;ShPe&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:00&lt;/TD&gt;&lt;TD&gt;12:01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_2&lt;/TD&gt;&lt;TD&gt;Shpe&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;12:00&lt;/TD&gt;&lt;TD&gt;12:01&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should look like this:&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;DuCr&lt;/TD&gt;&lt;TD&gt;ShPe&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;video_2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the most related discussion post I could find:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Finding-the-max-value-as-per-ID/m-p/52616#M29792" target="_blank" rel="noopener"&gt;https://community.jmp.com/t5/Discussions/Finding-the-max-value-as-per-ID/m-p/52616#M29792&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 00:49:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/486478#M73043</guid>
      <dc:creator>MRM</dc:creator>
      <dc:date>2023-06-09T00:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find MaxN value (species count) per ID for overlapping time range.</title>
      <link>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/486586#M73050</link>
      <description>&lt;P&gt;This post might give some ideas&lt;LI-MESSAGE title="Overlap / Count of periods at the same point of time" uid="482622" url="https://community.jmp.com/t5/Discussions/Overlap-Count-of-periods-at-the-same-point-of-time/m-p/482622#U482622" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One question, if time period is 12:00 - 12:01 and other one is 12:01 - 12:02 is that an overlap or not?&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 06:57:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/486586#M73050</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-05-13T06:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find MaxN value (species count) per ID for overlapping time range.</title>
      <link>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/487208#M73102</link>
      <description>&lt;P&gt;Yes, the 12:01 would be the overlapping second.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im just looking at the highest count for 1 second.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 17:12:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/487208#M73102</guid>
      <dc:creator>MRM</dc:creator>
      <dc:date>2022-05-16T17:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find MaxN value (species count) per ID for overlapping time range.</title>
      <link>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/487272#M73105</link>
      <description>&lt;P&gt;This solution might be over-complicated (hopefully it is at least correct). It is based on pairings created by ID and Species and "distances" between different times (distance matrix can get quite big which can slow down the calculations)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled 37",
	Add Rows(8),
	New Column("ID",
		Character,
		"Nominal",
		Set Values({"video_1", "video_1", "video_1", "video_2", "video_2", "video_2", "video_2", "video_2"})
	),
	New Column("Species", Character(16), "Nominal", Set Values({"DuCr", "ShPe", "ShPe", "DuCr", "ShPe", "ShPe", "ShPe", "ShPe"})),
	New Column("Count", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 1, 1, 1, 1, 1])),
	New Column("time_start",
		Numeric,
		"Continuous",
		Format("hr:m", 12),
		Input Format("hr:m"),
		Set Values([43200, 43200, 43500, 43200, 43200, 43200, 43260, 43320])
	),
	New Column("time_end",
		Numeric,
		"Continuous",
		Format("hr:m", 12),
		Input Format("hr:m"),
		Set Values([43260, 43260, 43560, 43260, 43260, 43260, 43320, 43380])
	),
	New Column("Correct", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 1, 3, 3, 4, 2]))
);

// dt:time_start &amp;lt;&amp;lt; Data Type(Numeric, Format("hr:m", 30), Input Format("hr:m")) &amp;lt;&amp;lt; Set Modeling Type("Continuous") &amp;lt;&amp;lt; Set Field Width(12);
// dt:time_end &amp;lt;&amp;lt; Data Type(Numeric, Format("hr:m", 30), Input Format("hr:m")) &amp;lt;&amp;lt; Set Modeling Type("Continuous") &amp;lt;&amp;lt; Set Field Width(12);

// Create Pair column with ID and Species
dt &amp;lt;&amp;lt; New Column("Pairs", Character, Nominal, &amp;lt;&amp;lt;Set Each Value(:ID || :Species));
// Create matrix of time_start and time_end columns
time_m = dt[0, {"time_start", "time_end"}];
// Calculate distances between all rows
D = Distance(time_m, time_m);
// Get unique pairs
Summarize(dt, uniq_pairs = by(:Pairs));
// Create result column
dt &amp;lt;&amp;lt; New Column("Overlap_count", Numeric, Continuous);

For Each Row(
	dt, // loop over each row
	pair_rows = Loc(dt[0, "Pairs"], :Pairs); // get pairs for current row
	nearest_rows = pair_rows[Loc(D[Row(), pair_rows] &amp;lt;= 7200)]; // get rows which are close enough
	counts = Sum(dt[nearest_rows, "Count"]); // calculate sum of Count
	dt[Row(), "Overlap_count"] = counts; // set value to Overlap_count column
);

dt_summary = dt &amp;lt;&amp;lt; Summary(
	Group(:ID),
	Max(:Overlap_count),
	Subgroup(:Species),
	Freq("None"),
	Weight("None"),
	statistics column name format("column"),
	Link to original data table(0)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_4-1652729758211.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42464iE7FAB0710EB646FA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_4-1652729758211.png" alt="jthi_4-1652729758211.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_5-1652729768507.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42465iEC3EB5EE5B65BE6F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_5-1652729768507.png" alt="jthi_5-1652729768507.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 19:38:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Find-MaxN-value-species-count-per-ID-for-overlapping-time-range/m-p/487272#M73105</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-05-16T19:38:19Z</dc:date>
    </item>
  </channel>
</rss>

