I would like to perform a modified Poisson regression using JMP.
I would also like to display confidence intervals using robust variance.
Could you please explain in detail how to do this in JMP?
Thank you very much in advance.
ただ、修正ポアソン回帰はロバスト分散を使用することで正しい信頼区間を計算しているのですよね?
ロバスト分散とサンドイッチ分散は同じものを指しているという理解でよろしいでしょうか?
log(p/(1-p)) = β0 + β1 x
β1 = log(p1/(1-p1)) - log(p0/(1-p0))
β1 = log({p1/(1-p1)}/{p0/(1-p0)})
exp(β1) = {p1/(1-p1)}/{p0/(1-p0)}
{p1/(1-p1)}/{p0/(1-p0)}≒p1/p0
log(p) = β0 + β1 x
log(p1/p0) = β1 p1/p0 = exp(β1)
New Table("Test", New Column("X1", Nominal, Character,Values({"A","A","A","A","A","A","B","B","B","B","B","B","B","B","B"})), New Column("X2", Values([5,4,3,2,1,4,5,4,3,3,3,2,1,5,4])), New Column("Y", Values([0,1,0,1,0,1,1,0,1,1,0,1,1,0,1])); );
R Init(); R Submit(" R.Version(); print('Hello, World!') ");
R Init(); dt = Current Data Table(); dt << New Column("ID", Nominal, Formula(Row())); Wait(0); R Send(dt);
R Submit(" if (!require('geepack')) { install.packages('geepack') } library(geepack) gee.result <- geeglm(Y~X1 + X2, data=dt, id = ID, family=poisson('log')) summary(gee.result) est <- coef(gee.result) se <- diag(vcov(gee.result)) z <- qnorm(0.975) print('Risk Ratios and the Confidence Interlvals') print(cbind(exp(est), exp(est - se*z), exp(est + se*z))) ");
/* 以下のURLを参考にしました。https://www.ism.ac.jp/~noma/file/software/rqlm_JPN.pdf */ R Submit(" if (!require('rqlm')) { install.packages('rqlm') } library(rqlm) mpr.result <- rqlm(Y ~ X1 + X2, data=dt, family=poisson, eform=TRUE) mpr.result ");
from jmputils import jpip jpip('install --upgrade', 'pip setuptools certifi') jpip('install', 'numpy pandas statsmodels')
import jmp import numpy as np import pandas as pd import statsmodels as sm from statsmodels.genmod.generalized_estimating_equations import GEE from statsmodels.genmod.families import Poisson from statsmodels.genmod.families.links import log from statsmodels.genmod.cov_struct import Independence
dt = jmp.current() data = pd.DataFrame( { 'Y': dt['Y'][0:n], 'X1': dt['X1'][0:n], 'X2': dt['X2'][0:n], 'ID': dt['ID'][0:n] } )
data['X1B'] = (data['X1'] == 'B').astype(int) print(data)
model = GEE.from_formula( "Y ~ X1B + X2", groups="ID", data=data, family=Poisson(link=log()), cov_struct=Independence()) model = GEE(Ydata, Xdata, groups=ID, cov_struct=cov_struct, family=Poisson(link=Log())) result = model.fit() print(result.summary()) print(result.cov_robust) print(np.exp(result.params)) print(np.exp(result.conf_int()))
Names Default To Here(1); dt = Current Data Table(); /* 自分で指示変数(ダミー変数)を作成しないといけない */ x1 = Design(Column(dt, "X1")<<Get As Matrix); //x1 = x1[0, 1::(NCol(x1)-1)]; x1 = x1[0, 2]; /* x2は連続変数なので、そのまま使える */ x2 = Column(dt, "X2")<<Get As Matrix; /* この例では、yはすでに0,1になっているものとする */ y = Column(dt,"y")<<Get As Matrix; /* 計画行列(切片を付ける) */ x = J(NRow(x1),1,1)||x1||x2; /* Newton-Raphson法スタート */ b = J(NCol(x),1,0); maxit = 1000; check = 0; For(i = 1, i <= maxit, i++, eta = x*b; pred =Exp(eta); g = x`*(y - pred); h = x` * Diag(pred) * x; If(check == 1, Break()); new b = b + Inv(h)*g; If(Max(Abs(new b - b))<1e-18, check=1); b = new b; ); /* サンドイッチ分散 */ /* Inv(h) * X` * Diag((y - pred)^2) * X * Inv(h)が、A*B*Aの形になっているので「サンドイッチ分散」*/ se = Sqrt(VecDiag(Inv(h) * X` * Diag((y - pred)^2) * X * Inv(h))); p = 2*Normal Distribution(-Abs(b:/se)); /* 結果の表示 */ New Window("Test", Outline Box("Result", Table Box( Number Col Box("exp(Est)", Exp(b)), Number Col Box("Stderr for Est", se), Number Col Box("Low CL exp(Est)", Exp(b - Normal Quantile(0.975)*se)), Number Col Box("Up CL exp(Est)", Exp(b + Normal Quantile(0.975)*se)), Number Col Box("p-value", p) ) ) );
Hi @Shintaro1120,Welcome in the Community !Poisson regression is available through Generalized Regression models in JMP Pro. You can check the available distributions for these models.Could you please add more details (and if possible an anonimized or toy dataset) about what you're trying to achieve if you want a more detailed guidance/help from JMP users ?
Hello, I am Yusuke Ono, Senior Tester at JMP Japan Group in SAS Institute Japan.
You can fit modified Poisson regression (and modified OLS regression) by Generalized Linear Mixed Model platform on JMP Pro 19, the next new major JMP release.
When you use this feature, the Y variable should be 0 and 1 (even if Y is originally binary categorical variable) in your data. You can convert the binary data to 0-1 indicator variable by Cols-Utilities-Indicator Columns. After preparing the 0-1 data, select Analyze - Fit Model. Select Generalized Linear Mixed Model for the Personality and select Poisson for Distribution (If you want to fit modified OLS, select Normal for Distribution). Set the 0-1 Y variable and Model Effects. Click Run button. Select Model Report - Empirical Standard Errors (Standard Errors by Sandwich Variance in Japanese) from the red triangle menu at the Poisson outline in the report window. Now, all standard errors, tests, and confidence intervals are calculated by sandwich variances (a.k.a. empirical variances or robust standard variances). Note that the point estimates are not changed by this menu. Only standard errors, tests, and confidene intervals are changed. If you want Exp(b) where b is the point estimates or confidence limits, to calculated point estimates and confidence intervals for risk ratios, you need to output the estimation table to a JMP data table, and convert them to Exp(b) by yourself.
This "Sandwich variance" feature in JMP Pro 19's Generalized Linear Mixed Models (and Mixed Models) is really one of new features for JMP users in epidemiology and medical area. By this feature, you can also calculate standard errors for the Inverse Probability Weighting (IPW) (with assuming the weights are known).
On JMP 18 or before, there is no feature for fitting modified Poisson regression. You can fit Log-Binomial models (where the Distribution is binomial and the link function is Log function) on the Generalized Linear Models platform. But the fitting may fail and the predict probability values exceed zero or one in the Log-Binomial models. You can fit Genearlized Linear Models by selecting Analyze - Fit Model, and select Genearlized Linear Models for the Personality. The Generalized Linear Models is supported by standard JMP 18 or before. (The Genearalized Linear Mixed Models is supported only by JMP Pro.)
CORRECTION:
If you want Exp(b) where b is the point estimates or confidence limits, to calculated point estimates and confidence intervals for risk ratios, you need to output the estimation table to a JMP data table, and convert them to Exp(b) by yourself.
You can calculate Exp(b) in modified Poisson regression by Multiple Comparions. You can select this menu from the red triangle menu for the Poisson outline. Sorry for my misunderstanding.
Thank you for your reply.Thank you also for the detailed explanation.However, I am stuck halfway through.I had been planning to use Generalized Linear Models to perform modified Poisson regression, but based on your advice, I will use Generalized Linear Mixed Model for the Personality to perform modified Poisson regression.“Select Model Report - Empirical Standard Errors (Standard Errors by Sandwich Variance in Japanese) from the red triangle menu at the Poisson outline in the report window. Now, all standard errors, tests, and confidence intervals are calculated by sandwich variances (a.k.a. empirical variances or robust standard variances).” I don’t quite understand this. Could you please explain this part and your correction in more detail, even in Japanese?I have taken a screenshot to illustrate the current situation and have attached it. I would appreciate it if you could review it.
Thank you very much for your assistance.
By the way, I am using JMP Pro 18. Could you please help me perform the modified Poisson regression?
Thank you very much for your assistance.Best regards,
I am sorry for the confusion. The feature I explained is a new feature for JMP Pro 19. You cannot use the new feature on JMP Pro 18.
If you select Poisson distribution and Log link function in the Generalized Linear Models platform, the standard Poisson regression is fit. It assumes Poisson distribution, not binomial distribution, for the distribution of Y variable. The point estimates in the standard Poisson regression models are the same as the ones in the modified Poisson regression models, but standard errors are different. In modified Poisson regression, the standard errors are calculated by "sandwich variances", so the standard errors are valid also when the true distribution is binomial (if the sample size is large).
Even in JMP 18 or before, you can fit log-binomial model. If the response distribution is selected as Binomial and the link function is selected as Log in the Generalized Linear Models platform, then log-binomial model is estimated. Note that the optimization might fail (This is one of some reasons why the modified Poisson regression is preferred in practice). And, you need to be careful that in JMP's Generalized Linear Models platform, "effect-coding" is used for nominal X variables (like the Standard Least Squares and Nominal Logistic platform).
If you really want to do the modified Poisson regression on JMP Pro 18 or before, you need to program the algorithm from scratch with JMP Scripting Language(JSL), or program the code to invoke a routine to fit modified Poisson regression models in R or Python from JMP with JMP Scripting Language(JSL).
If you have more questions, I would like you to reply again.
混乱させてしまいすみません。先月に説明した機能はJMP Pro 19のものです。こちらの機能はJMP Pro 18以前ではまだ実装されていません。
もし「一般化線形モデル」プラットフォームにおいて、Poisson分布を応答変数の分布に、対数をリンク関数に指定すると、通常のPoisson回帰が実行されます。この分析では、二項分布ではなく、Poisson分布が仮定されます。通常のPoisson回帰の回帰係数に対する点推定値は、修正Poisson回帰のものと同じです。しかし、標準誤差は両者で異なります。修正Poisson回帰では、標準誤差は「サンドイッチ分散」によって計算されます。この「サンドイッチ分散」を用いることにより、真の分布が二項分布である場合でも、(大標本の場合には)標準誤差が妥当なものとなります。
JMP 18以前でも、対数-二項モデルならばあてはめることができます。「一般化線形モデル」プラットフォームにて、分布を二項分布に、リンク関数を対数に指定すると、この対数-二項モデルがあてはめられます。ただし、対数尤度を最大化するための最適化計算が失敗する場合もあります(対数-二項分布では最適化計算が失敗することが、修正Poisson回帰のほうが好まれる理由の1つです)。また、「一般化線形モデル」では、(「標準最小2乗」や「名義ロジスティック」と同様)名義尺度の説明変数に対して「効果コーディング」というコーディング方法を使っています。
どうしても、JMP Pro 18で修正Poisson回帰を行いたい場合には、(1) 自分自身でアルゴリズムをプログラミングするか、(2) RもしくはPythonで該当の機能を呼び出すプログラムを作成する、といったJMPスクリプト言語(JSL)によるプログラミングが必要となってきます。JMP Pro 19からは、先日申し上げた方法で簡単に実行できるようになります。
何かご不明な点などがありましたら、遠慮なくご返信ください。