turn on suggestions

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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- SGPLOT LOESS Semi-log wont work with 0

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-07-2013 06:18 PM

I have 0 in the dataset, I used

proc sgplot data=;

loess x=age y=pc/smooth=3 clm;

xaxis label='Age';

yaxis type=log logbase=10 logstyle=logexpand label='Outcome' values=(0.1 1 10 100);

I have tried the following:

1) set 0 to missing, got error msg, Log axis cannot support zero or negative values in the data range.

2) delete 0, got error msg, Log axis cannot support zero or negative values in the data range (I really dont understand this case)

3) set 0 to a very small number, 0.0001, the semi-log scale will work, but 0.0001 will shown, even you have specified the range to be 0.1-100

4) I also try min=0.1 max=100 on yaxis, got same error msg as 1) and 2) above

Please share your experience... Thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-07-2013 06:29 PM

One problem might be that the loess fit generates some fitted values or confidence limits <= 0. - PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-09-2013 08:54 AM

I like to analyze the data in one step and plot it in the next if I think data transforms are required of the results. So you might use PROC LOESS to analyze the data, then use a DATA step to transform the resultsm, and PROC SGPLOT to display the transformed results.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-09-2013 09:44 AM

PG and Rick: Thanks for your help.

I used Proc LOESS to get Pred and CLM variables, yes, I found LCLM to have negative value.

because I want my log scale to be from 0.1 to 100, so I assume I will need to set raw value < 0.1 to missing, and lclm < 0.1 to missing, correct ?

the next question is, then how can I plot the predicated, and CLM.

I used proc gplot (not sgplot)

value*age=1 pred*age=2 lclm*age=3 uclm*age=4/overlay skipmiss

because I had the smooth option, the result of 2), 3) and 4) were actually not line, but curves,

I am not too familiar with proc sgplot, need to read the docu. how to plot these curves

any suggestions will be greatly appreciated.

Thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-09-2013 10:24 AM

Here is the outline of what I would try:

**data graphX;****do x = myXmin to myXmax by smallAmount;**** output;**** end;****run;**

** **

**data loessLog;****set myData;****logY = log10(y);****run;**

** **

**proc loess data=loessLog;****model logY = x / clm smooth=0.2 degree=1;****score data=graphX / clm;****ods output scoreResults=loessScore;****run;**

** **

**data expGraphX;****set loessScore(in=ok) myData;****if ok then do;**** predY = 10**p_y;**** lcl = 10**lcl_y;**** ucl = 10**ucl_y;**** end;****run;**

** **

**proc sgplot data=expGraphX;****band x=x lower=lcl upper=ucl; ****series x=x y=predY;****scatter x=x y=y;****yaxis type=log logbase=10;****run;**

PG

PG

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-09-2013 11:18 AM

PG:

Thanks for your code.

I want to present the original data in log scale, so I am not sure I should run proc loess on log-transformed data.

this is what I have done.

1) ran proc loess on my un-transformed data, got pred, lclm and uclm.

2) set pred, lclm, uclm < 0.1 to missing.

3) proc sort data=stat_1; by age;

proc sgplot data=stat_1 noautolegend ;

band x=age lower=lclm upper=uclm ;

series x=age y=pred/break;

scatter x=age y=rawdata;

xaxis label="Age (years)" ;

yaxis label="Raw Data"

logbase=10 type=log min=0.1 max=100;

run;

more questions

1) I used values =(0.1 1 10 100) in yaxis statement, and it only shown 0.1 and 100, without 1, 10, and dont have any minor tick marks.

maybe I should try more options on yaxis.

2) for lclm and uclm that I set to missing, wont have any impact on the band, it will be omitted...

3) it produced the graph without any obvious problems, but I am not sure if the bands and smooth line are presented correctly.

need to do more research.

Thank you so much for your help.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-09-2013 11:50 AM

1) Sometimes it's better to use less options with log axes.

3) Sometimes you can get away with using PBSPLINE instead of SERIES to get the smooth line to *look* smoother. I prefer to get a dense and evenly spaced series of predicted values, and use those to draw the smooth lines, as shown in my earlier post.

PG

PG