<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issue calculating confidence interval in hierarchical linear model macro in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/905923#M6150</link>
    <description>&lt;P&gt;I have a macro for performing HLM and logistic regression and then outputting a results table with the odds ratios and 95% confidence intervals from both models. When I apply the macro and try to run it, it is not able to generate the upper 95% CI for the logistic regression (OR_lr95UCI). If I remove this line from the code, it generates a table with all other results but when I include this variable, the code does not run. I am calculating it the same way as the lower limit&amp;nbsp; (OR_lr95LCI), so I don't know what is causing the issue. I have copied the macro below, with the problem variable bolded.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO HLM2(data=, outcome=, covariates=, data2=, covariates2=, b2index=);&lt;BR /&gt;&lt;BR /&gt;/* Run PROC LOGISTIC, result is in the data set logistic_output */&lt;BR /&gt;&lt;BR /&gt;proc logistic data=&amp;amp;DATA desc COVOUT OUTEST=logistic_output;&lt;BR /&gt;model &amp;amp;OUTCOME = &amp;amp;COVARIATES ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;/****************************************************************&lt;BR /&gt;*** Hirearchical model using empirical-Bayes or semi-Bayes estimation. ***&lt;BR /&gt;****************************************************************/&lt;BR /&gt;start hm_reg(b,v,z,t2,max_iter,c_criter,b_hm,bcov_hm,b2);&lt;BR /&gt;/****************************************************************&lt;BR /&gt;** Input: b : 1st-stage parameter estimates&lt;BR /&gt;** v : 1st-stage covariance matrix estimates for b&lt;BR /&gt;** z : 2nd-stage design matrix (prior design matrix)&lt;BR /&gt;** t2 : prior variance for semi-Bayes estimation (vector),&lt;BR /&gt;** (0 if prior variance is to be estimated using&lt;BR /&gt;** emirical-Bayes estimation.)&lt;BR /&gt;** max_iter: maximum number of iteration (default is 20)&lt;BR /&gt;** c_criter: convergence criteria (default is 1e-3)&lt;BR /&gt;** Output: b_hm : posterier estimates&lt;BR /&gt;** bcov_hm : covariance matrix for b&lt;BR /&gt;** b2 : 2nd-stage parameter estimates&lt;BR /&gt;****************************************************************/&lt;/P&gt;&lt;P&gt;/*** Number of first-stage parameters.***/&lt;BR /&gt;np = nrow(Z);&lt;BR /&gt;ncolz = ncol(Z);&lt;BR /&gt;/*** Second-stage degrees of freedom. */&lt;BR /&gt;df2 = np-ncolz; Inp = I(np);&lt;BR /&gt;/*** Empirical-Bayes estimation, else semi-Bayes estimation. ***/&lt;BR /&gt;if (min(t2) &amp;lt;= 0) then t2pass = 0; else t2pass = 1;&lt;BR /&gt;/*** Maximum number of iterations, and convergence criterion for t2. ***/&lt;BR /&gt;if max_iter = 0 then _maxiter = 20; else _maxiter = max_iter;&lt;BR /&gt;if c_criter = 0 then _criter = 1e-3; else _criter = c_criter;&lt;/P&gt;&lt;P&gt;if t2pass = 0 then do;&lt;BR /&gt;print np[format=4.0] " first stage parameters were regressed on"&lt;BR /&gt;ncolz[format=4.0] " second stage covariate(s)",&lt;BR /&gt;" using empirical-Bayes estimation method (prior variance (t2) to be estimated).";&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;print np[format=4.0] " first stage parameters were regressed on"&lt;BR /&gt;ncolz[format=4.0] " second stage covariate(s)",&lt;BR /&gt;" using semi-Bayes estimation with prior variance (t2) fixed at" t2[format=8.4];&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/*** Undertake second-stage regression: ***/&lt;BR /&gt;t2old = t2+1;&lt;BR /&gt;do iter = 1 to _maxiter while(abs(t2-t2old) &amp;gt; _criter);&lt;BR /&gt;t2old = t2;&lt;BR /&gt;/*** Weight matrix. ***/&lt;BR /&gt;w = inv(v+t2#Inp); wv = w*v; wz = w*z; ws = sum(w);&lt;BR /&gt;/*** Invert 2nd-stage information. ***/&lt;BR /&gt;vs = inv(t(Z)*w*Z);&lt;BR /&gt;/*** 2nd-stage coefficient estimates. ***/&lt;BR /&gt;b2 = vs*(t(wz)*b);&lt;BR /&gt;if t2pass=0 then do;&lt;BR /&gt;/*** Residual from 2nd-stage estimates. ***/&lt;BR /&gt;e = b - (Z*b2);&lt;BR /&gt;/*** Total residual sums of squares. ***/&lt;BR /&gt;rsst = t(e)*w*e;&lt;BR /&gt;/*** Residual mean square. ***/&lt;BR /&gt;rms = np*rsst/(df2*ws);&lt;BR /&gt;/*** Update t2 for empirical Bayes. ***/&lt;BR /&gt;t2 = max(rms-sum(wv)/ws,0);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/*** Calculate posterior expectations of 1st-stage parameters: ***/&lt;BR /&gt;/*** Weight for prior expectations of the 1st-stage parameters (curvature correction for EB.) ***/&lt;BR /&gt;if t2pass=0 then wvc = ((df2-2)/df2)*wv; else wvc = wv;&lt;BR /&gt;/*** Projection of b to prior mean. ***/&lt;BR /&gt;hatw = Z*vs*t(wz);&lt;BR /&gt;st2 = sqrt(t2*t(t2));&lt;BR /&gt;/*** Projection of b to posterior mean. ***/&lt;BR /&gt;hatp = wvc*hatw + w#st2 + (wv-wvc);&lt;BR /&gt;/*** Estimated posterior mean. ***/&lt;BR /&gt;b_hm = hatp*b;&lt;BR /&gt;/*** Estimated posterior covariance. ***/&lt;BR /&gt;bcov_hm = v - wvc*(Inp-hatw)*v;&lt;BR /&gt;/*** Approx df in hierarchical model. ***/&lt;BR /&gt;npa = trace(hatp);&lt;/P&gt;&lt;P&gt;if t2pass=0 then do;&lt;BR /&gt;/*** Add variance component due to estimation of the prior variance: ***/&lt;BR /&gt;wvce = wvc*(e#(sqrt((sum(wv)/ws + t2)/(vecdiag(v)+t2))));&lt;BR /&gt;bcov_hm = bcov_hm + (2/(df2-2))*wvce*t(wvce);&lt;/P&gt;&lt;P&gt;/*** Check for fitting problems: ***/&lt;BR /&gt;if iter &amp;gt;= _maxiter then print " Empirical-Bayes did not converge.";&lt;BR /&gt;else do; if t2=0 then print " Empirical-Bayes converged after" iter[format=4.0] " iterations,"&lt;BR /&gt;" but potential underdispersion: t2 set to zero.";&lt;BR /&gt;else print " Empirical-Bayes converged after" iter[format=4.0] " iterations,"&lt;BR /&gt;" with prior variance (t2) estimate:" t2[format=8.4];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do i=1 to np;&lt;BR /&gt;if bcov_hm[i,i]&amp;lt;0 then do;&lt;BR /&gt;print "Negative second-stage variance: set to zero.";&lt;BR /&gt;bcov_hm[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;finish;&lt;BR /&gt;/****************************************************************/&lt;/P&gt;&lt;P&gt;/****************************************************************&lt;BR /&gt;*** Main procedure for the estimation. Check model setting for each run ***&lt;BR /&gt;****************************************************************/&lt;/P&gt;&lt;P&gt;/*************************&lt;BR /&gt;**** Ordinary Logistic Regression Model ***&lt;BR /&gt;*************************/&lt;BR /&gt;bnames = {INTERCEPT &amp;amp;COVARIATES}`;&lt;BR /&gt;/* Make use of logistic_output */&lt;BR /&gt;use logistic_output;&lt;BR /&gt;read all into lr_est;&lt;BR /&gt;b_lr = lr_est[1,1:(ncol(lr_est)-1)]`;&lt;BR /&gt;bcov_lr = lr_est[2:nrow(lr_est),1:(ncol(lr_est)-1)];&lt;/P&gt;&lt;P&gt;/*********************************&lt;BR /&gt;*** Output logistic result ***&lt;BR /&gt;*********************************/&lt;BR /&gt;SE_lr = sqrt(vecdiag(bcov_lr));&lt;BR /&gt;ward = (b_lr # b_lr) / (se_lr # se_lr);&lt;BR /&gt;P_value = 1 - probchi(ward,1);&lt;BR /&gt;&lt;BR /&gt;print "Ordinary logistic regression estimates:";&lt;BR /&gt;print bnames b_lr[format=10.4] se_lr[format=10.4] p_value[format=8.4];&lt;/P&gt;&lt;P&gt;/*******************&lt;BR /&gt;*** HLM Model ***&lt;BR /&gt;*******************/&lt;BR /&gt;/*** Initialize 1st-stage parameters to be modelled in the hierarchical model ***/&lt;BR /&gt;b_lr0 = b_lr[&amp;amp;b2index];&lt;BR /&gt;v_lr0 = bcov_lr[&amp;amp;b2index,&amp;amp;b2index];&lt;BR /&gt;bnames_hm = bnames[&amp;amp;b2index];&lt;/P&gt;&lt;P&gt;/*** Specify 2nd-stage data and parameters to be modelled in the hierarchical model ***/&lt;BR /&gt;use &amp;amp;DATA2 var {&amp;amp;COVARIATES2};&lt;BR /&gt;read all into Z_mat;&lt;BR /&gt;bnames2 = {&amp;amp;COVARIATES2}`;&lt;BR /&gt;print bnames2 Z_mat;&lt;/P&gt;&lt;P&gt;Z_mat = repeat(1,nrow(b_lr0),1);&lt;BR /&gt;bnames2 = {INTERCEPT};&lt;/P&gt;&lt;P&gt;t2 = 0.5;&lt;BR /&gt;run hm_reg(b_lr0, v_lr0, Z_mat, t2, 0, 0, b_hm, bcov_hm, b_hm2);&lt;/P&gt;&lt;P&gt;/****************************&lt;BR /&gt;*** Output HLM result ***&lt;BR /&gt;****************************/&lt;BR /&gt;SE_hm = sqrt(vecdiag(bcov_hm));&lt;BR /&gt;ward = (b_hm # b_hm) / (SE_hm # SE_hm);&lt;BR /&gt;P_value = 1 - probchi(ward,1);&lt;BR /&gt;print "Hierarchical logistic regression estimates:";&lt;BR /&gt;print bnames_hm b_hm[format=10.4] SE_hm[format=10.4] P_value[format=8.4];&lt;/P&gt;&lt;P&gt;/*** OR estimates from both ordinary logistic model and hierarchical model ***/&lt;BR /&gt;OR_lr = exp(b_lr[&amp;amp;b2index]);&lt;BR /&gt;OR_lr95LCI = exp(b_lr[&amp;amp;b2index] - 1.96*SE_lr[&amp;amp;b2index]);&lt;BR /&gt;&lt;STRONG&gt;OR_lr95UCI = exp(b_lr[&amp;amp;b2index] + 1.96*SE_lr[&amp;amp;b2index]);&lt;/STRONG&gt;&lt;BR /&gt;OR_hm = exp(b_hm);&lt;BR /&gt;OR_hm95LCI = exp(b_hm - 1.96*SE_hm);&lt;BR /&gt;OR_hm95UCI = exp(b_hm + 1.96*SE_hm);&lt;/P&gt;&lt;P&gt;/*** Print results: ***/&lt;BR /&gt;print "Second stage parameter estimates using hierarchical model.", bnames2 b_hm2[format=10.4];&lt;/P&gt;&lt;P&gt;print " Odds Ratios and 95% CIs",&lt;BR /&gt;" Conventional Model Hierarchical Model",&lt;BR /&gt;bnames_hm OR_lr[format=8.2] OR_lr95LCI[format=8.2] &lt;STRONG&gt;OR_lr95UCI[format=8.2]&lt;/STRONG&gt;&lt;BR /&gt;OR_hm[format=8.2] OR_hm95LCI[format=8.2] OR_hm95UCI[format=8.2];&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%MEND;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2023 00:30:49 GMT</pubDate>
    <dc:creator>olliegeorge</dc:creator>
    <dc:date>2023-12-04T00:30:49Z</dc:date>
    <item>
      <title>Issue calculating confidence interval in hierarchical linear model macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/905923#M6150</link>
      <description>&lt;P&gt;I have a macro for performing HLM and logistic regression and then outputting a results table with the odds ratios and 95% confidence intervals from both models. When I apply the macro and try to run it, it is not able to generate the upper 95% CI for the logistic regression (OR_lr95UCI). If I remove this line from the code, it generates a table with all other results but when I include this variable, the code does not run. I am calculating it the same way as the lower limit&amp;nbsp; (OR_lr95LCI), so I don't know what is causing the issue. I have copied the macro below, with the problem variable bolded.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO HLM2(data=, outcome=, covariates=, data2=, covariates2=, b2index=);&lt;BR /&gt;&lt;BR /&gt;/* Run PROC LOGISTIC, result is in the data set logistic_output */&lt;BR /&gt;&lt;BR /&gt;proc logistic data=&amp;amp;DATA desc COVOUT OUTEST=logistic_output;&lt;BR /&gt;model &amp;amp;OUTCOME = &amp;amp;COVARIATES ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;/****************************************************************&lt;BR /&gt;*** Hirearchical model using empirical-Bayes or semi-Bayes estimation. ***&lt;BR /&gt;****************************************************************/&lt;BR /&gt;start hm_reg(b,v,z,t2,max_iter,c_criter,b_hm,bcov_hm,b2);&lt;BR /&gt;/****************************************************************&lt;BR /&gt;** Input: b : 1st-stage parameter estimates&lt;BR /&gt;** v : 1st-stage covariance matrix estimates for b&lt;BR /&gt;** z : 2nd-stage design matrix (prior design matrix)&lt;BR /&gt;** t2 : prior variance for semi-Bayes estimation (vector),&lt;BR /&gt;** (0 if prior variance is to be estimated using&lt;BR /&gt;** emirical-Bayes estimation.)&lt;BR /&gt;** max_iter: maximum number of iteration (default is 20)&lt;BR /&gt;** c_criter: convergence criteria (default is 1e-3)&lt;BR /&gt;** Output: b_hm : posterier estimates&lt;BR /&gt;** bcov_hm : covariance matrix for b&lt;BR /&gt;** b2 : 2nd-stage parameter estimates&lt;BR /&gt;****************************************************************/&lt;/P&gt;&lt;P&gt;/*** Number of first-stage parameters.***/&lt;BR /&gt;np = nrow(Z);&lt;BR /&gt;ncolz = ncol(Z);&lt;BR /&gt;/*** Second-stage degrees of freedom. */&lt;BR /&gt;df2 = np-ncolz; Inp = I(np);&lt;BR /&gt;/*** Empirical-Bayes estimation, else semi-Bayes estimation. ***/&lt;BR /&gt;if (min(t2) &amp;lt;= 0) then t2pass = 0; else t2pass = 1;&lt;BR /&gt;/*** Maximum number of iterations, and convergence criterion for t2. ***/&lt;BR /&gt;if max_iter = 0 then _maxiter = 20; else _maxiter = max_iter;&lt;BR /&gt;if c_criter = 0 then _criter = 1e-3; else _criter = c_criter;&lt;/P&gt;&lt;P&gt;if t2pass = 0 then do;&lt;BR /&gt;print np[format=4.0] " first stage parameters were regressed on"&lt;BR /&gt;ncolz[format=4.0] " second stage covariate(s)",&lt;BR /&gt;" using empirical-Bayes estimation method (prior variance (t2) to be estimated).";&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;print np[format=4.0] " first stage parameters were regressed on"&lt;BR /&gt;ncolz[format=4.0] " second stage covariate(s)",&lt;BR /&gt;" using semi-Bayes estimation with prior variance (t2) fixed at" t2[format=8.4];&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/*** Undertake second-stage regression: ***/&lt;BR /&gt;t2old = t2+1;&lt;BR /&gt;do iter = 1 to _maxiter while(abs(t2-t2old) &amp;gt; _criter);&lt;BR /&gt;t2old = t2;&lt;BR /&gt;/*** Weight matrix. ***/&lt;BR /&gt;w = inv(v+t2#Inp); wv = w*v; wz = w*z; ws = sum(w);&lt;BR /&gt;/*** Invert 2nd-stage information. ***/&lt;BR /&gt;vs = inv(t(Z)*w*Z);&lt;BR /&gt;/*** 2nd-stage coefficient estimates. ***/&lt;BR /&gt;b2 = vs*(t(wz)*b);&lt;BR /&gt;if t2pass=0 then do;&lt;BR /&gt;/*** Residual from 2nd-stage estimates. ***/&lt;BR /&gt;e = b - (Z*b2);&lt;BR /&gt;/*** Total residual sums of squares. ***/&lt;BR /&gt;rsst = t(e)*w*e;&lt;BR /&gt;/*** Residual mean square. ***/&lt;BR /&gt;rms = np*rsst/(df2*ws);&lt;BR /&gt;/*** Update t2 for empirical Bayes. ***/&lt;BR /&gt;t2 = max(rms-sum(wv)/ws,0);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;/*** Calculate posterior expectations of 1st-stage parameters: ***/&lt;BR /&gt;/*** Weight for prior expectations of the 1st-stage parameters (curvature correction for EB.) ***/&lt;BR /&gt;if t2pass=0 then wvc = ((df2-2)/df2)*wv; else wvc = wv;&lt;BR /&gt;/*** Projection of b to prior mean. ***/&lt;BR /&gt;hatw = Z*vs*t(wz);&lt;BR /&gt;st2 = sqrt(t2*t(t2));&lt;BR /&gt;/*** Projection of b to posterior mean. ***/&lt;BR /&gt;hatp = wvc*hatw + w#st2 + (wv-wvc);&lt;BR /&gt;/*** Estimated posterior mean. ***/&lt;BR /&gt;b_hm = hatp*b;&lt;BR /&gt;/*** Estimated posterior covariance. ***/&lt;BR /&gt;bcov_hm = v - wvc*(Inp-hatw)*v;&lt;BR /&gt;/*** Approx df in hierarchical model. ***/&lt;BR /&gt;npa = trace(hatp);&lt;/P&gt;&lt;P&gt;if t2pass=0 then do;&lt;BR /&gt;/*** Add variance component due to estimation of the prior variance: ***/&lt;BR /&gt;wvce = wvc*(e#(sqrt((sum(wv)/ws + t2)/(vecdiag(v)+t2))));&lt;BR /&gt;bcov_hm = bcov_hm + (2/(df2-2))*wvce*t(wvce);&lt;/P&gt;&lt;P&gt;/*** Check for fitting problems: ***/&lt;BR /&gt;if iter &amp;gt;= _maxiter then print " Empirical-Bayes did not converge.";&lt;BR /&gt;else do; if t2=0 then print " Empirical-Bayes converged after" iter[format=4.0] " iterations,"&lt;BR /&gt;" but potential underdispersion: t2 set to zero.";&lt;BR /&gt;else print " Empirical-Bayes converged after" iter[format=4.0] " iterations,"&lt;BR /&gt;" with prior variance (t2) estimate:" t2[format=8.4];&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;do i=1 to np;&lt;BR /&gt;if bcov_hm[i,i]&amp;lt;0 then do;&lt;BR /&gt;print "Negative second-stage variance: set to zero.";&lt;BR /&gt;bcov_hm[i] = 0;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;finish;&lt;BR /&gt;/****************************************************************/&lt;/P&gt;&lt;P&gt;/****************************************************************&lt;BR /&gt;*** Main procedure for the estimation. Check model setting for each run ***&lt;BR /&gt;****************************************************************/&lt;/P&gt;&lt;P&gt;/*************************&lt;BR /&gt;**** Ordinary Logistic Regression Model ***&lt;BR /&gt;*************************/&lt;BR /&gt;bnames = {INTERCEPT &amp;amp;COVARIATES}`;&lt;BR /&gt;/* Make use of logistic_output */&lt;BR /&gt;use logistic_output;&lt;BR /&gt;read all into lr_est;&lt;BR /&gt;b_lr = lr_est[1,1:(ncol(lr_est)-1)]`;&lt;BR /&gt;bcov_lr = lr_est[2:nrow(lr_est),1:(ncol(lr_est)-1)];&lt;/P&gt;&lt;P&gt;/*********************************&lt;BR /&gt;*** Output logistic result ***&lt;BR /&gt;*********************************/&lt;BR /&gt;SE_lr = sqrt(vecdiag(bcov_lr));&lt;BR /&gt;ward = (b_lr # b_lr) / (se_lr # se_lr);&lt;BR /&gt;P_value = 1 - probchi(ward,1);&lt;BR /&gt;&lt;BR /&gt;print "Ordinary logistic regression estimates:";&lt;BR /&gt;print bnames b_lr[format=10.4] se_lr[format=10.4] p_value[format=8.4];&lt;/P&gt;&lt;P&gt;/*******************&lt;BR /&gt;*** HLM Model ***&lt;BR /&gt;*******************/&lt;BR /&gt;/*** Initialize 1st-stage parameters to be modelled in the hierarchical model ***/&lt;BR /&gt;b_lr0 = b_lr[&amp;amp;b2index];&lt;BR /&gt;v_lr0 = bcov_lr[&amp;amp;b2index,&amp;amp;b2index];&lt;BR /&gt;bnames_hm = bnames[&amp;amp;b2index];&lt;/P&gt;&lt;P&gt;/*** Specify 2nd-stage data and parameters to be modelled in the hierarchical model ***/&lt;BR /&gt;use &amp;amp;DATA2 var {&amp;amp;COVARIATES2};&lt;BR /&gt;read all into Z_mat;&lt;BR /&gt;bnames2 = {&amp;amp;COVARIATES2}`;&lt;BR /&gt;print bnames2 Z_mat;&lt;/P&gt;&lt;P&gt;Z_mat = repeat(1,nrow(b_lr0),1);&lt;BR /&gt;bnames2 = {INTERCEPT};&lt;/P&gt;&lt;P&gt;t2 = 0.5;&lt;BR /&gt;run hm_reg(b_lr0, v_lr0, Z_mat, t2, 0, 0, b_hm, bcov_hm, b_hm2);&lt;/P&gt;&lt;P&gt;/****************************&lt;BR /&gt;*** Output HLM result ***&lt;BR /&gt;****************************/&lt;BR /&gt;SE_hm = sqrt(vecdiag(bcov_hm));&lt;BR /&gt;ward = (b_hm # b_hm) / (SE_hm # SE_hm);&lt;BR /&gt;P_value = 1 - probchi(ward,1);&lt;BR /&gt;print "Hierarchical logistic regression estimates:";&lt;BR /&gt;print bnames_hm b_hm[format=10.4] SE_hm[format=10.4] P_value[format=8.4];&lt;/P&gt;&lt;P&gt;/*** OR estimates from both ordinary logistic model and hierarchical model ***/&lt;BR /&gt;OR_lr = exp(b_lr[&amp;amp;b2index]);&lt;BR /&gt;OR_lr95LCI = exp(b_lr[&amp;amp;b2index] - 1.96*SE_lr[&amp;amp;b2index]);&lt;BR /&gt;&lt;STRONG&gt;OR_lr95UCI = exp(b_lr[&amp;amp;b2index] + 1.96*SE_lr[&amp;amp;b2index]);&lt;/STRONG&gt;&lt;BR /&gt;OR_hm = exp(b_hm);&lt;BR /&gt;OR_hm95LCI = exp(b_hm - 1.96*SE_hm);&lt;BR /&gt;OR_hm95UCI = exp(b_hm + 1.96*SE_hm);&lt;/P&gt;&lt;P&gt;/*** Print results: ***/&lt;BR /&gt;print "Second stage parameter estimates using hierarchical model.", bnames2 b_hm2[format=10.4];&lt;/P&gt;&lt;P&gt;print " Odds Ratios and 95% CIs",&lt;BR /&gt;" Conventional Model Hierarchical Model",&lt;BR /&gt;bnames_hm OR_lr[format=8.2] OR_lr95LCI[format=8.2] &lt;STRONG&gt;OR_lr95UCI[format=8.2]&lt;/STRONG&gt;&lt;BR /&gt;OR_hm[format=8.2] OR_hm95LCI[format=8.2] OR_hm95UCI[format=8.2];&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%MEND;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 00:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/905923#M6150</guid>
      <dc:creator>olliegeorge</dc:creator>
      <dc:date>2023-12-04T00:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Issue calculating confidence interval in hierarchical linear model macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906040#M6151</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have moved this topic thread to another board that is more appropriate for this query of yours.&lt;BR /&gt;Home &amp;gt; Analytics &amp;gt; SAS/IML&lt;BR /&gt;"SAS/IML software and matrix computations"-board&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say :&lt;BR /&gt;"...&amp;nbsp;&lt;EM&gt;but when I include this variable, the code does not run.&lt;/EM&gt;"&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Does it generate a WARNING or an ERROR in the LOG??&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, when copying and pasting SAS-code, click the little "running man" squared icon in the header, ... you then get a pop-up window in which you can paste your code. That way, formatting and structure are preserved and font is mono-spaced.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906040#M6151</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-12-04T15:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Issue calculating confidence interval in hierarchical linear model macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906058#M6152</link>
      <description>&lt;P&gt;Are you claiming that the statement&lt;BR /&gt;&lt;SPAN&gt;OR_lr95LCI = exp(b_lr[&amp;amp;b2index] - 1.96*SE_lr[&amp;amp;b2index]);&lt;BR /&gt;&lt;/SPAN&gt;runs without error but the statement&lt;BR /&gt;OR_lr95UCI = exp(b_lr[&amp;amp;b2index] + 1.96*SE_lr[&amp;amp;b2index]);&amp;nbsp; &amp;nbsp; /* same statement but with a PLUS sign */&lt;/P&gt;
&lt;P&gt;gives an error?&amp;nbsp; If so, perhaps the standard error is so large the EXP function is overflowing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be extremely helpful if you &lt;STRONG&gt;copy/paste the EXACT statements in the SAS log&lt;/STRONG&gt; that show the error, along with 5 statements before and after the error to provide context.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this and report back:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;lowerArg = b_lr[&amp;amp;b2index] - 1.96*SE_lr[&amp;amp;b2index];
upperArg = b_lr[&amp;amp;b2index] + 1.96*SE_lr[&amp;amp;b2index];
logbig = constant('logbig');   /* largest value that can be exponentiated */
print lowerArg upperArg logbig;

OR_lr95LCI = exp(lowerArg);
OR_lr95UCI = exp(upperArg);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 16:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906058#M6152</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-12-04T16:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue calculating confidence interval in hierarchical linear model macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906128#M6153</link>
      <description>&lt;P&gt;Hello, thanks for your response and advice! Yes,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;OR_lr95LCI = exp(b_lr[&amp;amp;b2index] - 1.96*SE_lr[&amp;amp;b2index])&amp;nbsp;&lt;/SPAN&gt;runs without error but the statement but OR_lr95UCI = exp(b_lr[&amp;amp;b2index] + 1.96*SE_lr[&amp;amp;b2index]) gives an error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran your suggested code and have pasted the log contents below, showing the error statements. I have also attached a PDF of the results output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I include&amp;nbsp;OR_lr95UCI in the macro, there are no results for Odds Ratios and 95% CIs but if I remove OR_lr95UCI, the results include a table listing all&amp;nbsp; bnames_hm, OR_lr, OR_lr95LCI, OR_hm, OR_hm95LCI, OR_hm95UCI[format=8.2] further validating that the issue is with&amp;nbsp;OR_lr95UCI .&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV align="left"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;4089 ods html body=test;&lt;BR /&gt;NOTE: Writing HTML Body file: TEST&lt;BR /&gt;4090 %HLM2(DATA = pyear.Pregev_Dataall, OUTCOME = neuro,&lt;BR /&gt;4091 COVARIATES = %NUMLIST(ResExp2-ResExp52)&lt;BR /&gt;4092 birthyear quin2 quin3 quin4 quin5 mraco mracw mage /* mage20_24mage25_29 mage30_34 mage35 female*/,&lt;BR /&gt;4093 DATA2 = pyear.HLM2rXLS,&lt;BR /&gt;4094 COVARIATES2 = _2_6_Dinitroaniline Amide Anilide Anthranilic_diamide Azole Chloroacetanilide Dicarboximide&lt;BR /&gt;4095 Halogenated_organic N_Methyl_Carbamate Organochlorine Organophosphorus Pyrazole Pyridine&lt;BR /&gt;4096 Pyrethroid Substituted_Benzene Triazine Unclassified Urea,&lt;BR /&gt;4097 B2INDEX = (2:52) );&lt;/P&gt;&lt;P&gt;NOTE: PROC LOGISTIC is modeling the probability that NEURO='1'.&lt;BR /&gt;NOTE: There were 37887 observations read from the data set PYEAR.PREGEV_DATAALL.&lt;BR /&gt;NOTE: The data set WORK.LOGISTIC_OUTPUT has 61 observations and 66 variables.&lt;BR /&gt;NOTE: Compressing data set WORK.LOGISTIC_OUTPUT increased size by 100.00 percent.&lt;BR /&gt;Compressed is 2 pages; un-compressed would require 1 pages.&lt;BR /&gt;NOTE: PROCEDURE LOGISTIC used (Total process time):&lt;BR /&gt;real time 2.08 seconds&lt;BR /&gt;cpu time 0.39 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NOTE: IML Ready&lt;BR /&gt;NOTE: Module HM_REG defined.&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: (execution) Invalid argument to function.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;count : number of occurrences is 9&lt;BR /&gt;operation : EXP at line 5817 column 18&lt;BR /&gt;operands : upperArg&lt;BR /&gt;upperArg 51 rows 1 col (numeric)&lt;/P&gt;&lt;P&gt;statement : ASSIGN at line 5817 column 2&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: Matrix OR_lr95UCI has not been set to a value.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;statement : PRINT at line 5819 column 25&lt;BR /&gt;NOTE: Exiting IML.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE IML used (Total process time):&lt;BR /&gt;real time 0.14 seconds&lt;BR /&gt;cpu time 0.04 seconds&lt;/P&gt;&lt;P&gt;4098 RUN;&lt;BR /&gt;4099 ods html close;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 21:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906128#M6153</guid>
      <dc:creator>olliegeorge</dc:creator>
      <dc:date>2023-12-04T21:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Issue calculating confidence interval in hierarchical linear model macro</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906135#M6154</link>
      <description>&lt;P&gt;Yes, as I suspected, you are getting numerical overflows in EXP for several elements of the upper CL.&lt;/P&gt;
&lt;P&gt;The CL for those indices are essentially (0, Infinity).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a few ways to handle this situation. One is to report the statistics on the log-scale and not back-transform the statistics and CLs.&lt;/P&gt;
&lt;P&gt;Another is to &lt;A href="https://blogs.sas.com/content/iml/2015/11/04/trap-cap-division-by-zero.html" target="_self"&gt;trap the arguments that will result in domain errors&lt;/A&gt;&amp;nbsp;and manually insert missing values for the upper CLs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully, it is clear how to proceed. If not, study the following small example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
b_lr    = {0.5,  1,   0,  0.2, 0.8};
SE_lr   = {0.6, 80, 800,  2.1, 3};
lowerArg = b_lr - 1.96*SE_lr;
upperArg = b_lr + 1.96*SE_lr;

OR_lr95LCI = exp(lowerArg);
OR_lr95UCI = j(nrow(upperArg), 1, .);  /* use missing value for infinity */
idx = loc(upperArg &amp;lt; constant('logbig'));
if ncol(idx)&amp;gt;0 then 
   OR_lr95UCI[idx,] = exp(upperArg[idx,]);

print lowerArg upperArg OR_lr95LCI OR_lr95UCI;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2023 21:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Issue-calculating-confidence-interval-in-hierarchical-linear/m-p/906135#M6154</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-12-04T21:56:19Z</dc:date>
    </item>
  </channel>
</rss>

