Hello SAS community!
I'm working on fitting the lactation curve of dairy cows according to the calving season (1=winter, 2= spring and 3= summer) using the model of Wood for fitting.
My question here is that I want to draw the three curves together as one curve according to the three seasons and not each curve separately.
Can anyone please correct the code for me. I really need help!
Here is the data and the tried code:
data curves;
input season days Milk;
datalines;
1 22 7.63
1 54 7.25
1 85 8.40
1 113 8.10
1 142 5.75
1 174 6.00
1 208 5.00
1 230 4.00
1 263
1 299
2 17 8.54
2 46 8.71
2 75 7.27
2 107 5.46
2 140 5.82
2 167 6.22
2 187 6.60
2 219 3.00
2 258
2 285
3 16 7.00
3 50 9.00
3 84 7.00
3 107 9.50
3 140 8.00
3 163
;
proc nlin data = curves plots = fit;
parms A = 15 B = 0.19 C = -0.0012 ;
bounds A B C > 0;
by season;
model PL = A * days **b * exp(-C*days);
output out = Fit predicted = Pred;
by season;
run;
title1' lactation curve ';
proc gplot data=fit; plot pred*days milk*days/overlay;
by season;
run;
Thank you, the community!
I suggest you use the "missing value trick" to create an evenly spaced set of Jours for scoring. Then run the model and use PROC SGPLOT to overlay the data and curves. You do this by using the GROUP=saison option:
/* to improve the visualization, add a sequence of evenly spaced
values to the data. This is the scoring set. */
data Score;
Score = 1;
do saison = 1 to 3;
do Jours = 15 to 250 by 5;
output;
end;
end;
run;
data All;
set curves Score;
run;
proc sort data=All;
by saison Jours;
run;
proc nlin data = All plots = fit;
parms A = 15 B = 0.19 C = -0.0012 ;
bounds A B C > 0;
by saison;
model PL = A * Jours **b * exp(-C*Jours);
output out = Fit predicted = Pred ;
run;
title1' courbe de lactation ';
proc sgplot data=fit;
scatter y=PL x=Jours / group=saison;
series y=pred x=Jours / group=saison;
run;
Please look at the log for this code and fix the error. (That could be why you can't get a plot; or it may be there are additional errors)
Maybe you are running different code than what you showed above? When I copy and paste that code into SAS, there is an error in PROC NLIN.
Thank you, your code now works. However, I don't really understand this part:
I want to draw the three curves together as one curve according to the three seasons and not each curve separately.
Does this mean you want values 1 2 and 3 on the horizontal axis? If so, what should go on the vertical axis? Or do you want something else? I really need a more clear explanation.
@always-good wrote:
Yes this is what I mean, values 1,2 and 3 on the horizontal axis and the same vertical axis for all curves like in the code, I means "Jours".
I want to fit the curve of Milk production "PL" (horizontal axis) for the three seasons 1,2 and 3, according to the days "Jours" (vertical axis).
I'm still not grasping what you want. What "curves"? What is the value on the Y-axis? Can you show me a similar plot that is on the internet somewhere?
Please check this out
Please include a screen capture of this plot by clicking on the "Insert Photos" icon. I refuse to download files; and furthermore Microsoft Office documents can be a security threat.
lactation curves according to different season of calving
This does not look anything like what you said earlier "Yes this is what I mean, values 1,2 and 3 on the horizontal axis"
This doesn't seem to match your original description of the plot "My question here is that I want to draw the three curves together as one curve", this plot shows separate curves and does not draw the three curves together as one curve.
Not clear. The plot shows a horizontal axis going from 5 to 305. Do you want a horizontal axis that has only values 1, 2 and 3? (Because that's what you said earlier) And do you want ""My question here is that I want to draw the three curves together as one curve", or do you want three curves?
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.