{"id":72,"date":"2012-04-04T01:38:00","date_gmt":"2012-04-04T05:38:00","guid":{"rendered":"http:\/\/jeffq.com\/blog\/?p=72"},"modified":"2012-04-04T01:38:00","modified_gmt":"2012-04-04T05:38:00","slug":"modeling-weight-loss-with-differential-equations","status":"publish","type":"post","link":"https:\/\/jeffq.com\/blog\/modeling-weight-loss-with-differential-equations\/","title":{"rendered":"Modeling weight loss with differential equations"},"content":{"rendered":"<p>This comes from a talk I&#8217;m giving at <a href=\"http:\/\/penguicon.org\">Penguicon 2012<\/a>. The talk in general is about weight loss and getting healthy but part of it involves doing some predictive modeling of future weights based on calorie counting.<\/p>\n<p>Consider the question &#8220;if I eat X number of calories a day, will I gain or lose weight?&#8221;. It&#8217;s a supremely practical question but without doing some research it isn&#8217;t immediately apparent how to answer this. The best place to start is one of the formulas for calculating <a href=\"http:\/\/en.wikipedia.org\/wiki\/Basal_metabolic_rate\">basal metabolic rate<\/a>. The obligatory Wikipedia link provides some more background but in short it gives us a formula for the &#8220;baseline&#8221; number of calories our body needs. Mifflin-St. Jeor is considered by many [citation needed] to be the most accurate. It is of the form:<\/p>\n<p><a style=\"font-style: normal; line-height: 24px; text-decoration: underline;\" href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-74 aligncenter\" style=\"background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee;\" title=\"Mifflin-St. Jeor equation\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj.png\" alt=\"\" width=\"350\" height=\"51\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj.png 350w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj-300x43.png 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><\/p>\n<p>In this formula, <em>m<\/em> is mass in kilograms, <em>h<\/em> is height in centimeters, <em>a<\/em> is age in years, and <em>s<\/em> is a gender offset which is either +5 for men or -161 for women. This gives us <em>P<\/em>, our basal metabolic rate in calories. An interesting thing about BMR is that it&#8217;s a measure of your caloric needs at more or less complete rest. A normal person&#8217;s caloric needs to maintain weight will usually be strictly greater than their BMR. Because of this, <em>P<\/em> is usually scaled by an &#8220;activity factor&#8221; which factors in daily life. This can range from ~1.2 for someone with a desk job who gets no exercise to ~1.9 for someone who engages in some serious workouts. Now that we know our caloric needs, how can use this to model where our weight will be in the future?<!--more--><\/p>\n<p>Let&#8217;s modify the M-SJ equation to use some arbitrary function <em>w(t)<\/em> which gives our weight after time <em>t<\/em> instead of the constant <em>m<\/em>. I&#8217;ll also bring in the activity factor <em>f<\/em>. Now we have:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj1.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-79\" title=\"Modified MS-J with activity factor and w(t)\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj1.gif\" alt=\"\" width=\"304\" height=\"82\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj1.gif 304w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj1-300x80.gif 300w\" sizes=\"(max-width: 304px) 100vw, 304px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">An apology to my metric-inclined friends but I&#8217;m using <em>w(t)<\/em>&#8216;s output as pounds (which is why I&#8217;m dividing by 11\/5 to convert to kilograms). <em>P<\/em> is now our adjusted metabolic rate. Let&#8217;s insert a new variable, <em>d<\/em>, which will represent our daily diet in calories. If we take <em>d<\/em> and subtract it by <em>P<\/em>, we will have our daily net caloric\u00a0deficit\/surplus.<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj2.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-81 aligncenter\" title=\"Daily caloric deficit\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msj2.gif\" alt=\"\" width=\"298\" height=\"82\" \/><\/a><\/p>\n<p style=\"text-align: left;\">It&#8217;s an accepted estimate that 3500 calories equals one pound. If we divide this whole equation by 3500, we&#8217;ll have how much we&#8217;d expect to our weight to change by eating <em>d<\/em> calories when weighing <em>w(t)<\/em>. But, <em>this is precisely the derivative of w(t)!<\/em>\u00a0Our equation now looks something like this:<\/p>\n<p style=\"text-align: left;\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msjdiffq1.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-83 aligncenter\" title=\"MS-J Differential Equation\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msjdiffq1.gif\" alt=\"\" width=\"375\" height=\"89\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msjdiffq1.gif 375w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/msjdiffq1-300x71.gif 300w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p style=\"text-align: left;\">This allows us to solve for <em>w(t)<\/em>.<\/p>\n<p><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/generalwt.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-89 aligncenter\" title=\"General w(t)\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/generalwt.gif\" alt=\"\" width=\"436\" height=\"62\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/generalwt.gif 436w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/generalwt-300x42.gif 300w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/a><\/p>\n<p>The left term is the weight we&#8217;re asymptotic to; our &#8220;plateau&#8221;.\u00a0<em>c<sub>1<\/sub>\u00a0<\/em>is the constant of integration. At\u00a0<em>t<\/em>\u00a0= 0, <em>w(t)<\/em> equals the left term plus\u00a0<em>c<sub>1<\/sub><\/em>. To model for a specific person,\u00a0<em>t<\/em>\u00a0= 0 should be equal to their starting weight. Therefore,\u00a0<em>c<sub>1\u00a0<\/sub><\/em>should be equal to the difference between their start weight and the left term.<\/p>\n<p>We&#8217;ve created a nice complicated formula, but sadly this a 7-dimensional surface (8 if you include the starting weight) and doesn&#8217;t offer much in the way of visualization. To get some more concrete results. Let&#8217;s pick some values for the constants\u00a0<em>a, h, s, f<\/em>\u00a0and starting weight which are invariant (more or less) for a given person.<\/p>\n<figure id=\"attachment_91\" aria-describedby=\"caption-attachment-91\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-91\" title=\"weight-24yo-177cm-1.2af-male\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-300x223.gif\" alt=\"\" width=\"300\" height=\"223\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-300x223.gif 300w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-402x300.gif 402w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male.gif 450w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-91\" class=\"wp-caption-text\">24 year old, 5&#39; 10&quot; male at a desk job starting at 300 pounds<\/figcaption><\/figure>\n<figure id=\"attachment_93\" aria-describedby=\"caption-attachment-93\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-36yo-155cm-1.3af-female.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-93\" title=\"weight-36yo-155cm-1.3af-female\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-36yo-155cm-1.3af-female-300x218.gif\" alt=\"\" width=\"300\" height=\"218\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-36yo-155cm-1.3af-female-300x218.gif 300w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-36yo-155cm-1.3af-female-411x300.gif 411w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-36yo-155cm-1.3af-female.gif 450w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-93\" class=\"wp-caption-text\">36 year old, 5&#39; 1&quot; female with light exercise starting at 135 pounds<\/figcaption><\/figure>\n<p>Pretty 3D! If we pick a fixed diet <em>d <\/em>the graph becomes even more instructional.<\/p>\n<figure id=\"attachment_97\" aria-describedby=\"caption-attachment-97\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-1900calories.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-97\" title=\"weight-24yo-177cm-1.2af-male-1900calories\" src=\"http:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-1900calories-300x188.gif\" alt=\"\" width=\"300\" height=\"188\" srcset=\"https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-1900calories-300x188.gif 300w, https:\/\/jeffq.com\/blog\/wp-content\/uploads\/2012\/04\/weight-24yo-177cm-1.2af-male-1900calories.gif 450w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-97\" class=\"wp-caption-text\">24 year old, 5&#39; 10&quot; male at desk job on a 1900 calorie diet starting at 300 pounds<\/figcaption><\/figure>\n<p>Hope this was insightful! For anyone in the Metro Detroit area, I&#8217;ll be speaking more on this again at <a href=\"http:\/\/penguicon.org\">Penguicon 2012<\/a>. See you there!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This comes from a talk I&#8217;m giving at Penguicon 2012. The talk in general is about weight loss and getting healthy but part of it involves doing some predictive modeling of future weights based on calorie counting. Consider the question &#8220;if I eat X number of calories a day, will I gain or lose weight?&#8221;. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":91,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[8,9],"_links":{"self":[{"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/72"}],"collection":[{"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":27,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":109,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/posts\/72\/revisions\/109"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/media\/91"}],"wp:attachment":[{"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jeffq.com\/blog\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}