我目前第一次使用 JSL 來自動化數據分析/報告。 我的分析涉及:
1.導入所需數據(完成)
2. 分析數據(data)
3. 使用計算數據執行雙變量分析並擬合直線(完成)
4. 使用生成的回歸方程來預測特定“y”值的“x”:這就是我的問題所在。 我希望能夠在 JSL 中從“y”動態生成“x”。 我也不想手動輸入回歸方程,因為這對於不同的數據集會有所不同。
有什麼指點嗎?
這使用擬合曲線平台並保存具有逆預測的公式列。
dt=open("$Sample_Data/Big Class.jmp");
model= Fit Curve( Y( :height ), X( :weight ) );
model<< Fit Linear(Save Inverse Prediction Formula);
您可以只使用表中的值,但也可以獲取公式列屬性,
我應該要求澄清。你真的想做逆向預測嗎?如果是這樣,您仍然可以使用我的方法,只需使用 (:height - coef[1])/coef[2] 執行公式
最簡單的方法可能是使用擬合模型並獲取內置逆預測的擬合最小二乘平台。
你好@艾納斯基德
可能有一百萬種方法可以實現您想要做的事情。這取決於您想要如何給出預測變量的值以獲得預測響應。您想在用戶輸入數字、按下按鈕、窗口返回預測的對話框中執行此操作嗎?將 X 的新值作為附加行放入數據表中並讓預測公式在列中返回預測值是否可以接受?
我將快速向您展示如何執行後者,因為它更容易。以下是使用 Big Class 數據集並根據體重預測身高的示例:
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
現在,您應該會在 Big Class 中看到一個包含預測的新列。由於它是一個公式,我可以添加帶有重量值的新行並獲得新的高度預測。在這裡,我添加了一行 200,得到了 75.42 作為預測
我想指出的是,如果您在“擬合模型”平台中擬合模型,這會更容易,因為您只需向“擬合模型”對象發送<< 預測公式消息即可獲取包含預測公式的列。
FitMod = dt << Fit Model(
Y( :height ),
Effects( :weight ),
Personality( "Standard Least Squares" ),
Emphasis( "Effect Leverage" ), Run()
);
FitMod << Prediction Formula;