BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Joa14
Obsidian | Level 7

Hello,

 

I am trying to fit some variables through regression (temperatures (X&Y) and plots with various vegetation types, groups), but I want my output to look like the graph attached from Beeles et al., 2021, particularly the fit relative to the line 1:1 line. The code I am using is:

proc transreg data=work.import ss2 plots=fit(nocli noclm);
ods output coef=coef;
model identity(Y)=class(Forest_Type / zero=none) | identity(X);
run;

 

Fit 1 1 line.jpg

 

Thank you so much!

1 ACCEPTED SOLUTION

Accepted Solutions
StatsMan
SAS Super FREQ

What about this code is not working for you?

 

data test;
input Forest_Type $	X Y;
datalines;
CO 16.8 16.8
CO 16 16.5
CO 16.5 16.9
CO 17 17.5
CO 18.2 18.2
CO 17.8 17.9
OP 17.9 18.1
OP 17.9 16.7
OP 13.9 14.9
OP 16.7 16.2
OP 17.8 17.8
OP 17 17.9
OP 17.2 16.8
OP 17.5 17.2
OP 17.9 16.7
PO 15.9 15.8
PO 14.4 13.4
PO 17.6 17.6
PO 15.2 15.8
PO 15.8 19.3
PO 16 16
PO 16.1 16
PP 16.4 15.6
PP 16.4 17.1
PP 16.9 16.6
PP 15.2 15.9
PP 16.6 16.4
SO 13.8 14.4
SO 14.9 14.6
SO 15.9 15.6
SO 15.8 19
;
run;

proc sgplot data=test;
   scatter x=x y=y / group=forest_type;
   reg x=x y=y / degree=1;
   reg x=x y=y / degree=2;
   lineparm x=0 y=0 slope=1 / clip;
run;

Here is the graph produced by this code:

StatsMan_0-1687274685435.png

 

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26
proc sgplot data=have;
    reg y=y x=x/degree=1;
    reg y=y x=x/degree=2;
    lineparm x=0 y=0 slope=1;
    scatter y=y x=x/markerattrs=(symbol=circle) group=forest_type;
run;
--
Paige Miller
Joa14
Obsidian | Level 7

Thank you PaigeMiller.

I tried your code but it is not working 😞

The resulting graph is this:

Fit 1 1 line_Suggested-codeb.jpg

This is the data I am working with. Thanks for your insights. 

Forest_Type X Y
CO 16.8 16.8
CO 16 16.5
CO 16.5 16.9
CO 17 17.5
CO 18.2 18.2
CO 17.8 17.9
OP 17.9 18.1
OP 17.9 16.7
OP 13.9 14.9
OP 16.7 16.2
OP 17.8 17.8
OP 17 17.9
OP 17.2 16.8
OP 17.5 17.2
OP 17.9 16.7
PO 15.9 15.8
PO 14.4 13.4
PO 17.6 17.6
PO 15.2 15.8
PO 15.8 19.3
PO 16 16
PO 16.1 16
PP 16.4 15.6
PP 16.4 17.1
PP 16.9 16.6
PP 15.2 15.9
PP 16.6 16.4
SO 13.8 14.4
SO 14.9 14.6
SO 15.9 15.6
SO 15.8 19
DanObermiller
SAS Employee

The lineparm x=0 y=0 slope=1; statement is the culprit. Since the picture of your data looked like it went to the origin, that is the way @PaigeMiller coded it. Your actual data has minimums around 13.4 and 13.8 so, change that lineparm line to 

lineparm x=13 y=13 slope=1;

or something similar to that. Just specify your minimum value for the x and y axes. Actually, the axes will default to the data as long as you enter values on the lineparm line that are within the data range.

DanO_0-1687224396600.png

 

PaigeMiller
Diamond | Level 26

@Joa14 wrote:

Thank you PaigeMiller.

I tried your code but it is not working 😞

The resulting graph is this:

Fit 1 1 line_Suggested-codeb.jpg

 


What about this is not working? You should explain instead of simply saying "not working" and providing no additional explanation. The plots looks to me to be correct.

--
Paige Miller
Rick_SAS
SAS Super FREQ

The modification is even easier than Dan's suggestion: Just add the CLIP option to the LINEPARM statement:

 lineparm x=0 y=0 slope=1 / clip;

 

StatsMan
SAS Super FREQ

What about this code is not working for you?

 

data test;
input Forest_Type $	X Y;
datalines;
CO 16.8 16.8
CO 16 16.5
CO 16.5 16.9
CO 17 17.5
CO 18.2 18.2
CO 17.8 17.9
OP 17.9 18.1
OP 17.9 16.7
OP 13.9 14.9
OP 16.7 16.2
OP 17.8 17.8
OP 17 17.9
OP 17.2 16.8
OP 17.5 17.2
OP 17.9 16.7
PO 15.9 15.8
PO 14.4 13.4
PO 17.6 17.6
PO 15.2 15.8
PO 15.8 19.3
PO 16 16
PO 16.1 16
PP 16.4 15.6
PP 16.4 17.1
PP 16.9 16.6
PP 15.2 15.9
PP 16.6 16.4
SO 13.8 14.4
SO 14.9 14.6
SO 15.9 15.6
SO 15.8 19
;
run;

proc sgplot data=test;
   scatter x=x y=y / group=forest_type;
   reg x=x y=y / degree=1;
   reg x=x y=y / degree=2;
   lineparm x=0 y=0 slope=1 / clip;
run;

Here is the graph produced by this code:

StatsMan_0-1687274685435.png

 

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
  • 6 replies
  • 658 views
  • 3 likes
  • 5 in conversation