cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
  • New JMP features coming to desktops everywhere this September. Sign up to learn more at jmp.com/launch.
Choose Language Hide Translation Bar
Caozheng0115
Level III

JMP script to generate cumulative value after modeling

Hi, all
I am new to JMP and tried to write a script
I use JMP 18 standard and perform recurrence analysis. The model I use is loglinear NHPP. I want to generate specific cumulative value at 100k, 200k, 300k, 400k and 500k transactions. I can see there is click option in the UI for each transaction (shown in the attachment). But I want to automate this using scripts. Following is the script I tried: It generate an error in the figure. Is there Could you help me with the code?

Caozheng0115_3-1756390218559.png

 

 

 

Caozheng0115_0-1756389953346.png

 

// Run the analysis and capture the report
rec_report = Recurrence Analysis(
	Y( :Accumulated Transactions ),
	Label( :BOT ID ),
	Cost( :SAP Purchase Price ),
	Grouping( :Bot Series ),
	Event Plot( 0 ),
	MCF Confid Limits( 1 ),
	Fit Model(
		Scale Effects( :Bot Series ),
		Shape Effects( :Bot Series ),
		Run Model,
		Model Type( "Loglinear Nonhomogeneous Poisson Process" )
	)
);

// --- Extract Estimates ---
// Get the "Estimates" table directly from the report and convert it to a scriptable object
estimates_table = rec_report["Loglinear NHPP Report", "Estimates"] << Table Box;

// Get the 'Estimate' column values as a list.
// The order is consistently Lambda, then Beta.
estimates_list = estimates_table << Get Values( "Estimate" );

// Assign the parameter estimates from the list
lambda_hat = estimates_list[1]; // Lambda (λ) is the first estimate
beta_hat = estimates_list[2]; // Beta (β) is the second estimate

// Define the transactions for which to calculate values
transactions = {100000, 200000, 300000, 400000, 500000};

// Calculate and display intensity and cumulative values
For( i = 1, i <= N Items( transactions ), i++,
	transaction_time = transactions[i];

	// Cumulative Mean Function C(t) = λ * t^β
	cumulative = lambda_hat * (transaction_time ^ beta_hat);

	// Instantaneous Intensity λ(t) = λ * β * t^(β-1)
	intensity = lambda_hat * beta_hat * (transaction_time ^ (beta_hat - 1));

	// Print the results to the log
	Show( transaction_time, cumulative, intensity );
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: JMP script to generate cumulative value after modeling

Your script very strongly looks like AI generated... Note that these are not documented in Scripting Index (<< Save Intensity Formula and << Save Cumulative Formula) but you can "figure it out" by tinkering around

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Reliability/Bladder Cancer.jmp");
ra = dt << Recurrence Analysis(
	Y(:Age),
	Label(:Patient Number),
	Cost(:Cost),
	Grouping(:Treatment Group),
	Event Plot(1),
	Fit Model(
		Scale Effects(:Age),
		Run Model,
		Model Type("Proportional Intensity Poisson Process")
	)
);

fit = Report(ra)[OutlineBox("Fitted Recurrence Model")] << Get Scriptable Object;

intensity_col = fit << Save Intensity Formula;
cumul_col = fit << Save Cumulative Formula;

i_f = intensity_col << Get Formula;
c_f = cumul_col << Get Formula;

transactions = {1, 2, 3, 4, 5};
dt_s = New Table("Specific Intensity and Cumulative",
	New Column("Age", Numeric, "Continuous", Values(transactions))
);

Eval(Eval Expr(
	dt_s << New Column("Intensity", Numeric, Continuous, Formula(
		Expr(NameExpr(i_f))
	));
));

Eval(Eval Expr(
	dt_s << New Column("Cumulative", Numeric, Continuous, Formula(
		Expr(NameExpr(c_f))
	));
));

Write();

@julian 

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: JMP script to generate cumulative value after modeling

Most likely you wish to include Table Box inside your report subscript instead of sending a message to it

estimates_table = rec_report["Loglinear NHPP Report", "Estimates", Table Box(1)]

Also I think your "Estimates" should be "Parameter Estimates" (or use ? wildcard)'. Here is example until that point using JMP's sample data

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Reliability/Bladder Cancer.jmp");

ra = dt << Recurrence Analysis(
	Y(:Age),
	Label(:Patient Number),
	Cost(:Cost),
	Grouping(:Treatment Group),
	Event Plot(1),
	Fit Model(
		Scale Effects(:Intensity),
		Shape Effects(:Intensity),
		Run Model,
		Model Type("Power Nonhomogeneous Poisson Process")
	)
);


tb = Report(ra)[OutlineBox("Fitted Recurrence Model"), OutlineBox("Parameter Estimates"), TableBox(1)];
estimates = tb[NumberColBox("Estimate")] << get;
-Jarmo
Caozheng0115
Level III

Re: JMP script to generate cumulative value after modeling

Hi, jthi

It works now. Thanks a lot.
I should not try to create my own formular. There is 'Specific Intensity and Cumulative' under 'Fitted Recurrence Model' after I run the model in JMP. It can generate the cumulative value with confidence interval. I can just use the formular instead of creating a new one. I tried to get the formular to generate new results in a table. But failed. Could you help? The error is in the image. Thanks again.

Caozheng0115_0-1756479195959.png

 

Names Default To Here( 1 );

// --- Run the analysis ---
rec_report = Recurrence Analysis(
	Y( :Accumulated Transactions ),
	Label( :BOT ID ),
	Cost( :SAP Purchase Price ),
	Grouping( :Bot Series ),
	Event Plot( 0 ),
	MCF Confid Limits( 1 ),
	Fit Model(
		Scale Effects( :Bot Series ),
		Shape Effects( :Bot Series ),
		Run Model,
		Model Type( "Loglinear Nonhomogeneous Poisson Process" )
	)
);

// --- Save JMP’s own formulas into the source table ---
rec_report << Save Intensity Formula;
rec_report << Save Cumulative Formula;

// Grab those formulas so we can reuse them in a clean table
dt_src=Current Data Table();
intensity_formula  = Column( dt_src, "Intensity" )  << Get Formula;
cumulative_formula = Column( dt_src, "Cumulative" ) << Get Formula;

// --- Define the transaction times you care about ---
transactions = {100000, 200000, 300000, 400000, 500000};

// --- Build a results table with JMP-calculated fitted values ---
dt_sic = New Table( "Specific Intensity and Cumulative",
	New Column( "Accumulated Transactions", Numeric, "Continuous", Values( transactions ) ),
	New Column( "Intensity",  Numeric, Formula( intensity_formula ) ),
	New Column( "Cumulative", Numeric, Formula( cumulative_formula ) )
);

// Evaluate formulas and show the table
dt_sic << Recalculate;
dt_sic << Bring Window To Front;

  

jthi
Super User

Re: JMP script to generate cumulative value after modeling

Your script very strongly looks like AI generated... Note that these are not documented in Scripting Index (<< Save Intensity Formula and << Save Cumulative Formula) but you can "figure it out" by tinkering around

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Reliability/Bladder Cancer.jmp");
ra = dt << Recurrence Analysis(
	Y(:Age),
	Label(:Patient Number),
	Cost(:Cost),
	Grouping(:Treatment Group),
	Event Plot(1),
	Fit Model(
		Scale Effects(:Age),
		Run Model,
		Model Type("Proportional Intensity Poisson Process")
	)
);

fit = Report(ra)[OutlineBox("Fitted Recurrence Model")] << Get Scriptable Object;

intensity_col = fit << Save Intensity Formula;
cumul_col = fit << Save Cumulative Formula;

i_f = intensity_col << Get Formula;
c_f = cumul_col << Get Formula;

transactions = {1, 2, 3, 4, 5};
dt_s = New Table("Specific Intensity and Cumulative",
	New Column("Age", Numeric, "Continuous", Values(transactions))
);

Eval(Eval Expr(
	dt_s << New Column("Intensity", Numeric, Continuous, Formula(
		Expr(NameExpr(i_f))
	));
));

Eval(Eval Expr(
	dt_s << New Column("Cumulative", Numeric, Continuous, Formula(
		Expr(NameExpr(c_f))
	));
));

Write();

@julian 

-Jarmo
Caozheng0115
Level III

Re: JMP script to generate cumulative value after modeling

Hi, jthi
Thanks, this works. All my code is generated by AI. I start to script in JMP last week. I can hardly wrote a single line of code by myself. Is there a place that I can learn JMP script?
Thanks.

jthi
Super User

Re: JMP script to generate cumulative value after modeling

Use enhanced log in JMP and learn the different methods how JMP is able to create some of the scripts for you. There is also Scripting Guide , you have direct access to Scripting Index from JMP's Help menu and JMP Community does have a lot of content like  Introduction to the JMP Scripting Language , JMP Scripters Club and JSL Cookbook .

-Jarmo

Recommended Articles