cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Ainaskid
Level II

JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equation?

I'm currently using JSL for the first time to automate data anlysis/reporting. My analysis involves:

1. Importing the required data (done)

2. Analysing the data (data)

3. Using computed data to perform a bivariate analysis and fitting a line (done)

4. Using the generated regression equation to predict 'x' for specific 'y' values: Here's where my problem lies. I'd like to have the capability of dynamically generating 'x' from 'y' in JSL. I also don't want to have to type in the regression equation manually since this would differ for different data sets.

Any pointers? 

1 ACCEPTED SOLUTION

Accepted Solutions
cwillden
Super User (Alumni)

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

Hi @Ainaskid

There's probably a million ways to get what you are trying to do.  It depends on how you want to give the values of the predictors to get the predicted response.  Do you want to do it in a dialog box where the user inputs a number, presses a button, and the window returns a prediction?  Would it be acceptable to just put new values of X as additional rows in your data table and have a prediction formula return the predicted value in a column?

I'll show you quickly how to do the latter since it is easier.  Here's an example using the Big Class data set and predicting height from weight:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

biv = dt << Bivariate( Y( :height ), X( :weight ), Fit Line() ); //get reference to Bivariate object
rpt = (biv << Report); //get reference to report window for Biv

//get the coefficients from the parameter estimates table
Coefs = (rpt["Parameter Estimates"][Table Box( 1 )] << Get as Matrix)[0, 1];

//Create prediction formula from the coefficients
Eval(
Parse(
Eval Insert( "\[dt << New Column("Prediction Formula", formula(^Coefs[1]^ + ^Coefs[2]^*:weight))]\" )
)
);
//You'll want to hard code in the value of the coefs using the string
//Otherwise this column won't work once Coefs is no longer defined or the value has changed
//The "Eval Insert" function inserts the value of Coefs[1] and Coefs[2] into the formula - this is how it is hard-coded in

Now, you should see a new column in Big Class with the predictions.  Since it's a formula, I can add new rows with weight values and get new height predictions.  Here, I added a row for 200, and got 75.42 as the predictionPredictions.PNG

I want to point out that this is even easier if you fit the model in the Fit Model platform instead since you can just send a << Prediction Formula message to the Fit Model object to get the column with the prediction formula. 

FitMod = dt << Fit Model(
	Y( :height ),
	Effects( :weight ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Effect Leverage" ), Run()
);

FitMod << Prediction Formula;
-- Cameron Willden

View solution in original post

5 REPLIES 5
cwillden
Super User (Alumni)

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

Hi @Ainaskid

There's probably a million ways to get what you are trying to do.  It depends on how you want to give the values of the predictors to get the predicted response.  Do you want to do it in a dialog box where the user inputs a number, presses a button, and the window returns a prediction?  Would it be acceptable to just put new values of X as additional rows in your data table and have a prediction formula return the predicted value in a column?

I'll show you quickly how to do the latter since it is easier.  Here's an example using the Big Class data set and predicting height from weight:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

biv = dt << Bivariate( Y( :height ), X( :weight ), Fit Line() ); //get reference to Bivariate object
rpt = (biv << Report); //get reference to report window for Biv

//get the coefficients from the parameter estimates table
Coefs = (rpt["Parameter Estimates"][Table Box( 1 )] << Get as Matrix)[0, 1];

//Create prediction formula from the coefficients
Eval(
Parse(
Eval Insert( "\[dt << New Column("Prediction Formula", formula(^Coefs[1]^ + ^Coefs[2]^*:weight))]\" )
)
);
//You'll want to hard code in the value of the coefs using the string
//Otherwise this column won't work once Coefs is no longer defined or the value has changed
//The "Eval Insert" function inserts the value of Coefs[1] and Coefs[2] into the formula - this is how it is hard-coded in

Now, you should see a new column in Big Class with the predictions.  Since it's a formula, I can add new rows with weight values and get new height predictions.  Here, I added a row for 200, and got 75.42 as the predictionPredictions.PNG

I want to point out that this is even easier if you fit the model in the Fit Model platform instead since you can just send a << Prediction Formula message to the Fit Model object to get the column with the prediction formula. 

FitMod = dt << Fit Model(
	Y( :height ),
	Effects( :weight ),
	Personality( "Standard Least Squares" ),
	Emphasis( "Effect Leverage" ), Run()
);

FitMod << Prediction Formula;
-- Cameron Willden

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

Another approach: Use Fit Model and then use the Inverse Prediction command.

Dan Obermiller

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

The easiest way might be to use Fit Model and get the Fit Least Squares platform that has Inverse Prediction built in.

cwillden
Super User (Alumni)

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

I should have asked for clarification.  Did you really want to do inverse prediction?  If so, you can still use my method and just do a formula with (:height - coef[1])/coef[2]

-- Cameron Willden
Byron_JMP
Staff

Re: JSL- Is there a way to automatically interpolate 'x' values from from 'y' using regression equat

This uses the fit curve platfrom and saves a formula column with the inverse predictions.

dt=open("$Sample_Data/Big Class.jmp");
model= Fit Curve( Y( :height ), X( :weight ) );
model<< Fit Linear(Save Inverse Prediction Formula);

you could either just use the values in the table, but you could also get the formula column property,

 

JMP Systems Engineer, Health and Life Sciences (Pharma)