Hello everyone:
I'm a PhD candidate majoring in animal science in China.
As in your book which titled "SAS/STAT 9.3 User's Guide - The FMM Procudure (Chapter)", example 37.2 from page 2533-2541 illustrates when do cows eat.
I'm so interested in the content of one sentence "The point at which the second and third components cross over is used to separate feeding events into meals." which appears at page 2533.
However, the point's information mentioned above can not be found throughout this chapter. A small issue I wish to concern about is, which data or process in the FMM procedure offer hints to represent the value of this point at which the pdf of the two populations cross?
Thanks you allowing me for sharing my problem. Your reply may be highly appreciated
Best regards!
James Xu
My first comment is that if you want to separate the events into meals, it probably suffices to simply look at the picture and estimate the crossing visually. It doesn't make much difference to the cows whether the time is 9:00am or 9:07am.
However, if you want a rigorous solution, let f1 and f2 be the two densities for which you wish to find the crossing point. (Use the estimated parameters from PROC FMM.) Then the function f(x) - f1(x)-f2(x) is zero at the crossing point, and you can find the zero by using any numerical root-finding method. For example, in the SAS/IML 12.1 language you can use the FROOT function:
proc iml;
start func(x);
f1 = pdf("Normal", x, 0, 1); /* density of N(0,1) */
f2 = pdf("Normal", x, 1, 2); /* density of N(1,2), where 2 is std dev */
return( f1 - f2 );
finish;
x = froot("Func", {0 3});
print x;
If you are running a version of SAS/IML prior to 12.1, you can use the bisection module to find the root. See Finding the root (zero) of a function in SAS
Dear Rick:
Thanks so much for your reply, and it must give me good suggestion to solve my question.
Given the accurate data which I want to obtain, the function and method referring to FROOT function is preferred.
In strict accordance with your statement in SAS/IML 12.1, I try to fix these statements in your example illustrating the distribution of Scrabble® scores which is characterized by a mixture of two normal distributions upon your score.
proc iml;
start func(x);
f1 = pdf("Normal", x, 21.7, 6.7); /* density of N(21.7,6.7), where 2 is std dev in your example*/
f2 = pdf("Normal", x, 37.3, 3);
return( f1 - f2 );
finish;
x = froot("Func", {27 37});
print x;
However, after performing, the error terms occur : "Matrix x has not been set to a value".
What does it mean? And any errors in my statements?? If have, could you please tell me??
Thank you for your helpful assistance.
Your code is correct. My guess is you don't have SAS/IML 12.1. Check the LOG to see If you are getting an error such as "ERROR: the FROOT function is not found."
Thanks for reminding, my SAS sofeware actually have a little problems when installing, FROOT function is not available in my computer, but the bisection method is OK. Then I change the statement as below:
proc iml;
start func(x);
f1 = pdf("Normal", x, 12.7, 6.7); /* density of N(12.7,6.7), where 6.7 is std dev in your example*/
f2 = pdf("Normal", x, 37.3, 3);
return( f1 - f2 );
finish;
start bisection(a, b);
dx = 1e-6; dy = 1e-4;
do i = 1 to 100;
c = (a+b)/2;
if abs(func(c)) < dy | (b-a)/2 < dx then
return(c);
if func(a)#func(c) > 0 then a = c;
else b = c;
end;
return (.);
finish;
z = bisection(27, 37);
print z;
Then the SAS procedure determines the solution is "Z=29.03".
Is the statement mentioned above right or wrong?
By the way, you said that the function f(x) - f1(x)-f2(x) is zero at the crossing point,but why return(f1-f2) in the func(x), is that meaning f1(x)-f2(x)=0???
Looking forward your friendly answer!
Many thanks and best regards!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.