BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Yang
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

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;
Yang
Calcite | Level 5

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?

Rick_SAS
SAS Super FREQ

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.

Ksharp
Super User
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 

Rick_SAS
SAS Super FREQ

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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1165 views
  • 0 likes
  • 3 in conversation