Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Fitting the integral of a unknown function


From   "Steichen, Thomas J." <SteichT@RJRT.com>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Fitting the integral of a unknown function
Date   Thu, 5 Feb 2009 17:01:19 -0500

You can approximate it by summing over i = 2 to k:  (x[i]-x[i-1]) * (y[i] + y[i-1]) / 2
Where [] indicates a subscript and k is the number of (x,y) pairs.

This is the trapezoid approach where
(x[i]-x[i-1]) is the width of each interval.
(y[i-1] + y[i]) / 2 is the "half-height" of that interval.
The product is the area under that section of the curve.
The sum is the total area.

In simple Stata code:

sort x
gen areaparts = (x[_n]-x[_n-1]) * (y[_n] + y[_n-1]) / 2
egen area = total(areaparts)

-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tiago V. Pereira
Sent: Thursday, February 05, 2009 4:00 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Fitting the integral of a unknown function

Dear statalisters,

I am unsure if the topic is 100% related to the objective I am looking
for, because I failed to find an exact expression in English.

I have two positively correlated variables (say, X and Y) that can range
from 0 to 1.

For every value of X (0 to 1) I have values for Y, giving a non-linear
curve. Is it possible to calculate the area under the curve having only
these data?

All the best,

Tiago




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index