Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Confidence Intervals for Coefficient of Variation of logged data

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-10-2019 06:43 AM
(1641 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 PERCENT*w*.*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.

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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 PERCENT*w*.*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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dear FreelanceReinhard,

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

Regards,

Rick

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.