@Jeff_Perkinson , @Milo ,
這是參考討論 - 斜率和截距函數
我發現這個討論很有幫助。我目前正在使用JMP 13,所以如果在JMP 14中進行了開發,我不一定能夠訪問它。
但是,這是我的問題:
Clear Log() ; Clear Globals(); Close All(DataTables,"No Save");
Slope = function({x,y},{default local},
If( !(Is Matrix( x ) & Is Matrix( y ) & N Col( x ) == 1 & N Col( y ) == 1),
Show( "x or y arguments are not matrices or they have more than one column" );
Throw();
,
x = J( N Row( x ), 1 ) || x; // put in an intercept column of 1s
beta = Inv( X` * X ) * X` * Y; // the least square estimates
beta[2];
);
);
Intercept = function({x,y},{default local},
If( !(Is Matrix( x ) & Is Matrix( y ) & N Col( x ) == 1 & N Col( y ) == 1),
Show( "x or y arguments are not matrices or they have more than one column" );
Throw();
,
x = J( N Row( x ), 1 ) || x; // put in an intercept column of 1s
beta = Inv( X` * X ) * X` * Y; // the least square estimates
beta[1];
);
); // end of intercept function
x1 = 0.05417099;
x2 = 0.057730865;
y1 = 30.5885;
y2 = 31.5885;
dt = New Table();
dt << New Column("X",Numeric,Continuous,<< Set Values({x1,x2}))
<< New Column("Y",Numeric,Continuous,<< Set Values({y1,y2}));
dt << New Script("Biv",Bivariate( Y( :Y ), X( :X ), Fit Line( {Line Color( {213, 72, 87} )} ) ));
SlopeTest = Slope(Matrix({y1,y2}),Matrix({x1,x2}));
Show(SlopeTest);
InterceptTest = Intercept(Matrix({y1,y2}),Matrix({x1,x2}));
Show(InterceptTest);
1。為什麼斜率和截距與我採用雙變量的測試用例不匹配?
2。如果函數或其實現有錯誤,您是否願意提供替代方案?
您輸入的順序是向後的。 在函數上它是斜率(x,y),當你打電話給你做斜率(y,x)
@cwillden ,
雖然這是一個很好的捕獲,但並沒有改變結果,功能與二變量不匹配
你得到了Slope and Intercept函數的後向參數。 只需顛倒矩陣的順序即可。