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

Hi guys,

 

I am trying to use incomplete Gamma function model in SAS to fit a curve for dairy cows  lactaion ,but I do not know how to write this model in SAS using Proc Nlin .  Can anybody please help me about this ?

How can I specify the values of a,b and c in the model?

 

y(t)= a t^b e^-c*t      (Wood's model)

 

I look forward to hearing from you.

Ibrahim.

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Glad you got the results you needed. I guess you discovered that the PLOTS=FIT option automatically creates the graph.

 

The PARMS statement sets initial guesses for the nonlinear optimization, so I guessed. You can put any numbers that you want there, especially if you have a better guess than I do. If you make a bad guess, the process might not converge. If you make a good guess, it will converge in only a few iterations. 

View solution in original post

7 REPLIES 7
Rick_SAS
SAS Super FREQ

It sounds like you want to estimate the parameters in the model for the "average cow."

But are there covariates in the model, such as age or treatment?

 

Please provide example data. For example, do your data look like this?

 

data cows;
input
cow time milk;
datalines;
1 1 1.1
1 2 1.2
1 3 1.3
1 4 1.1
2 1 1.3
2 2 1.3
2 3 1.5
2 4 1.4
3 1 0.9
3 2 1.2
3 3 1.4
3 4 1.3
4 1 1.0
4 2 1.1
4 3 1.5
4 4 1.3
;

proc sgplot data=cows;
series x=time y=milk / group=cow;
run;

 

Rick_SAS
SAS Super FREQ

The PROC NLIN documentation contains a very similar example. Here it is modified for your model, using the data that I previously posted:

 

proc nlin data=cows plots=fit; 
   parms A=1 B=0.1 C=0.2;
   bounds A B C > 0; 
   model milk = A * time**b * exp(-C*time);
   output out=Fit predicted=Pred;
run;

Barkamih
Pyrite | Level 9

Hi Rick

 

My dataset looks like this 

I have Test_day_milk kg and Test date as this form of date dd/mm/yy but I had changed to Months only in order to have 12 months in X var. And milk kg in Var Y, Also How to additivity the Parameters A,B and c which based on what?

Alos, I'm looking for a code to plot this data as a lactation curve. 

 

my data set around 244000 records 

  

 

Herd	COW_ID	  Test_Day_milk _kg 	 Test_Date	   Months
A41  	2201	                 25	 01/01/2014     	1
A41     2201	                 45 	 02/04/2014       	4
A41  	2201	                 32	 15/05/2014         	5
A41   	2201	                 25      13/07/2014        	7
A42   	2202	                 25      05/02/2014         	2
A42   	2202	                 54      18/06/2014	        6
A42  	2202	                 44      08/08/2014	        8
A42     2202	                 45      20/10/2014	       10
A42     2202	                 32      20/11/2014	       11
A42    	2202	                 33	 25/12/2014	       12


_

 

 

Barkamih
Pyrite | Level 9

this code working and I got results 

 

but why 

A=1 B=0.1 C=0.2 ?

 sorry about that but I want to understand why you put 1 and 0.1 and 0.2 for parms 

 

thanks 

 

Regards 

Rick_SAS
SAS Super FREQ

Glad you got the results you needed. I guess you discovered that the PLOTS=FIT option automatically creates the graph.

 

The PARMS statement sets initial guesses for the nonlinear optimization, so I guessed. You can put any numbers that you want there, especially if you have a better guess than I do. If you make a bad guess, the process might not converge. If you make a good guess, it will converge in only a few iterations. 

Barkamih
Pyrite | Level 9
Great
thank you so much
I got the plots of my question, and thank you again for the explanation of parms.

kind Rgrds

Ibrahim

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 2241 views
  • 2 likes
  • 3 in conversation