turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2016 02:45 PM

I want to integral this function (1-chi-square(x/2,df=10))**5 by the chi-square(x, df=10), so I write the code below. However, the error showed up. Can any one help me solve this problem?

Proc iml;

start integrand(probchi(x,10));

return ((1-probchi((x/2),10))**5);

finish;

call quad(answer, "integrand", {0 .P});

print answer;

quit;

Accepted Solutions

Solution

10-01-2016
03:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Yang

09-21-2016 03:15 PM - edited 09-21-2016 03:39 PM

So that we can all use the same terminology, please review "The four essential functions for statistical programmers."

For the chi-square distribution, the CDF at x is the integral of the PDF from 0 to x. It looks like you want your integrand to be

(1 - CDF("ChiSq", x, 10))**5, and the domain of integration to be [0, infinity).

If so, then your code is almost right. Just a slight modification of the calling syntax (and I use CDF instead of PROBCHI):

```
proc iml;
start integrand(x);
return (1-cdf("ChiSq", x/2,10))##5 ;
finish;
call quad(answer, "integrand", {0 .P});
print answer;
```

All Replies

Solution

10-01-2016
03:33 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Yang

09-21-2016 03:15 PM - edited 09-21-2016 03:39 PM

So that we can all use the same terminology, please review "The four essential functions for statistical programmers."

For the chi-square distribution, the CDF at x is the integral of the PDF from 0 to x. It looks like you want your integrand to be

(1 - CDF("ChiSq", x, 10))**5, and the domain of integration to be [0, infinity).

If so, then your code is almost right. Just a slight modification of the calling syntax (and I use CDF instead of PROBCHI):

```
proc iml;
start integrand(x);
return (1-cdf("ChiSq", x/2,10))##5 ;
finish;
call quad(answer, "integrand", {0 .P});
print answer;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

09-21-2016 03:24 PM

Thank you! Yes, this is very helpful. But I want the "Integrand (CDF("ChiSq", x/2, 10))" instead of Integrand (x)). In other word, I want "dCDF("ChiSq", x/2, 10)" instead of "dx". How should I do that?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Yang

09-21-2016 03:38 PM

Sorry, but I don't understand your notation. I don't know what "dCDF" means, unless you mean PDF, which is the derivative of the CDF.

The Integrand function evaluates a function at a value of x. It returns a number. The QUAD function integrates that function on a (possibly infinite) interval. It returns the definite integral of the function on the interval.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Yang

09-21-2016 10:27 PM

Maybe you should calculated it by hand firstly. Assuming CDF("ChiSq", x/2, 10)= e^x , then dCDF("ChiSq", x/2, 10)= e^x * dx

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Ksharp

09-22-2016 07:44 AM

If F(x) is the cumulative distribution function and f(x) is the associated density, then one iterpretation of "dCDF" is

dF = dF/dx * dx = f(x) dx

which is why I suggested using the PDF function.

However, if the argument to F is itself a function of x, say u(x), then make sure you use the chain rule. For example, if the argument is u(x) then

d(F(u(x)) = dF/du * du/dx * dx = f(u(x)) * u`(x) dx