BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted
Community Trekker

## How to save predicteds when using a "Group By" function?

Hello, All

Is there a way to save predicteds when the the "to be predicted" data is grouped using a By statement.

I am using a code like this one:

`Fit Group(    Biv_GRAV_T1 = Bivariate(        Y( :Gravimetric_Flow1_L ),        X( :RatioID ),        Fit Where( :DOY == 31, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 32, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 33, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 34, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 35, Kernel Smoother( 1, 1, 0.1, 0 ) ),        Fit Where( :DOY == 36, Kernel Smoother( 1, 1, 0.1, 0 ) )    ),    Biv_GRAV_T2 = Bivariate(        Y( :Gravimetric_Flow2_L ),        X( :RatioID ),        Fit Where( :DOY == 31, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 32, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 33, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 34, Kernel Smoother( 1, 1, 0.1, 1 ) ),        Fit Where( :DOY == 35, Kernel Smoother( 1, 1, 0.1, 0 ) ),        Fit Where( :DOY == 36, Kernel Smoother( 1, 1, 0.1, 0 ) )    );     Biv_GRAV_T1 << (curve[1] << save predicteds);`

Given that I want to save predicteds by DOY, is there a way to save all days in the same column?

With:

Biv_GRAV_T1 << (curve[1] << save predicteds);

I can save any curve I want, but I want all the curves in the same column. Is there a way to do this?

Something like:

Biv_GRAV_T1 << (curve[1&2&3&4&5&6] << save predicteds);  [I know this does not work, of course  ]

Any help would be appreciated!

-JGL

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How to save predicteds when using a "Group By" function?

Here is a sample of code that uses your method, but in the end, combines all of the predicted

Names Default To Here( 1 );

dt = Open( "\$SAMPLE_DATA/semiconductor capability.jmp" );

Fit Group(

Biv_GRAV_T1 = Bivariate(

Y( :npn1 ),

X( :pnp2 ),

Fit Where( :Site == 1, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 2, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 3, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 4, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 5, Kernel Smoother( 1, 1, 0.1, 0 ) )

),

Biv_GRAV_T2 = Bivariate(

Y( :npn2 ),

X( :pnp2 ),

Fit Where( :Site == 1, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 2, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 3, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 4, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 5, Kernel Smoother( 1, 1, 0.1, 0 ) )

);

Biv_GRAV_T1 << (curve[1] << save predicteds);

Biv_GRAV_T1 << (curve[2] << save predicteds);

Biv_GRAV_T1 << (curve[3] << save predicteds);

Biv_GRAV_T1 << (curve[4] << save predicteds);

Biv_GRAV_T1 << (curve[5] << save predicteds);

Biv_GRAV_T2 << (curve[1] << save predicteds);

Biv_GRAV_T2 << (curve[2] << save predicteds);

Biv_GRAV_T2 << (curve[3] << save predicteds);

Biv_GRAV_T2 << (curve[4] << save predicteds);

Biv_GRAV_T2 << (curve[5] << save predicteds);

);

// Create new columns that are composites of the saved predicteds

dt << New Column( "All NPN1 Predicted",

formula( Sum( :Predicted NPN1, :Predicted NPN1 2, Predicted NPN1 3, :Predicted NPN1 4, :Predicted NPN1 5 ) )

);

dt << New Column( "All NPN2 Predicted",

formula( Sum( :Predicted NPN2, :Predicted NPN2 2, Predicted NPN2 3, :Predicted NPN2 4, :Predicted NPN2 5 ) )

);

// Delete the formulas so the columns used in the formulas can be deleted

dt:All NPN1 Predicted << delete Property( "formula" );

dt:All NPN2 Predicted << delete Property( "formula" );

// Delete all of the incomplete columns

dt << delete columns(

{:Predicted NPN1, :Predicted NPN1 2, :Predicted NPN1 3, :Predicted NPN1 4, :Predicted NPN1 5, :Predicted NPN2, :Predicted NPN2 2, :Predicted NPN2 3, :Predicted NPN2 4, :Predicted NPN2 5}

);

Jim
2 REPLIES 2
Super User

## Re: How to save predicteds when using a "Group By" function?

Here is a sample of code that uses your method, but in the end, combines all of the predicted

Names Default To Here( 1 );

dt = Open( "\$SAMPLE_DATA/semiconductor capability.jmp" );

Fit Group(

Biv_GRAV_T1 = Bivariate(

Y( :npn1 ),

X( :pnp2 ),

Fit Where( :Site == 1, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 2, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 3, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 4, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 5, Kernel Smoother( 1, 1, 0.1, 0 ) )

),

Biv_GRAV_T2 = Bivariate(

Y( :npn2 ),

X( :pnp2 ),

Fit Where( :Site == 1, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 2, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 3, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 4, Kernel Smoother( 1, 1, 0.1, 1 ) ),

Fit Where( :Site == 5, Kernel Smoother( 1, 1, 0.1, 0 ) )

);

Biv_GRAV_T1 << (curve[1] << save predicteds);

Biv_GRAV_T1 << (curve[2] << save predicteds);

Biv_GRAV_T1 << (curve[3] << save predicteds);

Biv_GRAV_T1 << (curve[4] << save predicteds);

Biv_GRAV_T1 << (curve[5] << save predicteds);

Biv_GRAV_T2 << (curve[1] << save predicteds);

Biv_GRAV_T2 << (curve[2] << save predicteds);

Biv_GRAV_T2 << (curve[3] << save predicteds);

Biv_GRAV_T2 << (curve[4] << save predicteds);

Biv_GRAV_T2 << (curve[5] << save predicteds);

);

// Create new columns that are composites of the saved predicteds

dt << New Column( "All NPN1 Predicted",

formula( Sum( :Predicted NPN1, :Predicted NPN1 2, Predicted NPN1 3, :Predicted NPN1 4, :Predicted NPN1 5 ) )

);

dt << New Column( "All NPN2 Predicted",

formula( Sum( :Predicted NPN2, :Predicted NPN2 2, Predicted NPN2 3, :Predicted NPN2 4, :Predicted NPN2 5 ) )

);

// Delete the formulas so the columns used in the formulas can be deleted

dt:All NPN1 Predicted << delete Property( "formula" );

dt:All NPN2 Predicted << delete Property( "formula" );

// Delete all of the incomplete columns

dt << delete columns(

{:Predicted NPN1, :Predicted NPN1 2, :Predicted NPN1 3, :Predicted NPN1 4, :Predicted NPN1 5, :Predicted NPN2, :Predicted NPN2 2, :Predicted NPN2 3, :Predicted NPN2 4, :Predicted NPN2 5}

);

Jim
Community Trekker

## Re: How to save predicteds when using a "Group By" function?

Hi Jim,

I would have never thought of this method. And of course, adding them up makes sense because non-predicted values should have empty cells.

Thanks a lot, I really appreciate it.

-JL