Chicken Soup

From Norsemathology
Jump to navigation Jump to search

Independent Research Project, MAT499

Randy at work, recording egg data for the day

Project Summary: When Should Egg Layers Be Replaced?

  • Randy Wiebe is a poultry farmer in Manitoba. At some point in each cycle of production, Randy has to decide when to replace his layers -- and ideally, he would do it when they are effectively exhausted (still producing, but not as they once were), and when replacing them with new hens will prove economically advantageous (there's the cost of the new hens, the down time, the time it takes for the new girls to ramp up production, etc.).
  • Steve Wilcox has undertaken to find a model that will prove useful to Randy (and others) as they decide when to change out their current layers.
  • Some more pictures:
  1. That's a long line of chickens to tend!. There are several aisles like this in the barn.
  2. Manure coming off the end of the line. This is a cost of egg production, but could also be of value as a source of fertilizer.
  3. The eggs drop from the hen, and are gravity fed to a conveyor belt outside of the cages.
  4. Eggs coming off the line, when the conveyors are set in motion.
  5. Here are eggs being machine packed into trays (unsorted in any way, so all grades are packed together).
  6. Cartons of Eggs are loaded onto wheeled pallets, which are refrigerated until the trucks take the eggs to Winnipeg.


We have some information to start with:


  • Q: Randy, I recall that you told me that the Poultry provider said 70 weeks is the optimal lifespan, but we'd like a better reference that "personal communication" -- could you provide a reference, please? Product information ( suggests an 80 week laying period, which is almost exactly what we found as the optimal time.
  • Q: From whom do you buy the hens? Could I get the name, address, contact information, etc.?
  • Q: How much lead time do you need to order the next flock? If we can tell you 23 weeks before you need the next batch, would that be long enough?


Some Background Information: The hen housed is our starting number of birds carried through to the end , about 365 days. The levy off our eggs is what our provincial and national egg boards need to make our supply management system work properly. Each egg farmer has to meet a minimum egg production (24.9 doz/hen housed) and if the farmer doesn't meet the minimum he has to pay the difference but if he is over he gets a refund for the difference. Levy price and egg price per doz can fluctuate through out the year to offset higher input costs like feed or if they are carrying to much surplus eggs in the system they end to compensate the farmers because the eggs might go at a discount to get rid of them, so the boards try to carry a reserve of cash to cover off a problem like that. It is quite a complex system but at least the farmer always makes a margin. Egg farming in Canada under this system is not a boom or bust, just a constant margin.

  • Q: There are a few odd things in this data, as seen in the scatterplot: Specifically around week 20 in the 2010 data. The number of eggs seems to drop dramatically at this point, but 20 weeks seems way too early for this to happen. Do you know why there are some data points that are a lot lower than they should be? We would guess the reason for this is simply because there was more than one pickup for those particular weeks, so the lower numbers are the numbers for the second pickup for that week. Would that be a correct assumption to make?
    A: Week 20 question?. 1st scenario and hopefully might clear up some confusion (and according to your email I think you figured it out) is that the May 2010 invoices are from this years flock and that you are missing the Apr 7-June 2009 + 1 week in March 2010 invoices.(this will account for the weird numbers). Scenario 2, around the 16th week (week 34 on the daily production chart,end of July beginning of August) the chickens had a challenge which set them back for about 3 weeks until they regained the previous production numbers. --- Some data points lower? If you took the info off the grade out invoice then there is a possible egg pick up difference. Some weeks they may have picked up twice a week with each pick up receiving a invoice. That may account for that but if the data was taken off the daily egg chart then it could be something like the challenge or egg collection time(early or later in the day) for that week.
  • Q: This plot gives rise to another question: it appears that, for the first few weeks, the chickens have an extremely consistent number of eggs. It seems very unlikely that the chickens produced the same number of eggs for three or four weeks in a row, so would you know why this seems to happen a number of times? Here are the sorted data for egg totals, and you'll notice that there are a lot of repeats: 2700 3600 4500 9000 9000 9000 9900 9900 9900 10620 10800 10800 10800 10800 10800 10800 10800 10800 11595 11700 11700 11700 11700 11700 11700 11700 11700 11700 11700 11700 11700 12600 12600 12600 12600 12600 12600 12600 12600 12600 12600 12600 13500 13500 13500 13500 13500 13500 14400 14400. Our guess, based on the differences in these values, is that the pallets of eggs come in 900 dozen units....
    A: week to week consistent numbers? Yes the consistent numbers represent that they picked up the same number of pallets (1 pallet =10800 eggs or 900 doz.) from week to week.
  • Q: What breeds of chickens we are dealing with?
    A: (Randy's Answer) a leghorn called a Shaver White.
  • Q: We're looking at the daily egg production numbers you gave me, and we're looking at the grade out sheets you provided, and we notice that the start date on production is April 7th, 2009, but that the gradeouts don't start until June 3rd. Do you have some other sheets you can share? Or what went on that we don't have grade out sheets for the early going?
  • Q: Speaking of missing grade out sheets, we seem to be missing the grade-out sheet for the first week of March. Do you have that?
    A: Randy will provide.
  • Q: Could you give us a good estimate for the costs associated with the "down time", when you're swapping out a flock of hens? How long does this last? For example, how much do you save each day because you don't have to feed the hens? How much are the cleaning supplies to clean out the barns? How much does it cost to have the hens killed and removed? Etc.
    A: cost of down time? Some costs associated with cleaning out, cleaning up and starting up again include.
    -flock disposal-21819 @ .30 cents = 6545.70
    -Labor (washing,maintenance etc)=2000.00
    -kerosine (hot pressure washer) = 250.00
    -disinfectant = 300.00
    -fumigate = 400.00
    -repairs/maintenance = 1000.00 (unpredictable)
    -suction truck = 100.00
    Cost to start up
    -price to buy the birds 22696 @ 5.50 = 124828.00
    -flock placement (labor) 22696 @ .15 = 3404.40
    Savings on down time
    -feed = 8000.00
  • Q: Is there any reason that the egg quality would change dramatically from day to day (e.g. forgetting to feed the chickens?)
    A: Egg quality day to day? - I'm not sure except under grades (rejects, and cracks) and size (small, medium, large etc) vary as the birds get older, more under grades and size gets bigger as birds get older.
Time Series Plot of Death Total.jpg
  • Q: The plot above is the number of deaths (per week) for the chickens. It appears from this graph that at around week 41-45, the number of deaths increased significantly, then dropped back down after week 46. Do you happen to remember any significant reasoning behind this sudden increase in deaths across this four week period of time? It appears possible to me that the timing for those weeks would be right around some time in November or December, would that be correct? Perhaps that is the reason for the increase in chicken deaths?
    A: Increased deaths?-nothing really specific happened during those weeks. Sometimes birds react to a change in ration in the feed and it takes a while for us to help them through that transition or they were under some other kind of stress that is hard to determine and it takes a bit of time again to get them through it. If these weeks fell in the summer months it would be a little easier to figure out that some of them would die due to heat stress but these weeks are in Sept/Oct so that scenario is not applicable in this case.
  • Q: Are cracked or otherwise "bad" eggs being removed before the egg is even accounted for?
    A: All eggs are accounted for on the grade out invoice except the ones that are obviously broken or leaking which we throw out while collecting the eggs.
  • Q: What other economic factors are working against us? For example, chicken feed and cleaning supplies are necessary items in order to make this process work. So what other types of things are needed for this process?
    A: other costs?-some day to day costs associated with egg farming are
    -feed $11.00 per hen housed (22696) = 249656.00
    -levy $7.00/h.h. (supply management fee) =158872.00
    -other $10.00/h.h. (labor,utilities,maintenance,etc) =226960.00
  • Q: As I recall, your brother Steve likes to collect the eggs early, but you like to do it later -- so might that account for why the egg production (as seen in the daily egg counts) seems to bounce around so much? What can you tell us about that?
    A: Varying daily egg numbers? Yep, egg numbers vary from day to day sometimes because of what time we start gathering the eggs. Even a 1/2 hr collection variation from day to day can effect numbers 2000 eggs more or less.
  • Q: How many days does it take you to change out a set of hens and put in a new one? We've got 11 days in our model, but that's a parameter that the poultry farmer can play with. What number shall we use for you?
    A: days between flocks? We try to keep our down days to about 10 days. This is a recommended amount from our egg board. The main reason for this amount of days is to hopefully let the barn dry down and thus kill any lingering bad bacterias and other pathogens.
  • Q: We have the costs associated with the transition period at $139091.20: does that seem reasonable?
    A: The number of 139000.00 sounds about right
  • Q: We run the model with the levy, and without, and it doesn't seem to make much difference in how many days to keep the flock. It does reduce your profits considerably, of course, when you have to pay $7.00/hen. Is this something that you pay each time you begin a new flock? Or is it something that would increase in price if you were to keep the hens longer? Obviously, if it's fixed, this is one factor that argues for keeping the hens longer.
    A: The levy is an annual, calendar year fee taken off of each egg check that egg farmers have to pay to be a registered producer. It is based on the number of birds the egg farmer has. In our case we are registered to have 22696 birds and the egg board needs the egg farmers to get the birds to produce 24.99 Doz @ .28 cents/doz/year to run the national supply management system. So in this case the board requires from us 22696birds*24.99doz*.28cents/doz/year=$158808.00 for the calendar year (Jan 1-Dec 31). If for some some reason our birds don't lay 24.99 doz/bird we have to pay the difference of what we are short, but if we are fortunate enough to produce over 24.99 doz/bird then we would receive a refund for the difference that we are over. Essentially the levy gives the egg board a reliable source of income to maintain our national system. The levy does play in because whether our birds are laying well or not we have to, in this case, come up with 158000.00. This is simplistic overview of our levy system, it gets quite involved when a person digs into the system.
  • Q: How come we're missing a day of eggs at the beginning of the cycle? On April 7, we have 14000 eggs or so; none on the 8th? Then, for three days running in the next week, we have the same number of eggs -- 12780 -- on three days running: what's going on?
    A: Our birds were put in the barn Apr 4 and then the first few days they don't lay very many eggs so we wait until there is enough eggs to make it worth while to run the egg belts, in this case Apr 7 we collected and then Apr 8 we left and then Apr 9 we collected 2 days worth and from there everyday. The reason for 3 days having the same numbers eggs (12780) each day is just coincidence, time of collecting, birds picking up their egg production, etc.



We use the following data that Randy has provided:

  1. Costs for daily operations and for the down period when transitioning from one flock to another,
  2. Egg prices,
  3. Daily egg output (in eggs total), and
  4. Grade-outs from the egg buyers in Winnipeg, roughly once per week.

From all of that we compute new data, which we will model -- the average profit per day. We do this by interpolating the grades of daily eggs from the weekly grade-outs. We then seek to find the number of days to keep a flock, so that if their production is reflected by the model then we will maximize the average profit per day. This will maximize Randy's return in the long run.

For the moment we use the "grade-outs" individually, using linear interpolants to determine the proportion of each type of egg on dates for which we don't have grade outs. For example, below we show the plot for the number of medium eggs per day. We could model this graph by smoothing it (removing noise), or we could simply "connect the dots" as shown in the graph so as to predict what happened between times when we have actual data.

Medium per Day.jpg

This is only one method we could use to create a model for the grades on individual days, which are necessary to produce a daily economic value (per the first image above). Another strategy (which we have already investigated) is to compute the Singular Value Decomposition (SVD) on the matrix of grades of eggs over time, then smooth it out by removing noise and modeling the components remaining. This could then serve to estimate the proportions of each type of grade at any date. Having modeled the grades of the eggs for any given day, we then move to modeling the average daily profit function, as in this plot:

09-10 Flock Estimates

From the model, we can predict the duration of the current flock (this one is predicted to go for 440 days). From this information, which we can generate as the data comes in, the farmer can gauge the moment when he should place the order for the replacement flock. The model that's flowing through the data is a product of two logistic functions,

This model seems to have the right properties: it's asymptotically zero both before the hens are introduced and in the long run (when all the hens will be dead). The parameters can be interpreted as follows:

  1. : the steepness of the logistic responsible for capturing the initial rise;
  2. : the center of the logistic responsible for capturing the initial rise;
  3. : the steepness of the logistic responsible for capturing the long decline;
  4. : the center of the logistic responsible for capturing the long decline;
  5. : the (approximate) height to which the model rises. This captures the peak of the production profit curve.

Xlispstat Analysis File (that produced the plot above)

This one is "owned" by the XLarge, Large, and Medium Eggs, which are all negative on it (meaning that they're growing, rather than declining).
This one is positively weighted by the XLarge and Large, meaning that they're growing with this one, but the Medium is negatively weighted on this (the eggs are transferring from Medium to Large, and then moving on to XLarge).
This one is negatively weighted by Peewee, Small, and XLarge, and positively by Medium.
Weighted positively by XLarge and Medium, and negatively by the Large, Small, and Peewee.
Peewee largly owns this with negative value, while Small is positive.
This one, owned almost exclusively by Cracked, is counterbalanced by the XLarge (they're contributing primarily to the cracks in the end).
Almost entirely owned by Grade B.
Singular Values, ranked:
  • 4.444
  • 1.514
  • 0.948
  • 0.411
  • 0.107
  • 0.053
  • 0.005
PCA Variables:
-0.320 -0.876 -0.359 -0.028 -0.003 -0.006 -0.038
0.310 0.221 -0.777 -0.492 -0.096 -0.004 0.026
-0.384 0.010 0.386 -0.801 -0.245 -0.000 -0.046
0.793 -0.425 0.332 -0.172 -0.194 -0.006 0.112
-0.090 0.064 -0.088 0.293 -0.944 0.030 -0.040
0.132 -0.012 0.016 -0.006 0.026 0.044 -0.990
0.001 -0.008 -0.001 -0.012 0.026 0.999 0.046
The seven singular vectors of the PCA. The singular values are given in the second panel, third row. The coordinates of the singular vectors are given in the matrix in the final panel, giving the "weightings" of each variable on each component.

When we compute the Principal Components of the matrix of the seven grades of eggs over the course of the cycle, we find that there are six components that have some balance (the seventh is essentially owned entirely by the Grade B eggs, which are at the origin of each of these plots).


Randy's total return on a cycle of production is a function of several facets: how long he keeps his flock, the cost of the transition, etc. We have modeled his average daily return if he keeps the flock for days as follows:


  1. CPD is the Cost Per Day during Egg Production (we're using $1712.91, at present)
  2. TTC is Total Transition Cost (we're using $139091.20, at present)
  3. TTT is Total Transition Time (we're using 11 days, at present)

For the parameters we obtain for the DailyEggGrossReturn model, the AverageDailyReturn function looks like this:


We want to maximize this, so we use Newton's Method to find its peak, which is at about 436 days (with the Levy figured into the cost).

Now, we wanted to see how stable this procedure is from the farmer's perspective. The farmer will be providing a steady stream of data: daily egg production numbers and grade-out sheets. From these we can create the daily gross profit data, and fit it with a model. However, so long as the daily gross profit numbers are up high and holding, the model would simply say "keep the flock forever!" It's not until the profits begin to dip that the farmer is going to start considering that it's time to change out the flock.

So at about 170 days we start to see a dip in the profit numbers, as one can see:

09-10 Flock Estimates

We backed out procedure up to that point, and, using only the first 170 days of data, we were not able to fit a model of the form

At 170 days, the model we obtained looked like this:


The farmer should say to himself that things are going pretty well: no sense in thinking about changing out the flock at this point.

However, as we continue on, eventually the data dips enough that we can fit the AverageDailyReturn function. When we do, we can begin to predict the optimal duration. The following plot shows how the model prediction evolves for the set of data we have:


It was at day 193 that the non-linear regression procedure was able to detect the down-turn, and compute parameters for AverageDailyReturn. By day 240 or so, we've settled on a duration of about 450 days. Over the course of the next 130 days, it doesn't vary much: predictions seem to pretty stably predict that 440 days would be about the right length for this flock. This is encouraging!

We know that our parameter choice is wrong. What if the parameter choice is mis-specified? We did a sensitivity analysis, allowing our parameters to vary according to the standard errors of the parameters, but conditioned on their joint probability distribution. We sampled 1000 parameter sets with probabilities of .7 or less, and evaluated their predicted durations. The results are in the following figure:


Again, the results are comforting: the mean number of days stays consistently in the 430-something range, and the worst case scenarios are still around 400 or more.


We've decided to hold prices fixed, per one of the income reports Randy received. Incorporating a floating price structure would be more realistic, but the next stage of model development. The prices are as follows:

  1. Extra Large and Large: $1.54/dozen
  2. Medium: $1.36/dozen
  3. Small: $.94/dozen
  4. PeeWee: $.2425/dozen
  5. Grade B: $.45/dozen
  6. Grade C/Cracked: $.15/dozen

However, the prices of types of eggs are crucial: if the value of Extra Large were increased for example, you would find that it paid to keep the hens around longer, because the production of Extra Large eggs is rising even as the hens are being sent off for slaughter. What we're seeing in the data is that, as time goes on, the hens shift from pee wees, to small, to medium, to large, to extra large. We also see an increase in cracked, because the shells are getting thinner as the hens get older, in line with the references below.



  • Added in the draft for the paper.
  • Added a few questions into the "Questions" section.


  • Added in the SVD matrices (at least what I believe should be correct)


  • Updated the draft for the final paper.


  • Updated the draft for the final paper again.


  • Updated draft for the final paper.


  • Dramatically changed and updated the draft for the final paper.