## Area under a curve for multiple "X,Y" cycles, when every Y cycle has unique shape

Community Trekker

Joined:

Jul 31, 2015

Hello,

I have a data set where:

x = hour
y = average tree water use [out 3, 2 or 1 values due to data loss]

This cycle repeats for months at the time [24 hours per day], and every day "y" has a different pattern. Here is a three-day sample data:

Adding up hours is an easy way to do it, but assumes water use was the same during the entire hour [wrong assumption].

Is there a better way to integrate the area under each curve so that the resolution of "y" is not one hour?

I already tried fitting various non-linear models from the Model Library, but none yields favorable results, and can't make them adaptive to the daily changes in curve shape of "y".

Next I am going to try a Gaussian Process to see if I can get to increase the resolution.

Thank you,

-JGL

4 REPLIES

Super User

Joined:

Mar 17, 2015

The best way to do this is a riemann sum.  If all of your x intervals are the same then you can just do the sum and multiply by your interval.

So just add up all of your points in the day and multiply 1 in this case.

Community Trekker

Joined:

Jul 31, 2015

Hi Vince,

Any idea how to do this in JMP?

Super User

Joined:

Mar 17, 2015

Here's a function that will give you a new column of area.  It's not smart enough right now to be able to run while you have reports open so just make sure the window can be sorted.

All you need to do is run the function then call riemann_sum()

riemann_sum = Function(

{dt = Current Data Table(), xcol = "Pick", ycol = "Pick", bycol = "Pick"},

{DEFAULT LOCAL},

Current Data Table( dt );

If( xcol == "Pick",

nc = N Col( dt );

lbwidth = 130;

nw = New Window( "Reimann Sum",

<<Modal,

Border Box( Left( 3 ), top( 2 ),

V List Box(

Text Box( "Gets the Area under a curve" ),

H List Box(

V List Box(

Panel Box( "Select Columns",

colListData = Col List Box( All, width( lbWidth ), nLines( Min( nc, 10 ) ) )

),

),

Panel Box( "Cast Selected Columns into Roles",

Lineup Box( N Col( 2 ), Spacing( 3 ),

Button Box( "Y, Columns", colListY << Append( colListData << GetSelected ) ),

colListY = Col List Box(

width( lbWidth ),

nLines( 1 ),

maxselected( 1 ),

minItems( 1 ),

"numeric"

),

Button Box( "X", colListX << Append( colListData << GetSelected ) ),

colListX = Col List Box(

width( lbWidth ),

nLines( 1 ),

maxselected( 1 ),

minItems( 1 ),

"numeric"

),

Button Box( "By", colListB << Append( colListData << GetSelected ) ),

colListB = Col List Box( width( lbWidth ), nLines( 1 ), maxselected( 1 ) )

)

),

Panel Box( "Action",

Lineup Box( N Col( 1 ),

Button Box( "OK",

ycol = Column((colListY << Get Items)[1]);

xcol = Column((colListX << Get Items)[1]);

nby = nitems(colListB << Get Items);

if(nby,

bycol = Column((colListB << Get Items)[1]),

bycol = New Column("Fakeby", Formula(char(1)));

);

),

Button Box( "Cancel", nw << CloseWindow ),

Text Box( " " ),

Button Box( "Remove",

colListY << RemoveSelected;

colListX << RemoveSelected;

colListB << RemoveSelected;

),

)

)

)

)

)

);

);

Summarize( list_by = By( bycol ) );

dt << Sort(//sorts to make sure x's are in order

By( bycol, xcol ),

Order( Ascending, Ascending ),

Replace Table

);

list_valuesx = xcol << get values;

list_valuesy = ycol << get values;

Wait( 0.1 );

aa = Associative Array();

For( i = 1, i <= N Items( list_by ), i++,

dt << clear select;

list_rows = dt << get rows where( bycol[Row()] == list_by );

//dif_x and sum_y are where the magic happens

dif_x = list_valuesx[list_rows[2 :: (N Row( list_rows ))]] - list_valuesx[list_rows[1 :: (

N Row( list_rows ) - 1)]];

sum_y = .5 * (list_valuesy[list_rows[2 :: (N Row( list_rows ))]] + list_valuesy[list_rows[1 :: (

N Row( list_rows ) - 1)]]);

aa[list_by] = Sum( dif_x :* sum_y );

);

dt << New Column( "Integral", numeric, continuous, formula( aa[bycol[Row()]] ) );

Column( dt, "Integral" ) << delete formula;//makes it then kills it so aa can stay local

if(!nby, dt<<Delete Columns({bycol}));

);

Community Trekker

Joined:

Jul 31, 2015

This looks interesting!

Let me give it a try and I will get back to you.

-JGL