* ================================================================== . * File: binomial.SPS . * Date: 11-Jun-2007 . * Author: Bruce Weaver, bweaver@lakeheadu.ca . * Notes: Generate binomial distribution with parameters N and p . * ================================================================== . * Modify the values of N and p in the macros below . * The pnum macro gives the numerator of the fraction that is p . * The pden macro gives the denominator of the fraction that is p. * E.g., for p = 0.5, set pnum = 1 and pden = 2 . * For p = 2/3, set pnum = 2 and pden = 3 . define !N ()15!enddefine. /* N = the number of trials . define !pnum ()1!enddefine. /* pnum = numerator of the p-fraction . define !pden ()2!enddefine. /* pden = denominator of the p-fraction. new file. input program. loop #i = 0 to !N. - compute N = !N . - compute p = !pnum / !pden. - compute q = 1 - p. - compute x = #i. - end case. end loop. end file. end input program. exe. COMPUTE px = PDF.BINOM(x,n,p) . COMPUTE cumpx = CDF.BINOM(x,n,p) . compute icumpx = 1 - cumpx. exe. format N x (f5.0) / p q px cumpx icumpx (f8.6). var lab n 'N' px 'p(X)' cumpx 'Sum p(x)' icumpx '1 - Sum p(x)'. summarize table = n p x px cumpx icumpx /title = 'Binomial distribution' /format = nocasenum list /cells = none. * ================================================================== .