From noreply at r-forge.r-project.org Sun Oct 27 22:27:04 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 27 Oct 2013 22:27:04 +0100 (CET) Subject: [Prob-commits] r41 - in pkg: . R inst/doc man vignettes Message-ID: <20131027212704.3C3EA185A3A@r-forge.r-project.org> Author: gkerns Date: 2013-10-27 22:27:03 +0100 (Sun, 27 Oct 2013) New Revision: 41 Added: pkg/vignettes/ pkg/vignettes/charfunc.Rnw pkg/vignettes/prob.Rnw Removed: pkg/LICENSE pkg/inst/doc/charfunc.pdf pkg/inst/doc/charfunc.rnw pkg/inst/doc/prob.pdf pkg/inst/doc/prob.rnw Modified: pkg/DESCRIPTION pkg/R/characteristicfunctions.r pkg/R/prob.r pkg/R/utils-events.r pkg/man/prob-package.Rd Log: Fix bug first reported by Ryan Morrison. Also a lot of litte changes and fixes Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/DESCRIPTION 2013-10-27 21:27:03 UTC (rev 41) @@ -1,6 +1,6 @@ Package: prob -Version: 0.9-3 -Date: 2011-12-19 +Version: 0.9-4 +Date: 2013-10-27 Title: Elementary Probability on Finite Sample Spaces Author: G. Jay Kerns Maintainer: G. Jay Kerns @@ -14,6 +14,6 @@ and conditional probability, tools for simulation and checking the law of large numbers, adding random variables, and finding marginal distributions. Characteristic functions for all base R distributions are included. -License: GPL (>= 2) -URL: http://prob.r-forge.r-project.org, http://people.ysu.edu/~gjkerns +License: GPL (>= 3) +URL: http://prob.r-forge.r-project.org, http://people.ysu.edu/~gkerns Deleted: pkg/LICENSE =================================================================== --- pkg/LICENSE 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/LICENSE 2013-10-27 21:27:03 UTC (rev 41) @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. \ No newline at end of file Modified: pkg/R/characteristicfunctions.r =================================================================== --- pkg/R/characteristicfunctions.r 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/R/characteristicfunctions.r 2013-10-27 21:27:03 UTC (rev 41) @@ -71,7 +71,7 @@ cfhyper <- function(t, m, n, k){ if (m < 0 || n < 0 || k < 0) stop("m, n, k must be positive") - hypergeo:::hypergeo(-k, -m, n - k + 1, exp(1i*t))/hypergeo:::hypergeo(-k, -m, n - k + 1, 1) + hypergeo::hypergeo(-k, -m, n - k + 1, exp(1i*t))/hypergeo::hypergeo(-k, -m, n - k + 1, 1) } Modified: pkg/R/prob.r =================================================================== --- pkg/R/prob.r 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/R/prob.r 2013-10-27 21:27:03 UTC (rev 41) @@ -1,6 +1,4 @@ - - `Prob` <- function (x, ...) UseMethod("Prob") @@ -28,7 +26,7 @@ } else { f <- substitute(given) - g <- eval(f, x) + g <- eval(f, x, enclos = parent.frame()) if (!is.logical(g)) { if (!is.data.frame(given)) stop("'given' must be data.frame or evaluate to logical") @@ -48,9 +46,6 @@ } - - - `Prob.ps` <- function (x, event = NULL, given = NULL, ...){ if (is.null(x$probs)) { message("'space' is missing a probs component") @@ -62,7 +57,7 @@ else { e <- substitute(event) r <- sapply(x$outcomes, function(t) { - eval(e, t) + eval(e, t, enclos=parent.frame()) }) if (!is.logical(r)) stop("'event' must evaluate to logical") @@ -77,7 +72,7 @@ else { f <- substitute(given) g <- sapply(x$outcomes, function(t) { - eval(f, t) + eval(f, t, enclos=parent.frame()) }) if (!is.logical(g)) { if (!is.probspace(given)) Modified: pkg/R/utils-events.r =================================================================== --- pkg/R/utils-events.r 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/R/utils-events.r 2013-10-27 21:27:03 UTC (rev 41) @@ -3,13 +3,11 @@ `countrep` <- function (x, ...) UseMethod("countrep") - `countrep.data.frame` <- function (x, ...){ apply(x, MARGIN = 1, FUN = countrep, ...) } - `countrep.default` <- function (x, vals = unique(x), nrep = 2, ...){ res <- 0 if (length(x) >= nrep) { @@ -24,7 +22,6 @@ } - `isin` <- function (x, ...) UseMethod("isin") Deleted: pkg/inst/doc/charfunc.pdf =================================================================== --- pkg/inst/doc/charfunc.pdf 2011-12-19 16:58:56 UTC (rev 40) +++ pkg/inst/doc/charfunc.pdf 2013-10-27 21:27:03 UTC (rev 41) @@ -1,3596 +0,0 @@ -%PDF-1.4 -%???? -5 0 obj -<< /S /GoTo /D (section.1) >> -endobj -8 0 obj -(1 Introduction) -endobj -9 0 obj -<< /S /GoTo /D (section.2) >> -endobj -12 0 obj -(2 Characteristic functions) -endobj -13 0 obj -<< /S /GoTo /D (subsection.2.1) >> -endobj -16 0 obj -(2.1 Beta distribution: cfbeta\(t, shape1, shape2, ncp = 0\)) -endobj -17 0 obj -<< /S /GoTo /D (subsection.2.2) >> -endobj -20 0 obj -(2.2 Binomial distribution: cfbinom\(t, size, prob\)) -endobj -21 0 obj -<< /S /GoTo /D (subsection.2.3) >> -endobj -24 0 obj -(2.3 Cauchy Distribution: cfcauchy\(t, location = 0, scale = 1\)) -endobj -25 0 obj -<< /S /GoTo /D (subsection.2.4) >> -endobj -28 0 obj -(2.4 Chi-square Distribution: cfchisq\(t, df, ncp = 0\)) -endobj -29 0 obj -<< /S /GoTo /D (subsection.2.5) >> -endobj -32 0 obj -(2.5 Exponential Distribution: cfexp\(t, rate = 1\)) -endobj -33 0 obj -<< /S /GoTo /D (subsection.2.6) >> -endobj -36 0 obj -(2.6 F Distribution: cff\(t, df1, df2, ncp, kmax = 10\)) -endobj -37 0 obj -<< /S /GoTo /D (subsection.2.7) >> -endobj -40 0 obj -(2.7 Gamma Distribution: cfgamma\(t, shape, rate = 1, scale = 1/rate\)) -endobj -41 0 obj -<< /S /GoTo /D (subsection.2.8) >> -endobj -44 0 obj -(2.8 Geometric Distribution: cfgeom\(t, prob\)) -endobj -45 0 obj -<< /S /GoTo /D (subsection.2.9) >> -endobj -48 0 obj -(2.9 Hypergeometric Distribution: cfhyper\(t, m, n, k\)) -endobj -49 0 obj -<< /S /GoTo /D (subsection.2.10) >> -endobj -52 0 obj -(2.10 Logistic Distribution: cflogis\(t, location = 0, scale = 1\)) -endobj -53 0 obj -<< /S /GoTo /D (subsection.2.11) >> -endobj -56 0 obj -(2.11 Lognormal Distribution: cflnorm\(t, meanlog = 0, sdlog = 1\)) -endobj -57 0 obj -<< /S /GoTo /D (subsection.2.12) >> -endobj -60 0 obj -(2.12 Negative Binomial Distribution: cfnbinom\(t, size, prob, mu\)) -endobj -61 0 obj -<< /S /GoTo /D (subsection.2.13) >> -endobj -64 0 obj -(2.13 Normal Distribution: cfnorm\(t, mean = 0, sd = 1\)) -endobj -65 0 obj -<< /S /GoTo /D (subsection.2.14) >> -endobj -68 0 obj -(2.14 Poisson Distribution: cfpois\(t, lambda\)) -endobj -69 0 obj -<< /S /GoTo /D (subsection.2.15) >> -endobj -72 0 obj -(2.15 Wilcoxon Signed Rank Distribution: cfsignrank\(t, n\)) -endobj -73 0 obj -<< /S /GoTo /D (subsection.2.16) >> -endobj -76 0 obj -(2.16 Student's t Distribution: cft\(t, df, ncp\)) -endobj -77 0 obj -<< /S /GoTo /D (subsection.2.17) >> -endobj -80 0 obj -(2.17 Continuous Uniform Distribution: cfunif\(t, min = 0, max = 1\)) -endobj -81 0 obj -<< /S /GoTo /D (subsection.2.18) >> -endobj -84 0 obj -(2.18 Weibull Distribution: cfweibull\(t, shape, scale = 1\)) -endobj -85 0 obj -<< /S /GoTo /D (subsection.2.19) >> -endobj -88 0 obj -(2.19 Wilcoxon Rank Sum Distribution: cfwilcox\(t, m, n\)) -endobj -89 0 obj -<< /S /GoTo /D (section.3) >> -endobj -92 0 obj -(3 R Session information) -endobj -93 0 obj -<< /S /GoTo /D [94 0 R /FitH ] >> -endobj -118 0 obj << -/Length 1649 -/Filter /FlateDecode ->> -stream -x???Is?6????????Kgzh?????I??!???iEcIL(?u???@4$?"efj;???{+H??2????????I??(?a?k?Oa?c?&??18b\???t6??"??]?&?I?t{?h??&? ??????@??;??`n?j?K;??Y??nL?7cFZT???U?????Y?w????????B??? ?}???????r#??Rs???`7????\??H?0]?ynL?`?'??-???p~;%R??o?U?ZG?A??Z???*UK?W,FB? q)R??????m[??)???kT??>n? q???8??1????1??_[???????????Bh[o??"??l??7????&?)?y?Y?;??\????H7? -?F???d?Z???)???+#I???W+???"??_???K??n? I??A?`Rp?G??1 ????y)d??< ?[*4??%? -?????h??l ?7?s^???p?K? &l?>e;?????t??\O?>?6K?"?2??)????AH$ -?I+?3l??"?uhp_?#r?????29??.?k??Wal:5?a?????~??|+ODj??????[{?? C?>H?g??2"4,??????i???? ?0???t)???0C???$=?m0?M>]???rx??????Cky4?>1?.6=9O=8>?#? )i??G??'?U#?z????z9???@ ?R!??Y'?/w?t??{5CD???{???NJ?T???????.??q U?,???V??Q?Hj%ub?GVBZ???n?????'TH?V??7?NO??6[??w:p??Ug?!$?B?????=Z+1)?K?{?_?Y??m?1Jg???? -8,?w?Y???H?W?{+R???\@??XV/??? ???,??????4?P?+w?ua?n?6??????@???y???{?????*???? ?$?2"i???????+?2b?????qo? -???& ?B9c???I? ^?x$dx_????J????mJV69y?|?4??V??m?TD??~[?????!???nPSJ?6???;?????W??"CQ? -endstream -endobj -94 0 obj << -/Type /Page -/Contents 118 0 R -/Resources 117 0 R -/MediaBox [0 0 612 792] -/Parent 131 0 R -/Annots [ 95 0 R 96 0 R 97 0 R 98 0 R 99 0 R 100 0 R 101 0 R 102 0 R 103 0 R 104 0 R 105 0 R 106 0 R 107 0 R 108 0 R 109 0 R 110 0 R 111 0 R 112 0 R 113 0 R 114 0 R 115 0 R 116 0 R ] ->> endobj -95 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [71.004 526.215 151.033 535.082] -/Subtype /Link -/A << /S /GoTo /D (section.1) >> ->> endobj -96 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [71.004 498.32 207.67 507.186] -/Subtype /Link -/A << /S /GoTo /D (section.2) >> ->> endobj -97 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 478.175 370.1 489.293] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.1) >> ->> endobj -98 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 460.242 326.255 471.361] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.2) >> ->> endobj -99 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 442.31 394.658 453.428] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.3) >> ->> endobj -100 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 424.377 341.228 435.495] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.4) >> ->> endobj -101 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 406.444 320.705 417.562] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.5) >> ->> endobj -102 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 388.511 349.198 399.63] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.6) >> ->> endobj -103 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 370.579 433.204 381.697] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.7) >> ->> endobj -104 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 352.646 297.542 363.764] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.8) >> ->> endobj -105 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 334.713 342.433 345.831] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.9) >> ->> endobj -106 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 316.78 390.992 327.899] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.10) >> ->> endobj -107 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 298.848 398.484 309.966] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.11) >> ->> endobj -108 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 280.915 395.634 292.033] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.12) >> ->> endobj -109 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 263.819 347.694 274.1] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.13) >> ->> endobj -110 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 245.049 295.709 256.168] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.14) >> ->> endobj -111 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 227.117 357.009 238.235] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.15) >> ->> endobj -112 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 209.184 300.263 220.302] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.16) >> ->> endobj -113 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 192.088 403.883 202.369] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.17) >> ->> endobj -114 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 173.318 364.132 184.437] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.18) >> ->> endobj -115 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [85.948 156.223 352.835 166.504] -/Subtype /Link -/A << /S /GoTo /D (subsection.2.19) >> ->> endobj -116 0 obj << -/Type /Annot -/Border[0 0 0]/H/I/C[1 0 0] -/Rect [71.004 129.702 196.731 138.608] -/Subtype /Link -/A << /S /GoTo /D (section.3) >> ->> endobj -119 0 obj << -/D [94 0 R /XYZ 72 744.907 null] ->> endobj -120 0 obj << -/D [94 0 R /XYZ 72 720 null] ->> endobj -125 0 obj << -/D [94 0 R /XYZ 72 545.254 null] ->> endobj -117 0 obj << -/Font << /F64 121 0 R /F69 122 0 R /F20 123 0 R /F74 124 0 R /F79 126 0 R /F8 127 0 R /F86 128 0 R /F11 129 0 R /F87 130 0 R >> -/ProcSet [ /PDF /Text ] ->> endobj -140 0 obj << -/Length 3695 -/Filter /FlateDecode ->> -stream -x??[Y??~?_??p??xp?`$?!v,WRI?bm?\e??Kr??Wxx????H??u?r?b0??F???`????|U??77W_?m?@???Fn?????j?n?????z?????^??????nW??\N???x\??_n???[????? -??#?V??y?Y3x????Z???)??? ?6?????^Lp????6???p?%???v5?S??????_k?pu????E+!??j???vnH ????? ?J??????@???c1???3a A?N?????(J8??[??Sa??o*kP[])??~?M#S?ASu??8?U??????;?Y[9??~??x]Sy?'?????u>?g????L?=QF[)?~wL?????YA2[Y??? -x??X?Y???z0J&??i6???????V?M?+??=?????W ????Y?? -?K?*Lxu????????~6?0#?????e?zJ??Nl?]#???F?/? -?? 6\?#zS??E???d??|z????????? o?????6 $Y??>?*N?o ????4??| -?!??=?8?vH??+t"?Er??1o? -J???v??y7|???'61???P?NQ? ?jf vX3?????x???4?1?!?YD?y?!?PZl?? ?[u????j~??.Scs?F???R??'???D@"???X?PG???`???#??????#PK??{??+nA????`:???8D??,??3???P???R? -?h?????@?Vnq?~!???J+A??4?[!?A?$?tba?9I -B???? S???=??ME[/?Y???Jw?]5???~yr2??^8_?G -A?7f?n????????p???+ rV(?8=M? -??=?ypA?AN?f?8I&?*Z???f????8c?o3??#G$??????-?3??D??d???.??U?a???>E^/F????????_tu(D AyV??v?T6 9??v?a??*?[6%$??? "BKs 1??5????N??W????=%?e??t9O)Bg&??1?i???l?J?????????"?",?R???\??Z???T]L4U]??????u?????&v????~???{?a??0`???fY??J?;?z??k??kd??V|?]_Q?f?# ??,)}? ?7???7c&???????'O!???ut?o??Z?7L??B?\??Vn? ??B??? ??????1???T?8(?2 ???????0N ` ????r??p*?u?J!?IC ??$-???Y?!???!?$??X?ZW????????\?C??o?3O?I??T]?7rA???1F?c??:oC?????p???%?&6?????LM}??w2?e8?V cn?S [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/prob -r 41 From noreply at r-forge.r-project.org Sun Oct 27 23:08:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 27 Oct 2013 23:08:18 +0100 (CET) Subject: [Prob-commits] r42 - pkg/vignettes Message-ID: <20131027220818.69CB41862D8@r-forge.r-project.org> Author: gkerns Date: 2013-10-27 23:08:18 +0100 (Sun, 27 Oct 2013) New Revision: 42 Modified: pkg/vignettes/prob.Rnw Log: fixed the vignette Modified: pkg/vignettes/prob.Rnw =================================================================== --- pkg/vignettes/prob.Rnw 2013-10-27 21:27:03 UTC (rev 41) +++ pkg/vignettes/prob.Rnw 2013-10-27 22:08:18 UTC (rev 42) @@ -51,101 +51,216 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Preliminaries} -This document is designed to get a person up and running doing elementary probability in \texttt{R} using the \texttt{prob} package. In addition to \texttt{prob}, you will want to install the \texttt{combinat} package in order to use a couple of functions, but other than that a base installation of \texttt{R} should be more than enough. +This document is designed to get a person up and running doing +elementary probability in \texttt{R} using the \texttt{prob} package. +In addition to \texttt{prob}, you will want to install the +\texttt{combinat} package in order to use a couple of functions, but +other than that a base installation of \texttt{R} should be more than +enough. -The prerequisites are minimal. The term ``data frame'' should ring a bell, along with some common tricks like using \texttt{1:6} to represent the integers from 1 to 6. That being said, please note that this document is not a treatise on probability. The reader should have a passing familiarity with the basic tenets of probability and some of the topics that are customarily studied to be able to follow along. +The prerequisites are minimal. The term ``data frame'' should ring a +bell, along with some common tricks like using \texttt{1:6} to +represent the integers from 1 to 6. That being said, please note that +this document is not a treatise on probability. The reader should +have a passing familiarity with the basic tenets of probability and +some of the topics that are customarily studied to be able to follow +along. -In the interest of space, most of the examples described below are uncharacteristically small and do not fully showcase the true computational power of \texttt{R}. Nevertheless, the goal is for these small examples to serve as a starting point from which users can investigate more complicated problems at their leisure. +In the interest of space, most of the examples described below are +uncharacteristically small and do not fully showcase the true +computational power of \texttt{R}. Nevertheless, the goal is for +these small examples to serve as a starting point from which users can +investigate more complicated problems at their leisure. \section{Sample Spaces} -The first step is to set up a \emph{sample space}, or set of possible outcomes of an experiment. In the \texttt{prob} package, the most simple form of a sample space is represented by a \emph{data frame}, that is, a rectangular collection of variables. Each row of the data frame corresponds to an outcome of the experiment. +The first step is to set up a \emph{sample space}, or set of possible +outcomes of an experiment. In the \texttt{prob} package, the most +simple form of a sample space is represented by a \emph{data frame}, +that is, a rectangular collection of variables. Each row of the data +frame corresponds to an outcome of the experiment. -This is the primary way we will represent a sample space, both due to its simplicity and to maximize compatibility with the R Commander by John Fox. However, this structure is not rich enough to describe some of the more interesting probabilistic applications we will encounter. To handle these we will need to consider the more general \emph{list} data structure. See the last section for some remarks in this direction. +This is the primary way we will represent a sample space, both due to +its simplicity and to maximize compatibility with the R Commander by +John Fox. However, this structure is not rich enough to describe some +of the more interesting probabilistic applications we will encounter. +To handle these we will need to consider the more general \emph{list} +data structure. See the last section for some remarks in this +direction. -Note that the machinery doing the work to generate most of the sample spaces below is the \texttt{expand.grid()} function in the \texttt{base} package, also \texttt{combn()} in \texttt{combinat} and new but related \texttt{permsn()}. +Note that the machinery doing the work to generate most of the sample +spaces below is the \texttt{expand.grid()} function in the +\texttt{base} package, also \texttt{combn()} in \texttt{combinat} and +new but related \texttt{permsn()}. \subsection{Some Standard Sample Spaces} -The \texttt{prob} package has some functions to get one started. For example, consider the experiment of tossing a coin. The outcomes are $H$ and $T$. We can set up the sample space quicky with the \texttt{tosscoin()} function: +The \texttt{prob} package has some functions to get one started. For +example, consider the experiment of tossing a coin. The outcomes are +$H$ and $T$. We can set up the sample space quicky with the +\texttt{tosscoin()} function: <>= tosscoin(1) @ -The number 1 tells \texttt{tosscoin()} that we only want to toss the coin once. We could toss it three times: +The number 1 tells \texttt{tosscoin()} that we only want to toss the +coin once. We could toss it three times: <>= tosscoin(3) @ % -As an alternative, we could consider the experiment of rolling a fair die: +As an alternative, we could consider the experiment of rolling a fair +die: % <>= rolldie(1) @ -The \texttt{rolldie()} function defaults to a 6-sided die, but we can change it with the \texttt{nsides} argument. Typing \texttt{rolldie(3, nsides = 4)} would be for rolling a 4-sided die three times. +The \texttt{rolldie()} function defaults to a 6-sided die, but we can +change it with the \texttt{nsides} argument. Typing +\texttt{rolldie(3, nsides = 4)} would be for rolling a 4-sided die +three times. -Perhaps we would like to draw one card from a standard set of playing cards (it is a long data frame): +Perhaps we would like to draw one card from a standard set of playing +cards (it is a long data frame): <>= cards() @ -The \texttt{cards()} function that we just used has arguments \texttt{jokers} (if you would like Jokers to be in the deck) and \texttt{makespace} which we will discuss later. +The \texttt{cards()} function that we just used has arguments +\texttt{jokers} (if you would like Jokers to be in the deck) and +\texttt{makespace} which we will discuss later. -Additionally, the \texttt{roulette()} function gives the standard sample space for one spin on a roulette wheel. There are EU and USA versions available. I would appreciate hearing about any other game or sample spaces that may be of general interest. +Additionally, the \texttt{roulette()} function gives the standard +sample space for one spin on a roulette wheel. There are EU and USA +versions available. I would appreciate hearing about any other game +or sample spaces that may be of general interest. \subsection{Sampling from Urns} -Perhaps the most fundamental of statistical experiments consists of drawing distinguishable objects from an urn. The \texttt{prob} package addresses this topic with the \texttt{urnsamples(x, size, replace, ordered)} function. The argument \texttt{x} represents the urn from which sampling is to be done. The \texttt{size} argument tells how large the sample will be. The \texttt{ordered} and \texttt{replace} arguments are logical and specify how sampling will be performed. We will discuss each in turn. In the interest of saving space, for this example let our urn simply contain three balls, labeled 1, 2, and 3, respectively. We are going to take a sample of size 2. +Perhaps the most fundamental of statistical experiments consists of +drawing distinguishable objects from an urn. The \texttt{prob} +package addresses this topic with the \texttt{urnsamples(x, size, + replace, ordered)} function. The argument \texttt{x} represents the +urn from which sampling is to be done. The \texttt{size} argument +tells how large the sample will be. The \texttt{ordered} and +\texttt{replace} arguments are logical and specify how sampling will +be performed. We will discuss each in turn. In the interest of saving +space, for this example let our urn simply contain three balls, +labeled 1, 2, and 3, respectively. We are going to take a sample of +size 2. \subsubsection*{Ordered, With Replacement} -If sampling is with replacement, then we can get any outcome $1,2,3$ on any draw. Further, by ``ordered'' we mean that we shall keep track of the order of the draws that we observe. We can accomplish this in \texttt{R} with +If sampling is with replacement, then we can get any outcome $1,2,3$ +on any draw. Further, by ``ordered'' we mean that we shall keep track +of the order of the draws that we observe. We can accomplish this in +\texttt{R} with <>= urnsamples(1:3, size = 2, replace = TRUE, ordered = TRUE) -@ -Notice that rows 2 and 4 are identical, save for the order in which the numbers are shown. Further, note that every possible pair of the numbers 1 through 3 are listed. This experiment is equivalent to rolling a 3-sided die twice, which we could have accomplished with \texttt{rolldie(2, nsides = 3)}. +@ +Notice that rows 2 and 4 are identical, save for the order in which +the numbers are shown. Further, note that every possible pair of the +numbers 1 through 3 are listed. This experiment is equivalent to +rolling a 3-sided die twice, which we could have accomplished with +\texttt{rolldie(2, nsides = 3)}. + \subsubsection*{Ordered, Without Replacement} -Here sampling is without replacement, so we may not observe the same number twice in any row. Order is still important, however, so we expect to see the outcomes \texttt{1}, \texttt{2} and \texttt{2}, \texttt{1} somewhere in our data frame as before. +Here sampling is without replacement, so we may not observe the same +number twice in any row. Order is still important, however, so we +expect to see the outcomes \texttt{1}, \texttt{2} and \texttt{2}, +\texttt{1} somewhere in our data frame as before. <>= urnsamples(1:3, size = 2, replace = FALSE, ordered = TRUE) -@ -This is just as we expected. Notice that there are less rows in this answer, due to the restricted sampling procedure. If the numbers 1, 2, and 3 represented ``Fred'', ``Mary'', and ``Sue'', respectively, then this experiment would be equivalent to selecting two people of the three to serve as president and vice-president of a company, respectively, and the sample space lists all possible ways that this could be done. +@ +This is just as we expected. Notice that there are less rows in +this answer, due to the restricted sampling procedure. If the numbers +1, 2, and 3 represented ``Fred'', ``Mary'', and ``Sue'', respectively, +then this experiment would be equivalent to selecting two people of +the three to serve as president and vice-president of a company, +respectively, and the sample space lists all possible ways that this +could be done. \subsubsection*{Unordered, Without Replacement} -Again, we may not observe the same outcome twice, but in this case, we will only keep those outcomes which (when jumbled) would not duplicate earlier ones. +Again, we may not observe the same outcome twice, but in this case, we +will only keep those outcomes which (when jumbled) would not duplicate +earlier ones. <>= urnsamples(1:3, size = 2, replace = FALSE, ordered = FALSE) @ -This experiment is equivalent to reaching in the urn, picking a pair, and looking to see what they are. This is the default setting of \texttt{urnsamples()}, so we would have received the same output by simply typing \texttt{urnsamples(1:3,2)}. +This experiment is equivalent to reaching in the urn, picking a pair, +and looking to see what they are. This is the default setting of +\texttt{urnsamples()}, so we would have received the same output by +simply typing \texttt{urnsamples(1:3,2)}. + \subsubsection*{Unordered, With Replacement} -The last possibility is perhaps the most interesting. We replace the balls after every draw, but we do not remember the order in which the draws come. +The last possibility is perhaps the most interesting. We replace the +balls after every draw, but we do not remember the order in which the +draws come. <>= urnsamples(1:3, size = 2, replace = TRUE, ordered = FALSE) @ -We may interpret this experiment in a number of alternative ways. One way is to consider this as simply putting two 3-sided dice in a cup, shaking the cup, and looking inside as in a game of Liar's Dice, for instance. Each row of the sample space is a potential pair we could observe. Another equivalent view is to consider each outcome a separate way to distribute two identical golf balls into three boxes labeled 1, 2, and 3. Regardless of the interpretation, \texttt{urnsamples()} lists every possible way that the experiment can conclude. -Note that the urn does not need to contain numbers; we could have just as easily taken our urn to be \texttt{x = c("Red", "Blue", "Green")}. But, there is an \textbf{important} point to mention before proceeding. Astute readers will notice that in our example, the balls in the urn were \textit{distinguishable} in the sense that each had a unique label to distinguish it from the others in the urn. A natural question would be, ``What happens if your urn has indistinguishable elements, for example, what if \texttt{x = c("Red", "Red", "Blue")}?'' The answer is that \texttt{urnsamples()} behaves as if each ball in the urn is distinguishable, regardless of its actual contents. We may thus imagine that while there are two red balls in the urn, the balls are such that we can tell them apart (in principle) by looking closely enough at the imperfections on their surface. +We may interpret this experiment in a number of alternative ways. One +way is to consider this as simply putting two 3-sided dice in a cup, +shaking the cup, and looking inside as in a game of Liar's Dice, for +instance. Each row of the sample space is a potential pair we could +observe. Another equivalent view is to consider each outcome a +separate way to distribute two identical golf balls into three boxes +labeled 1, 2, and 3. Regardless of the interpretation, +\texttt{urnsamples()} lists every possible way that the experiment can +conclude. -In this way, when the \texttt{x} argument of \texttt{urnsamples()} has repeated elements, the resulting sample space may appear to be \texttt{ordered = TRUE} even when, in fact, the call to the function was \texttt{urnsamples(..., ordered = FALSE)}. Similar remarks apply for the \texttt{replace} argument. We investigate this issue further in the last section. +Note that the urn does not need to contain numbers; we could have just +as easily taken our urn to be \texttt{x <- c("Red", "Blue", "Green")}. +But, there is an \textbf{important} point to mention before +proceeding. Astute readers will notice that in our example, the balls +in the urn were \textit{distinguishable} in the sense that each had a +unique label to distinguish it from the others in the urn. A natural +question would be, ``What happens if your urn has indistinguishable +elements, for example, what if \texttt{x <- c("Red", "Red", "Blue")}?'' +The answer is that \texttt{urnsamples()} behaves as if each ball in +the urn is distinguishable, regardless of its actual contents. We may +thus imagine that while there are two red balls in the urn, the balls +are such that we can tell them apart (in principle) by looking closely +enough at the imperfections on their surface. +In this way, when the \texttt{x} argument of \texttt{urnsamples()} has +repeated elements, the resulting sample space may appear to be +\texttt{ordered = TRUE} even when, in fact, the call to the function +was \texttt{urnsamples(..., ordered = FALSE)}. Similar remarks apply +for the \texttt{replace} argument. We investigate this issue further +in the last section. - - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Counting Tools} -The sample spaces we have seen so far have been relatively small, and we can visually study them without much trouble. However, it is VERY easy to generate sample spaces that are prohibitively large. And while \texttt{R} is wonderful and powerful and does almost everything except wash windows, even \texttt{R} has limits of which we should be mindful. +The sample spaces we have seen so far have been relatively small, and +we can visually study them without much trouble. However, it is VERY +easy to generate sample spaces that are prohibitively large. And +while \texttt{R} is wonderful and powerful and does almost everything +except wash windows, even \texttt{R} has limits of which we should be +mindful. -In many cases, we do not need to actually generate the sample spaces of interest; it suffices merely to count the number of outcomes. The \texttt{nsamp()} function will calculate the number of rows in a sample space made by \texttt{urnsamples()}, without actually devoting the memory resources necessary to generate the space. The arguments are: \texttt{n}, the number of (distinguishable) objects in the urn, \texttt{k}, the sample size, and \texttt{replace}, \texttt{ordered} as above. +In many cases, we do not need to actually generate the sample spaces +of interest; it suffices merely to count the number of outcomes. The +\texttt{nsamp()} function will calculate the number of rows in a +sample space made by \texttt{urnsamples()}, without actually devoting +the memory resources necessary to generate the space. The arguments +are: \texttt{n}, the number of (distinguishable) objects in the urn, +\texttt{k}, the sample size, and \texttt{replace}, \texttt{ordered} as +above. -In a probability course, one derives the formulas used in the respective scenarios. For our purposes, it is sufficient to merely list them in the following table. Note that $x!=x(x-1)(x-2)\cdots3\cdot2\cdot1$ and ${n \choose k}=n!/[k!(n-k)!]$. +In a probability course, one derives the formulas used in the +respective scenarios. For our purposes, it is sufficient to merely +list them in the following table. Note that +$x!=x(x-1)(x-2)\cdots3\cdot2\cdot1$ and ${n \choose k}=n!/[k!(n-k)!]$. \begin{center} \textbf{Values of \texttt{nsamp(n, k, replace, ordered)}} @@ -165,128 +280,272 @@ \subsubsection*{Examples} -We will compute the number of outcomes for each of the four \texttt{urnsamples()} examples that we saw in the last section. Recall that we took a sample of size two from an urn with three distinguishable elements. +We will compute the number of outcomes for each of the four +\texttt{urnsamples()} examples that we saw in the last section. +Recall that we took a sample of size two from an urn with three +distinguishable elements. <>= nsamp(n=3, k=2, replace = TRUE, ordered = TRUE) nsamp(n=3, k=2, replace = FALSE, ordered = TRUE) nsamp(n=3, k=2, replace = FALSE, ordered = FALSE) nsamp(n=3, k=2, replace = TRUE, ordered = FALSE) @ -Compare these answers with the length of the data frames generated above. +Compare these answers with the length of the data frames generated +above. + \subsection{The Multiplication Principle} -A benefit of \texttt{nsamp()} is that it is \emph{vectorized}, so that entering vectors instead of numbers for \texttt{n}, \texttt{k}, \texttt{replace}, and \texttt{ordered} results in a vector of corresponding answers. This becomes particularly convenient when trying to demonstrate the Multiplication Principle for solving combinatorics problems. +A benefit of \texttt{nsamp()} is that it is \emph{vectorized}, so that +entering vectors instead of numbers for \texttt{n}, \texttt{k}, +\texttt{replace}, and \texttt{ordered} results in a vector of +corresponding answers. This becomes particularly convenient when +trying to demonstrate the Multiplication Principle for solving +combinatorics problems. \subsubsection*{Example} -Question: There are 11 artists who each submit a portfolio containing 7 paintings for competition in an art exhibition. Unfortunately, the gallery director only has space in the winners' section to accomodate 12 paintings in a row equally spread over three consecutive walls. The director decides to give the first, second, and third place winners each a wall to display the work of their choice. The walls boast 31 separate lighting options apiece. How many displays are possible? +Question: There are 11 artists who each submit a portfolio containing +7 paintings for competition in an art exhibition. Unfortunately, the +gallery director only has space in the winners' section to accomodate +12 paintings in a row equally spread over three consecutive walls. +The director decides to give the first, second, and third place +winners each a wall to display the work of their choice. The walls +boast 31 separate lighting options apiece. How many displays are +possible? -Answer: The judges will pick 3 (ranked) winners out of 11 (with \texttt{rep=FALSE}, \texttt{ord=TRUE}). Each artist will select 4 of his/her paintings from 7 for display in a row (\texttt{rep=FALSE}, \texttt{ord=TRUE}), and lastly, each of the 3 walls has 31 lighting possibilities (\texttt{rep=TRUE}, \texttt{ord=TRUE}). These three numbers can be calculated quickly with +Answer: The judges will pick 3 (ranked) winners out of 11 (with +\texttt{rep=FALSE}, \texttt{ord=TRUE}). Each artist will select 4 of +his/her paintings from 7 for display in a row (\texttt{rep=FALSE}, +\texttt{ord=TRUE}), and lastly, each of the 3 walls has 31 lighting +possibilities (\texttt{rep=TRUE}, \texttt{ord=TRUE}). These three +numbers can be calculated quickly with <>= -n = c(11,7,31) -k = c(3,4,3) -r = c(FALSE,FALSE,TRUE) +n <- c(11, 7, 31) +k <- c(3, 4, 3) +r <- c(FALSE,FALSE,TRUE) @ + <>= -x = nsamp(n, k, rep = r, ord = TRUE) +x <- nsamp(n, k, rep = r, ord = TRUE) @ -(Notice that \texttt{ordered} is always \texttt{TRUE}; \texttt{nsamp()} will recycle \texttt{ordered} and \texttt{replace} to the appropriate length.) By the Multiplication Principle, the number of ways to complete the experiment is the product of the entries of \texttt{x}: + +(Notice that \texttt{ordered} is always \texttt{TRUE}; +\texttt{nsamp()} will recycle \texttt{ordered} and \texttt{replace} to +the appropriate length.) By the Multiplication Principle, the number +of ways to complete the experiment is the product of the entries of +\texttt{x}: <>= prod(x) @ + Compare this with the some standard ways to compute this in \texttt{R}: <>= (11*10*9)*(7*6*5*4)*31^3 @ + or alternatively <>= prod(9:11)*prod(4:7)*31^3 @ + or even <>= prod(factorial(c(11,7))/factorial(c(8,3)))*31^3 @ -As one can guess, in many of the standard counting problems there aren't much savings in the amount of typing; it is about the same using \texttt{nsamp()} versus \texttt{factorial()} and \texttt{choose()}. But the virtue of \texttt{nsamp()} lies in its collecting the relevant counting formulas in a one-stop shop. Ultimately, it is up to the user to choose the method that works best for him/herself. -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +As one can guess, in many of the standard counting problems there +aren't much savings in the amount of typing; it is about the same +using \texttt{nsamp()} versus \texttt{factorial()} and +\texttt{choose()}. But the virtue of \texttt{nsamp()} lies in its +collecting the relevant counting formulas in a one-stop shop. +Ultimately, it is up to the user to choose the method that works best +for him/herself. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Defining a Probability Space} -Once a sample space is defined, the next step is to associate a probability model with it in order to be able to answer probabilistic questions. Formally speaking, a \textit{probability space} is a triple $(S,\mathscr{B},\P)$, where $S$ is a sample space, $\mathscr{B}$ is a sigma-algebra of subsets of $S$, and $\P$ is a probability measure defined on $\mathscr{B}$. However, for our purposes all of the sample spaces are finite, so we may take $\mathscr{B}$ to be the power set (the set of all subsets of $S$) and it suffices to specify $\P$ on the elements of $S$, the outcomes. The only requirement for $\P$ is that its values should be nonnegative and sum to 1. +Once a sample space is defined, the next step is to associate a +probability model with it in order to be able to answer probabilistic +questions. Formally speaking, a \textit{probability space} is a +triple $(S,\mathscr{B},\P)$, where $S$ is a sample space, +$\mathscr{B}$ is a sigma-algebra of subsets of $S$, and $\P$ is a +probability measure defined on $\mathscr{B}$. However, for our +purposes all of the sample spaces are finite, so we may take +$\mathscr{B}$ to be the power set (the set of all subsets of $S$) and +it suffices to specify $\P$ on the elements of $S$, the outcomes. The +only requirement for $\P$ is that its values should be nonnegative and +sum to 1. -The end result is that in the \texttt{prob} package, a probability space is an object of outcomes \texttt{S} and a vector of probabilities (called ``\texttt{probs}'') with entries that correspond to each outcome in \texttt{S}. When \texttt{S} is a data frame, we may simply add a column called \texttt{probs} to \texttt{S} and we will be finished; the probability space will simply be a data frame which we may call \texttt{space}. In the case that \text{S} is a list, we may combine the \texttt{outcomes} and \texttt{probs} into a larger list, \texttt{space}; it will have two components: \texttt{outcomes} and \texttt{probs}. The only requirement we place is that the entries of \texttt{probs} be nonnegative and \texttt{sum(probs)} is one. +The end result is that in the \texttt{prob} package, a probability +space is an object of outcomes \texttt{S} and a vector of +probabilities (called ``\texttt{probs}'') with entries that correspond +to each outcome in \texttt{S}. When \texttt{S} is a data frame, we +may simply add a column called \texttt{probs} to \texttt{S} and we +will be finished; the probability space will simply be a data frame +which we may call \texttt{space}. In the case that \text{S} is a +list, we may combine the \texttt{outcomes} and \texttt{probs} into a +larger list, \texttt{space}; it will have two components: +\texttt{outcomes} and \texttt{probs}. The only requirement we place +is that the entries of \texttt{probs} be nonnegative and +\texttt{sum(probs)} is one. -To accomplish this in \texttt{R}, we may use the \texttt{probspace()} function. The general syntax is \texttt{probspace(x, probs)}, where \texttt{x} is a sample space of outcomes and \texttt{probs} is a vector (of the same length as the number of outcomes in \texttt{x}). The specific choice of \texttt{probs} depends on the context of the problem, and some examples follow to demonstrate some of the more common choices. +To accomplish this in \texttt{R}, we may use the \texttt{probspace()} +function. The general syntax is \texttt{probspace(x, probs)}, where +\texttt{x} is a sample space of outcomes and \texttt{probs} is a +vector (of the same length as the number of outcomes in \texttt{x}). +The specific choice of \texttt{probs} depends on the context of the +problem, and some examples follow to demonstrate some of the more +common choices. \subsection{Examples} \subsubsection*{The Equally Likely Model} -The equally likely model asserts that every outcome of the sample space has the same probability, thus, if a sample space has $n$ outcomes, then \texttt{probs} would be a vector of length $n$ with identical entries $1/n$. The quickest way to generate \texttt{probs} is with the \texttt{rep()} function. We will start with the experiment of rolling a die, so that $n=6$. We will construct the sample space, generate the \texttt{probs} vector, and put them together with \texttt{probspace()}. +The equally likely model asserts that every outcome of the sample +space has the same probability, thus, if a sample space has $n$ +outcomes, then \texttt{probs} would be a vector of length $n$ with +identical entries $1/n$. The quickest way to generate \texttt{probs} +is with the \texttt{rep()} function. We will start with the +experiment of rolling a die, so that $n=6$. We will construct the +sample space, generate the \texttt{probs} vector, and put them +together with \texttt{probspace()}. <>= -outcomes = rolldie(1) +outcomes <- rolldie(1) p <- rep(1/6, times = 6) probspace(outcomes, probs = p) @ -The \texttt{probspace()} function is designed to save us some time in many of the most common situations. For example, due to the especial simplicity of the sample space in this case, we could have achieved the same result with simply (note the name change for the first column) + +The \texttt{probspace()} function is designed to save us some time in +many of the most common situations. For example, due to the especial +simplicity of the sample space in this case, we could have achieved +the same result with simply (note the name change for the first +column) <>= probspace(1:6, probs = p) -@ - Further, since the equally likely model plays such a fundamental role in the study of probability, the \texttt{probspace()} function will assume that the equally model is desired if no \texttt{probs} are specified. Thus, we get the same answer with only +@ + +Further, since the equally likely model plays such a fundamental +role in the study of probability, the \texttt{probspace()} function +will assume that the equally model is desired if no \texttt{probs} are +specified. Thus, we get the same answer with only <>= probspace(1:6) @ -And finally, since rolling dice is such a common experiment in probability classes, the \texttt{rolldie()} function has an additional logical argument \texttt{makespace} that will add a column of equally likely \texttt{probs} to the generated sample space: + +And finally, since rolling dice is such a common experiment in +probability classes, the \texttt{rolldie()} function has an additional +logical argument \texttt{makespace} that will add a column of equally +likely \texttt{probs} to the generated sample space: <>= rolldie(1, makespace = TRUE) @ -or just \texttt{rolldie(1:6,TRUE)}. Many of the other sample space functions (\texttt{tosscoin()}, \texttt{cards()}, \texttt{roulette()}, \textit{etc}.) have similar \texttt{makespace} arguments. Check the documentation for details. -One sample space function that does NOT have a \texttt{makespace} option is the \texttt{urnsamples()} function. This was intentional. The reason is that under the varied sampling assumptions the outcomes in the respective sample spaces are NOT, in general, equally likely. It is important for the user to carefully consider the experiment to decide whether or not the outcomes are equally likely, and then use \texttt{probspace()} to assign the model. +or just \texttt{rolldie(1:6,TRUE)}. Many of the other sample space +functions (\texttt{tosscoin()}, \texttt{cards()}, \texttt{roulette()}, +\textit{etc}.) have similar \texttt{makespace} arguments. Check the +documentation for details. +One sample space function that does NOT have a \texttt{makespace} +option is the \texttt{urnsamples()} function. This was intentional. +The reason is that under the varied sampling assumptions the outcomes +in the respective sample spaces are NOT, in general, equally likely. +It is important for the user to carefully consider the experiment to +decide whether or not the outcomes are equally likely, and then use +\texttt{probspace()} to assign the model. + \subsubsection*{An unbalanced coin} -While the \texttt{makespace} argument to \texttt{tosscoin()} is useful to represent the tossing of a \emph{fair} coin, it is not always appropriate. For example, suppose our coin is not perfectly balanced, for instance, maybe the ``$H$'' side is somewhat heavier such that the chances of a $H$ appearing in a single toss is 0.70 instead of 0.5. We may set up the probability space with +While the \texttt{makespace} argument to \texttt{tosscoin()} is useful +to represent the tossing of a \emph{fair} coin, it is not always +appropriate. For example, suppose our coin is not perfectly balanced, +for instance, maybe the ``$H$'' side is somewhat heavier such that the +chances of a $H$ appearing in a single toss is 0.70 instead of 0.5. We +may set up the probability space with <>= [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/prob -r 42 From noreply at r-forge.r-project.org Sun Oct 27 23:29:16 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 27 Oct 2013 23:29:16 +0100 (CET) Subject: [Prob-commits] r43 - in pkg: . R man vignettes Message-ID: <20131027222916.AC36C1862D4@r-forge.r-project.org> Author: gkerns Date: 2013-10-27 23:29:16 +0100 (Sun, 27 Oct 2013) New Revision: 43 Modified: pkg/NAMESPACE pkg/R/prob.r pkg/man/prob.rd pkg/vignettes/prob.Rnw Log: added deprecated version of "prob", changed encoding of prob vignette to UTF-8 Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-10-27 22:08:18 UTC (rev 42) +++ pkg/NAMESPACE 2013-10-27 22:29:16 UTC (rev 43) @@ -2,25 +2,25 @@ export( addrv, -cards, -cfbeta, -cfbinom, -cfcauchy, -cfchisq, -cfexp, -cff, -cfgamma, -cfgeom, -cfhyper, -cflnorm, -cflogis, -cfnbinom, -cfnorm, -cfpois, -cfsignrank, -cft, -cfunif, -cfweibull, +cards, +cfbeta, +cfbinom, +cfcauchy, +cfchisq, +cfexp, +cff, +cfgamma, +cfgeom, +cfhyper, +cflnorm, +cflogis, +cfnbinom, +cfnorm, +cfpois, +cfsignrank, +cft, +cfunif, +cfweibull, cfwilcox, countrep, empirical, @@ -34,6 +34,7 @@ noorder, nsamp, permsn, +prob, Prob, probspace, rolldie, Modified: pkg/R/prob.r =================================================================== --- pkg/R/prob.r 2013-10-27 22:08:18 UTC (rev 42) +++ pkg/R/prob.r 2013-10-27 22:29:16 UTC (rev 43) @@ -2,6 +2,10 @@ `Prob` <- function (x, ...) UseMethod("Prob") +`prob` <- function (x, ...){ + message("'prob' is deprecated; use 'Prob' instead.") + Prob(x, ...) +} `Prob.default` <- function (x, event = NULL, given = NULL, ...){ if (is.null(x$probs)) { Modified: pkg/man/prob.rd =================================================================== --- pkg/man/prob.rd 2013-10-27 22:08:18 UTC (rev 42) +++ pkg/man/prob.rd 2013-10-27 22:29:16 UTC (rev 43) @@ -1,4 +1,5 @@ \name{prob} +\alias{prob} \alias{Prob} \alias{Prob.default} \alias{Prob.ps} Modified: pkg/vignettes/prob.Rnw =================================================================== --- pkg/vignettes/prob.Rnw 2013-10-27 22:08:18 UTC (rev 42) +++ pkg/vignettes/prob.Rnw 2013-10-27 22:29:16 UTC (rev 43) @@ -15,6 +15,7 @@ \usepackage{layout} \usepackage{color} \usepackage{multicol} +\usepackage[utf8]{inputenc} \pagenumbering{roman} \let\myTOC\tableofcontents