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

Hello 

How to find the fish size effects on its digestion rate (slope value) using proc satatement?

 

I can find the slop and intercepet of each group using proc reg. But I have two groups and both produced different slope value. I know this change is becasue of fish size (one group has 30g size fish, another has 150g size fish), so is there any way to find the effect of fish size (exponent)?

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

You must fit an intercept for every group:

 

data fish;
set xl.'Sir Nadir$'n;
rename x=t y=S_t;
label y="S(t)" x="t";
run;

proc nlin data=fish;
parms slope_0 = 1.0 exponent = 1.0
    intercept_1 = 1.5 
    intercept_2 = 1.5 
    intercept_3 = 1.5 
    intercept_4 = 1.5 
    intercept_5 = 1.5 
    intercept_6 = 1.5 ;
slope = slope_0*fish_size**exponent;
group_1 = (group = 1);
group_2 = (group = 2);
group_3 = (group = 3);
group_4 = (group = 4);
group_5 = (group = 5);
group_6 = (group = 6);
model S_t = 
    intercept_1*group_1 + 
    intercept_2*group_2 + 
    intercept_3*group_3 + 
    intercept_4*group_4 + 
    intercept_5*group_5 + 
    intercept_6*group_6 -
    slope*t;
output out=fishPred predicted=p_S_t residual=r_S_t;
run;

proc sort data=fishPred; by group t fish_size; run;

title;
proc sgplot data=fishPred;
scatter y=S_t x=t / group=group;
series y=p_S_t x=t / group=group lineattrs=(pattern=Solid) 
    curvelabel curvelabelpos=end;
run;
                                          Approx       Approximate 95% Confidence
            Parameter      Estimate    Std Error                 Limits

            slope_0         0.00114     0.000405    0.000348     0.00194
            exponent         0.4911       0.0725      0.3485      0.6337
            intercept_1      1.2018       0.0284      1.1459      1.2578
            intercept_2      0.9589       0.0276      0.9046      1.0131
            intercept_3      0.7986       0.0258      0.7478      0.8494
            intercept_4      1.8081       0.0283      1.7524      1.8638
            intercept_5      1.4271       0.0290      1.3700      1.4842
            intercept_6      1.1312       0.0268      1.0785      1.1838

 

Six fish groups

PG

View solution in original post

16 REPLIES 16
Reeza
Super User

You can include fish size in the model. 

afgdurrani0
Pyrite | Level 9
It is the proc statement;
Proc reg data=abcd;
Model y=x;
Run;

So where to insert the fish size here? The relationship between slope and fish size is mostly described by simple power function.
Reeza
Super User
I'm not sure what you mean. Can you write out the equation your trying to model?

I was suggesting you add size into model, but it sounds like you want a more complex model.

Model Y = x size;
afgdurrani0
Pyrite | Level 9

Dear Reeza,

Generally we run first proc reg (model y=x) etc to find the slop value. Suppose I have two sample of 35g and 150g. I find the digestion rate (slope) for each group. After finding slope values, I plot the slope values at y-axis and fish body weight (W) at x-axis and run the power trending (see the fig. below). But I want to modify my model y=x to also calculate the effect of body mass of fish on slope value. 

 

 

 

4.png

Reeza
Super User

Try the suggested code above then.  

afgdurrani0
Pyrite | Level 9

Dear Reeza, 

I try but not working. I attached the xlsx file, you can try it too. As I told you that I run the simple linear regression and then plot the generated slope values against the fish weight to find the mass exponent (effect of fish size on slope value). 

Reeza
Super User

I don't like to download attachments, if you'd like further assistance from me please post your code and log. Otherwise someone else will help out. 

 

Here's a macro that will transform your data step into a data set code that can be pasted into the window here.

 

http://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/

afgdurrani0
Pyrite | Level 9

Deare Reeza, 

Unfortunately I don't know the method you shared for data sharing. We have to wait for someone else then to help me in this case. 

PGStats
Opal | Level 21

In your data, is Y = S(t), X = t and fish_size = W ?

PG
afgdurrani0
Pyrite | Level 9

Yes, it is like that (Y = S(t), X = t and fish_size = W). I want to find the fish size effect on slope value (digestion rate). You can see in my above shared graph. 

afgdurrani0
Pyrite | Level 9

Dears, 

I use this equation to find the intercept and slope for my data;  St=a- slope*t and then I used this: slope=slope*W^b to find the effect of fish size on slope (b). 

 

I need sas proc for this. 

PGStats
Opal | Level 21

You are looking for nonlinear regression. I renamed your data file Fish size effects.xlsx and ran:

 

libname xl Excel "&sasforum\datasets\Fish size effect.xlsx" access=readonly;
data fish;
set xl.'Sheet1$'n;
rename x=t y=S_t;
label y="S(t)" x="t";
run;

proc nlin data=fish;
parms slope_0 = 1.0 intercept_1 = 1.75 intercept_2 = 0.75 exponent = 1.0 ;
slope = slope_0*fish_size**exponent;
group_1 = (group = 1);
group_2 = (group = 2);
model S_t = intercept_1*group_1 + intercept_2*group_2 - slope*t;
output out=fishPred predicted=p_S_t;
run;

proc sort data=fishPred; by group t; run;

title;
proc sgplot data=fishPred;
scatter y=S_t x=t / group=group;
series y=p_S_t x=t / group=group;
run;

I got this fit (the vertical transitions represent the effect of fish size for each value of t):

 

Non linear fit

 

 

 

 

 

 

 

 

 

 

  

 

PG
afgdurrani0
Pyrite | Level 9

Thanks PG Stats, 

 

I run like that: 

 

FILENAME CSV "/folders/myfolders/Sir nadir.csv" TERMSTR=CRLF;
PROC IMPORT DATAFILE=CSV
OUT=geumar2
DBMS=CSV
REPLACE;
RUN;
title 'geumar';
data group;
set geumar2;
run;

data group;
set geumar2;
rename x=t y=S_t;
label y="S(t)" x="t";
run;

proc nlin data=exp;
parms slope_0 = 1.0 intercept_1 = 1.75 intercept_2 = 0.75 exponent = 1.0 ;
slope = slope_0*fish_size**exponent;
group_1 = (group = 1);
group_2 = (group = 2);
model S_t = intercept_1*group_1 + intercept_2*group_2 - slope*t;
output out=fishPred predicted=p_S_t;
run;

 

it doesn't give any error but it doesn't converge. 

WARNING: Step size shows no improvement.
WARNING: PROC NLIN failed to converge.
 

I am sharing a file which has total 6 groups, I edited your constricted proc to include others group too but the mass exponent is -48. According to my data analysis done with hands, it should be near to 0.55. 

PGStats
Opal | Level 21

You must fit an intercept for every group:

 

data fish;
set xl.'Sir Nadir$'n;
rename x=t y=S_t;
label y="S(t)" x="t";
run;

proc nlin data=fish;
parms slope_0 = 1.0 exponent = 1.0
    intercept_1 = 1.5 
    intercept_2 = 1.5 
    intercept_3 = 1.5 
    intercept_4 = 1.5 
    intercept_5 = 1.5 
    intercept_6 = 1.5 ;
slope = slope_0*fish_size**exponent;
group_1 = (group = 1);
group_2 = (group = 2);
group_3 = (group = 3);
group_4 = (group = 4);
group_5 = (group = 5);
group_6 = (group = 6);
model S_t = 
    intercept_1*group_1 + 
    intercept_2*group_2 + 
    intercept_3*group_3 + 
    intercept_4*group_4 + 
    intercept_5*group_5 + 
    intercept_6*group_6 -
    slope*t;
output out=fishPred predicted=p_S_t residual=r_S_t;
run;

proc sort data=fishPred; by group t fish_size; run;

title;
proc sgplot data=fishPred;
scatter y=S_t x=t / group=group;
series y=p_S_t x=t / group=group lineattrs=(pattern=Solid) 
    curvelabel curvelabelpos=end;
run;
                                          Approx       Approximate 95% Confidence
            Parameter      Estimate    Std Error                 Limits

            slope_0         0.00114     0.000405    0.000348     0.00194
            exponent         0.4911       0.0725      0.3485      0.6337
            intercept_1      1.2018       0.0284      1.1459      1.2578
            intercept_2      0.9589       0.0276      0.9046      1.0131
            intercept_3      0.7986       0.0258      0.7478      0.8494
            intercept_4      1.8081       0.0283      1.7524      1.8638
            intercept_5      1.4271       0.0290      1.3700      1.4842
            intercept_6      1.1312       0.0268      1.0785      1.1838

 

Six fish groups

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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