Programming the statistical procedures from SAS

Size effects

Accepted Solution Solved
Reply
Contributor
Posts: 58
Accepted Solution

Size effects

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)?


Accepted Solutions
Solution
‎03-14-2016 03:27 AM
Respected Advisor
Posts: 4,742

Re: Size effects

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


All Replies
Super User
Posts: 18,488

Re: Size effects

You can include fish size in the model. 

Contributor
Posts: 58

Re: Size effects

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.
Super User
Posts: 18,488

Re: Size effects

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;
Contributor
Posts: 58

Re: Size effects

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

Super User
Posts: 18,488

Re: Size effects

Try the suggested code above then.  

Contributor
Posts: 58

Re: Size effects

[ Edited ]

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). 

Super User
Posts: 18,488

Re: Size effects

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/

Contributor
Posts: 58

Re: Size effects

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. 

Respected Advisor
Posts: 4,742

Re: Size effects

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

PG
Contributor
Posts: 58

Re: Size effects

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. 

Contributor
Posts: 58

Re: Size effects

[ Edited ]

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. 

Respected Advisor
Posts: 4,742

Re: Size effects

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
Contributor
Posts: 58

Re: Size effects

[ Edited ]

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. 

Solution
‎03-14-2016 03:27 AM
Respected Advisor
Posts: 4,742

Re: Size effects

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
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 16 replies
  • 752 views
  • 5 likes
  • 3 in conversation