BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RC2
Calcite | Level 5 RC2
Calcite | Level 5

Below is code to get CV for log-transformed data (i.e. the geometric CV). But how do I calculate the 95% CI?

 

data DSN;

  set DSN_IN;

  if X ne . then lnX=log(X);

run;

 

proc means data=DSN noprint;

  var lnX;

  output out=stats n=n mean=mean stddev=sd;

run;

 

data stats;

  set stats;

  geosd=exp(sd);

  ln2GSD=(log(geosd))**2;

  geoCV=100*(sqrt(exp(ln2GSD)-1));

run;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @RC2,

 

My first idea was to transform a CI for the standard deviation of lnX:

/* Create test data for demonstration */

data have;
call streaminit(27182818);
do j=1 to 1000;
  x=rand('lognormal',5,2);
  output;
end;
run;

/* Compute geometric CV and 95% CI "manually" */

data trans;
set have;
if x>0 then lnx=log(x);
run;

proc summary data=trans;
var lnx;
output out=stat std=sd;
run;

data stat;
set stat;
geoCV=100*(sqrt(exp(sd**2)-1));
run;

ods output BasicIntervals=ci(where=(parameter=:'Std'));
proc univariate data=trans cibasic;
var lnx;
run;

data want0(keep=geoCV lcl ucl);
set ci;
set stat;
lcl=100*sqrt(exp(lowercl**2)-1);
ucl=100*sqrt(exp(uppercl**2)-1);
run;

proc print data=want0;
run;

But then I noticed that PROC TTEST (scroll down to the bottom of that page) can compute both the geometric CV and the same CI as above directly from the untransformed data (except for the factor of 100[%], which I introduce below by means of the PERCENTw.d format).

/* Let PROC TTEST compute geometric CV and 95% CI */

ods graphics off;
ods select none;
ods output conflimits=want;
proc ttest data=have dist=lognormal;
var x;
run;
ods graphics on;
ods select all;

proc print data=want;
format _numeric_ percent10.3;
var cv lowerclcv upperclcv umpu:;
run;

In addition, you get an alternative (UMPU) CI.

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

That's an interesting question, and I don't know a formula for the answer. The simplest answer is to run a bootstrap analysis of the geometric CV statistic. 

 

It appears that your formulas come from Sawant and Mohan (2011)

https://www.lexjansen.com/pharmasug/2011/PO/PharmaSUG-2011-PO08.pdf

 

However, I encourage you to read the articles by

Roenfeldt (2018) https://www.lexjansen.com/wuss/2018/56_Final_Paper_PDF.pdf

and the blog post by Lee Humphries (2010)
https://www.thinkingapplied.com/cov_folder/geo_cov.htm

which discuss how to compute the geometric CV. 

 

The computations by Roesfeldt and Humphries make sense to me, but it is possible that Sawant and Mohan's computation is on a different scale. It is always confusing (to me) to figure out which results are on the LOG scale and which are in the original scale. 

RC2
Calcite | Level 5 RC2
Calcite | Level 5

Dear RICK_SAS,

Many thanks for the article links. Indeed, they were interesting reads. Bootstrapping is a good option but I see a post suggesting TTEST, which I didn't know about.

 

Regards,

Rick

FreelanceReinh
Jade | Level 19

Hi @RC2,

 

My first idea was to transform a CI for the standard deviation of lnX:

/* Create test data for demonstration */

data have;
call streaminit(27182818);
do j=1 to 1000;
  x=rand('lognormal',5,2);
  output;
end;
run;

/* Compute geometric CV and 95% CI "manually" */

data trans;
set have;
if x>0 then lnx=log(x);
run;

proc summary data=trans;
var lnx;
output out=stat std=sd;
run;

data stat;
set stat;
geoCV=100*(sqrt(exp(sd**2)-1));
run;

ods output BasicIntervals=ci(where=(parameter=:'Std'));
proc univariate data=trans cibasic;
var lnx;
run;

data want0(keep=geoCV lcl ucl);
set ci;
set stat;
lcl=100*sqrt(exp(lowercl**2)-1);
ucl=100*sqrt(exp(uppercl**2)-1);
run;

proc print data=want0;
run;

But then I noticed that PROC TTEST (scroll down to the bottom of that page) can compute both the geometric CV and the same CI as above directly from the untransformed data (except for the factor of 100[%], which I introduce below by means of the PERCENTw.d format).

/* Let PROC TTEST compute geometric CV and 95% CI */

ods graphics off;
ods select none;
ods output conflimits=want;
proc ttest data=have dist=lognormal;
var x;
run;
ods graphics on;
ods select all;

proc print data=want;
format _numeric_ percent10.3;
var cv lowerclcv upperclcv umpu:;
run;

In addition, you get an alternative (UMPU) CI.

RC2
Calcite | Level 5 RC2
Calcite | Level 5

Dear FreelanceReinhard,

It never occurred to me that TTEST would do this. Thank you for the help.

 

Regards,

Rick

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 1458 views
  • 0 likes
  • 3 in conversation