diff --git a/README.Rmd b/README.Rmd index 8a694bc..02b9eb2 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,6 +16,9 @@ knitr::opts_chunk$set( # AcceptReject + + +[![R-CMD-check](https://github.com/prdm0/AcceptReject/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/prdm0/AcceptReject/actions/workflows/R-CMD-check.yaml) Generating pseudo-random observations from a probability distribution is a common task in statistics. Being able to generate pseudo-random observations from a probability distribution is useful for simulating scenarios, in [Monte-Carlo](https://en.wikipedia.org/wiki/Monte_Carlo_method) methods, which are useful for evaluating various statistical models. diff --git a/README.md b/README.md index 24223a7..e88008f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ # AcceptReject + + + +[![R-CMD-check](https://github.com/prdm0/AcceptReject/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/prdm0/AcceptReject/actions/workflows/R-CMD-check.yaml) Generating pseudo-random observations from a probability distribution is diff --git a/docs/articles/accept_reject.html b/docs/articles/accept_reject.html index d660b94..e85b75b 100644 --- a/docs/articles/accept_reject.html +++ b/docs/articles/accept_reject.html @@ -547,7 +547,7 @@

Accessing metadata#> $f #> function (x, mean = 0, sd = 1, log = FALSE) #> .Call(C_dnorm, x, mean, sd, log) -#> <bytecode: 0x6297c4a52470> +#> <bytecode: 0x5d31bdbbca78> #> <environment: namespace:stats> #> #> $args_f diff --git a/docs/index.html b/docs/index.html index 117ca86..d2f8406 100644 --- a/docs/index.html +++ b/docs/index.html @@ -79,7 +79,9 @@

- + + +

Generating pseudo-random observations from a probability distribution is a common task in statistics. Being able to generate pseudo-random observations from a probability distribution is useful for simulating scenarios, in Monte-Carlo methods, which are useful for evaluating various statistical models.

The inversion method is a common way to do this, but it is not always possible to find a closed-form formula for the inverse function of the cumulative distribution function of a random variable X, that is, q(u) = F−1(u) = x (quantile function), where F is the cumulative distribution function of X and u is a uniformly distributed random variable in the interval (0,1).

Whenever possible, it is preferable to use the inversion method to generate pseudo-random observations from a probability distribution. However, when it is not possible to find a closed-form formula for the inverse function of the cumulative distribution function of a random variable, it is necessary to resort to other methods. One way to do this is through the acceptance-rejection method, which is a Monte-Carlo procedure. This package aims to provide a function that implements the Acceptance and Rejection method for generating pseudo-random observations from probability distributions that are difficult to sample directly.

@@ -195,7 +197,12 @@

Developers

- +
+

Dev status

+ +
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index ccdaeeb..2b75459 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,5 +3,5 @@ pkgdown: 2.0.7 pkgdown_sha: ~ articles: accept_reject: accept_reject.html -last_built: 2024-04-11T12:18Z +last_built: 2024-04-11T12:57Z diff --git a/docs/reference/figures/README-unnamed-chunk-2-1.png b/docs/reference/figures/README-unnamed-chunk-2-1.png index 205f717..d2bafc1 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-2-1.png and b/docs/reference/figures/README-unnamed-chunk-2-1.png differ diff --git a/docs/reference/figures/README-unnamed-chunk-3-1.png b/docs/reference/figures/README-unnamed-chunk-3-1.png index cf831ce..d35c290 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-3-1.png and b/docs/reference/figures/README-unnamed-chunk-3-1.png differ diff --git a/docs/search.json b/docs/search.json index 7eaaf52..9dc48b5 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" 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 3 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, see . Copyright (C) This program 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."},{"path":"/articles/accept_reject.html","id":"understanding-the-method","dir":"Articles","previous_headings":"","what":"Understanding the Method","title":"Acceptance and rejection method","text":"situations use inversion method (situations obtaining quantile function possible) neither know transformation involving random variable can generate observations, can make use acceptance-rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. Furthermore, suppose exists constant \\(c\\) \\[\\frac{f(x)}{g(y)} \\leq c,\\] every value \\(x\\), \\(f(x) > 0\\). use acceptance-rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Important: important chosen random variable \\(Y\\) can easily generate observations. acceptance-rejection method computationally intensive direct methods transformation method inversion method, requires generation pseudo-random numbers uniform distribution. Algorithm Acceptance-Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) go back step 1. Proof: Consider discrete case, , \\(X\\) \\(Y\\) random variables pfs \\(f\\) \\(g\\), respectively. step 3 algorithm , \\(\\{accept\\} = \\{x = y\\} = u < \\frac{f(y)}{cg(y)}\\). , \\[P(accept | Y = y) = \\frac{P(accept \\cap \\{Y = y\\})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\] Hence, Law Total Probability, : \\[P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\] Therefore, acceptance-rejection method, accept occurrence \\(Y\\) occurrence \\(X\\) probability \\(1/c\\). Moreover, Bayes’ Theorem, \\[P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\] result shows accepting \\(x = y\\) algorithm’s procedure equivalent accepting value \\(X\\) pf \\(f\\). continuous case, proof similar. Important: Notice reduce computational cost method, choose \\(c\\) way can maximize \\(P(accept)\\). Therefore, choosing excessively large value constant \\(c\\) reduce probability accepting observation \\(Y\\) observation random variable \\(X\\). Note: Computationally, convenient consider \\(Y\\) random variable uniform distribution support \\(f\\), since generating observations uniform distribution straightforward computer. discrete case, considering \\(Y\\) discrete uniform distribution might good alternative.","code":""},{"path":"/articles/accept_reject.html","id":"installation-and-loading-the-package","dir":"Articles","previous_headings":"","what":"Installation and loading the package","title":"Acceptance and rejection method","text":"AcceptReject package available CRAN can installed using following command:","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/articles/accept_reject.html","id":"using-the-accept_reject-function","dir":"Articles","previous_headings":"Installation and loading the package","what":"Using the accept_reject Function","title":"Acceptance and rejection method","text":"Among various functions provided AcceptReject library, acceptance_rejection function implements acceptance-rejection method. AcceptReject::accept_reject() function following signature: Many arguments user need change, AcceptReject::accept_reject() function already default values . However, important note f argument probability density function (pdf) probability function (pf) random variable \\(X\\) observations desired generated. args_f argument list arguments passed f function. c argument value constant c used acceptance-rejection method. user provide value c, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). Note: need define c argument using AcceptReject::accept_reject() function. default, c = NULL, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). However, want set value c, simply pass value c argument. Details optimization c: arguments linesearch_algorithm, max_iterations, epsilon, start_c, ... arguments control optimization algorithm c value. linesearch_algorithm argument line search algorithm used optimization c value. max_iterations argument maximum number iterations optimization algorithm perform. epsilon argument stopping criterion optimization algorithm. start_c argument initial value c used optimization algorithm. arguments passed lbfgs::lbfgs() function, generally, need change .","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/articles/accept_reject.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"Acceptance and rejection method","text":"examples using AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. noted case \\(X\\) discrete random variable, necessary provide argument continuous = FALSE, whereas case \\(X\\) continuous (default), must consider continuous = TRUE.","code":""},{"path":"/articles/accept_reject.html","id":"generating-discrete-observations","dir":"Articles","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance and rejection method","text":"example, let \\(X \\sim Poisson(\\lambda = 0.7)\\). generate \\(n = 1000\\) observations \\(X\\) using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability \\(X\\) assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}). Note necessary specify nature random variable observations desired generated. case discrete variables, argument continuous = FALSE must passed. Now, consider want generate observations random variable \\(X \\sim Binomial(n = 5, p = 0.7)\\). , generate \\(n = 2000\\) observations \\(X\\).","code":"library(AcceptReject) # Ensuring Reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 1000 #> ✔ c: 10.4282913773332 #> ✔ Probability of acceptance (1/c): 0.0958929860910474 #> ✔ Observations: 0 0 0 0 1 0 0 2 1 2... #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dpois(values, lambda = 0.7) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid() library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 2000 #> ✔ c: 6.56249999733451 #> ✔ Probability of acceptance (1/c): 0.152380952442845 #> ✔ Observations: 3 4 4 2 3 1 2 4 2 2... #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dbinom(values, size = 5, prob = 0.5) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid()"},{"path":"/articles/accept_reject.html","id":"generating-continuous-observations","dir":"Articles","previous_headings":"Examples","what":"Generating continuous observations","title":"Acceptance and rejection method","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable \\(X \\sim \\mathcal{N}(\\mu = 0, \\sigma^2 = 1)\\). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. examples , graphs built without using AcceptReject::plot() function. just show can manipulate returning object using AcceptReject::accept_reject() function, , class object accept_reject. However, AcceptReject::plot() function can used generate graphs simpler way. , example use AcceptReject::plot() function generate probability density plot normal distribution. However, note AcceptReject::plot() function makes plotting task simpler direct. See following example: See another example, discrete case:","code":"library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 2000 #> ✔ c: 3.19153824335755 #> ✔ Probability of acceptance (1/c): 0.313328534314533 #> ✔ Observations: -1.023 -0.0184 -0.9111 0.7965 0.4243 2.3148 -0.1822 -2.0416 0.1491 2.1305... #> #> ──────────────────────────────────────────────────────────────────────────────── hist( data, main = \"Generating Gaussian observations\", xlab = \"x\", probability = TRUE, ylim = c(0, 0.4) ) x <- seq(-4, 4, length.out = 500L) y <- dnorm(x, mean = 0, sd = 1) lines(x, y, col = \"red\", lwd = 2) legend(\"topright\", legend = \"True density\", col = \"red\", lwd = 2) library(AcceptReject) library(patchwork) # install.packages(\"pacthwork\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) } # Inspecting p1 <- simulation(n = 250L) |> plot() p2 <- simulation(n = 2500L) |> plot() p3 <- simulation(n = 25000L) |> plot() p4 <- simulation(n = 250000L) |> plot() p1 + p2 + p3 + p4 library(AcceptReject) library(patchwork) # install.packages(\"patchwork\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) } p1 <- simulation(25L) |> plot() p2 <- simulation(250L) |> plot() p3 <- simulation(2500L) |> plot() p4 <- simulation(25000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/articles/accept_reject.html","id":"accessing-metadata","dir":"Articles","previous_headings":"Examples","what":"Accessing metadata","title":"Acceptance and rejection method","text":"AcceptReject::accept_reject() function returns object class accept_reject. executing print() function object class, organized output shown. However, can operate instance accept_reject class atomic vector. example , notice can obtain histogram hist() function check size vector observations generated using length() function. want access metadata, use attr() function. Check list attributes : case, important highlight , general, need access attributes. greatest interest access vector observations generated. want access observation values directly atomic vector R without attributes, without organized printout, simply coerce object using .vector() function, shown following example: Important: need coerce object accept_reject class atomic vector attributes unless specific reason . object accept_reject class atomic vector attributes, can operate like atomic vector. Everything can atomic vector, can object accept_reject class.","code":"library(AcceptReject) data <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) # Creating a histogram hist(data) # Checking the size of the vector of observations length(x) #> [1] 500 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) attributes(data) #> $class #> [1] \"accept_reject\" #> #> $f #> function (x, mean = 0, sd = 1, log = FALSE) #> .Call(C_dnorm, x, mean, sd, log) #> #> #> #> $args_f #> $args_f$mean #> [1] 0 #> #> $args_f$sd #> [1] 1 #> #> #> $c #> [1] 3.191538 #> #> $continuous #> [1] TRUE # Accessing the value c attr(data, \"c\") #> [1] 3.191538 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) class(data) #> [1] \"accept_reject\" print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 100 #> ✔ c: 3.19153824335755 #> ✔ Probability of acceptance (1/c): 0.313328534314533 #> ✔ Observations: -1.5387 0.3894 -1.1376 -1.1119 0.9404 1.0471 -0.617 0.1396 -0.6566 1.9164... #> #> ──────────────────────────────────────────────────────────────────────────────── # Coercing the object into an atomic vector without attributes data <- as.vector(data) print(data) #> [1] -1.53870467 0.38939574 -1.13758586 -1.11193044 0.94041345 1.04709638 #> [7] -0.61698095 0.13963057 -0.65663915 1.91636525 -0.12336472 -0.49628675 #> [13] 0.31267925 -0.56685336 0.78333928 -1.65211592 -1.57053891 2.70437769 #> [19] -0.88338146 -1.25963761 -1.76581944 -0.26738425 -0.51704984 0.19508744 #> [25] 1.16429157 -0.65323033 0.42140778 -1.58613284 1.05725540 1.71607799 #> [31] 1.56007421 1.24794785 -0.52846813 1.09929632 -0.03209583 -0.31734041 #> [37] -0.26176246 0.05915411 -1.36006397 0.57914058 -1.14458484 0.13927373 #> [43] 1.11677352 1.05017015 -1.92517745 -1.47765510 0.19147936 0.31150732 #> [49] -0.32513807 0.50762851 -0.13175768 0.49965012 -0.79175195 0.12672810 #> [55] 0.14944701 0.03548614 -0.29588091 -1.18112264 1.49476458 0.84075588 #> [61] 0.49501813 0.98546915 1.06355776 0.90327224 -0.97355275 -0.54394192 #> [67] 1.36181954 -1.54269020 -0.59670195 -0.56469662 -1.83341560 -0.57205664 #> [73] 0.10227137 0.01935146 -0.55981698 -1.19642650 0.94177106 0.21643013 #> [79] -0.59901242 0.65251458 0.21879227 1.25072688 1.27202878 -1.30618769 #> [85] -0.76321989 1.12885593 1.01499283 -0.81376197 0.59667628 -0.34872457 #> [91] 0.85112555 1.33809701 -0.51935011 0.92024392 0.20225682 -1.29229795 #> [97] 0.28451799 0.51134847 0.37151868 -0.05340494"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Pedro Rafael D. Marinho. Author, maintainer. Vera Lucia Damasceno Tomazella. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"D. Marinho P, Tomazella V (2024). AcceptReject: Acceptance-Rejection Method Generating Pseudo-Random Observations. R package version 0.1.0, https://prdm0.github.io/AcceptReject/.","code":"@Manual{, title = {AcceptReject: Acceptance-Rejection Method for Generating Pseudo-Random Observations}, author = {Pedro Rafael {D. Marinho} and Vera Lucia Damasceno Tomazella}, year = {2024}, note = {R package version 0.1.0}, url = {https://prdm0.github.io/AcceptReject/}, }"},{"path":"/index.html","id":"acceptreject-","dir":"","previous_headings":"","what":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Generating pseudo-random observations probability distribution common task statistics. able generate pseudo-random observations probability distribution useful simulating scenarios, Monte-Carlo methods, useful evaluating various statistical models. inversion method common way , always possible find closed-form formula inverse function cumulative distribution function random variable X, , q(u) = F−1(u) = x (quantile function), F cumulative distribution function X u uniformly distributed random variable interval (0,1). Whenever possible, preferable use inversion method generate pseudo-random observations probability distribution. However, possible find closed-form formula inverse function cumulative distribution function random variable, necessary resort methods. One way acceptance-rejection method, Monte-Carlo procedure. package aims provide function implements Acceptance Rejection method generating pseudo-random observations probability distributions difficult sample directly. package AcceptReject provides AcceptReject::accept_reject() function implements acceptance-rejection method optimized manner generate pseudo-random observations discrete continuous random variables. AcceptReject::accept_reject() function operates parallel Unix-based operating systems Linux MacOS operates sequentially Windows-based operating systems; however, still exhibits good performance. default, Unix-based systems, observations generated sequentially, possible generate observations parallel desired, using parallel = TRUE argument. AcceptReject::accept_reject() function, default, attempts maximize probability acceptance pseudo-random observations generated. Suppose X Y random variables probability density function (pdf) probability function (pf) f g, respectively. Furthermore, suppose exists constant c $$\\frac{f_X(x)}{g_Y(y)} \\leq c.$$ default, accept_reject function attempts find value c maximizes probability acceptance pseudo-random observations generated. However, possible provide value c AcceptReject::accept_reject() function argument c, Y random variable know generate observations. AcceptReject::accept_reject() function, necessary specify probability function probability density function Y generate observations X discrete continuous cases, respectively. discrete continuous cases, Y follows discrete uniform distribution function continuous uniform distribution function, respectively. Since probability acceptance 1/c, AcceptReject::accept_reject() function attempts find minimum value c satisfies description . Unless compelling reasons provide value c argument AcceptReject::accept_reject() function, recommended use c = NULL (default), allowing value c automatically determined.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"package versioned GitHub. can install development version AcceptReject, , must first install remotes package run following command: force = TRUE argument necessary. needed situations already installed package want reinstall new version.","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/index.html","id":"examples","dir":"","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Please note examples use AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. details, refer function’s documentation Reference Vignette.","code":""},{"path":"/index.html","id":"generating-discrete-observations","dir":"","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"example, let X ∼ Poisson(λ=0.7). generate n = 1000 observations X using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability X assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}).","code":"library(AcceptReject) library(patchwork) # install.packages(\"patchwork\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = TRUE ) } p1 <- simulation(25L) |> plot() p2 <- simulation(250L) |> plot() p3 <- simulation(2500L) |> plot() p4 <- simulation(25000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/index.html","id":"generating-continuous-observations","dir":"","previous_headings":"","what":"Generating continuous observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable X ∼ 𝒩(μ=0,σ2=1). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE.","code":"library(AcceptReject) library(patchwork) # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = TRUE ) } # Inspecting p1 <- simulation(n = 250L) |> plot() p2 <- simulation(n = 2500L) |> plot() p3 <- simulation(n = 25000L) |> plot() p4 <- simulation(n = 250000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/reference/accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Acceptance-Rejection Method — accept_reject","title":"Acceptance-Rejection Method — accept_reject","text":"function implements acceptance-rejection method generating random numbers given probability density function (pdf).","code":""},{"path":"/reference/accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/reference/accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Acceptance-Rejection Method — accept_reject","text":"n number random numbers generate. continuous logical value indicating whether pdf continuous discrete. Default TRUE. f probability density function (continuous = TRUE), continuous case probability mass function, discrete case (continuous = FALSE). args_f list arguments passed pdf function. xlim vector specifying range values random numbers form c(min, max). Default c(0, 100). c constant value used acceptance-rejection method. NULL, estimated using lbfgs::lbfgs() optimization algorithm. Default NULL. linesearch_algorithm linesearch algorithm used lbfgs::lbfgs() optimization. Default \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\". max_iterations maximum number iterations lbfgs::lbfgs() optimization. Default 1000. epsilon convergence criterion lbfgs::lbfgs() optimization. Default 1e-6. start_c initial value constant c lbfgs::lbfgs() optimization. Default 25. parallel logical value indicating whether use parallel processing generating random numbers. Default FALSE. ... Additional arguments passed lbfgs::lbfgs() optimization algorithm. details, see lbfgs::lbfgs().","code":""},{"path":"/reference/accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Acceptance-Rejection Method — accept_reject","text":"vector random numbers generated using acceptance-rejection method.","code":""},{"path":"/reference/accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Acceptance-Rejection Method — accept_reject","text":"situations use inversion method (situations possible obtain quantile function) know transformation involves random variable can generate observations, can use acceptance rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. addition, suppose constant \\(c\\) $$f(x) \\leq c \\cdot g(x), \\quad \\forall x \\\\mathbb{R}.$$ values \\(t\\), \\(f(t)>0\\). use acceptance rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Algorithm Acceptance Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) return step 1. Proof: consider discrete case, , \\(X\\) \\(Y\\) random variables pf's \\(f\\) \\(g\\), respectively. step 3 algorithm, \\({accept} = {x = y} = u < \\frac{f(y)}{cg(y)}\\). , \\(P(accept | Y = y) = \\frac{P(accept \\cap {Y = y})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\) Hence, Total Probability Theorem, : \\(P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\) Therefore, acceptance rejection method accept occurrence $Y$ occurrence \\(X\\) probability \\(1/c\\). addition, Bayes' Theorem, \\(P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\) result shows accepting \\(x = y\\) procedure algorithm equivalent accepting value \\(X\\) pf \\(f\\). argument c = NULL default. Thus, function accept_reject() estimates value c using optimization algorithm lbfgs::lbfgs(). details, see lbfgs::lbfgs(). value c provided, function accept_reject() use value generate random observations. inappropriate choice c can lead low efficiency acceptance rejection method. Unix-based operating systems, function accept_reject() can executed parallel. , simply set argument parallel = TRUE. function accept_reject() utilizes parallel::mclapply() function execute acceptance rejection method parallel. Windows operating systems, code seral even parallel = TRUE set.","code":""},{"path":"/reference/accept_reject.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Acceptance-Rejection Method — accept_reject","text":"CASELLA, George; ROBERT, Christian P.; WELLS, Martin T. Generalized accept-reject sampling schemes. Lecture Notes-Monograph Series, p. 342-347, 2004. NEAL, Radford M. Slice sampling. annals statistics, v. 31, n. 3, p. 705-767, 2003. BISHOP, Christopher. 11.4: Slice sampling. Pattern Recognition Machine Learning. Springer, 2006.","code":""},{"path":[]},{"path":"/reference/accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> plot() accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) |> plot()"},{"path":"/reference/plot.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Accept-Reject — plot.accept_reject","title":"Plot Accept-Reject — plot.accept_reject","text":"Inspects probability function (discrete case) probability density (continuous case) comparing theoretical case observed one.","code":""},{"path":"/reference/plot.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"# S3 method for accept_reject plot( x, color_observed_density = \"#FBBA78\", color_true_density = \"#1D7DA5\", color_bar = \"#FCEFC3\", color_observable_point = \"#7BBDB3\", color_real_point = \"#FE4F0E\", alpha = 0.3, ... )"},{"path":"/reference/plot.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Accept-Reject — plot.accept_reject","text":"x object class accept reject color_observed_density Observed density color (continuous case). color_true_density True density color (continuous case) color_bar Bar chart fill color (discrete case) color_observable_point Color generated points (discrete case) color_real_point Color real probability points (discrete case) alpha Bar chart transparency (discrete case) observed density (continuous case) ... Additional arguments.","code":""},{"path":"/reference/plot.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Accept-Reject — plot.accept_reject","text":"object class gg ggplot package ggplot2. function plot.accept_reject() expects object class accept_reject argument.","code":""},{"path":"/reference/plot.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot Accept-Reject — plot.accept_reject","text":"function plot.accept_reject() responsible plotting probability function (discrete case) probability density (continuous case), comparing theoretical case observed one. useful, therefore, inspecting quality samples generated acceptance-rejection method. returned plot object classes gg ggplot. Easily, can customize plot. function plot.accept_reject(), simply plot(), constructs plot inspection expects object class accept_reject argument.","code":""},{"path":[]},{"path":"/reference/plot.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> plot() accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) |> plot()"},{"path":"/reference/print.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for accept_reject objects — print.accept_reject","title":"Print method for accept_reject objects — print.accept_reject","text":"Print method accept_reject objects","code":""},{"path":"/reference/print.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"# S3 method for accept_reject print(x, n_min = 10L, ...)"},{"path":"/reference/print.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for accept_reject objects — print.accept_reject","text":"x accept_reject object n_min Minimum number observations print ... Additional arguments","code":""},{"path":"/reference/print.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print method for accept_reject objects — print.accept_reject","text":"object class character, providing formatted output information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() enables formatting executing object class 'accept_reject' console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":"/reference/print.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Print method for accept_reject objects — print.accept_reject","text":"function print.accept_reject() responsible printing object class accept_reject formatted manner, providing information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() delivers formatted output executing object class accept_reject console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":[]},{"path":"/reference/print.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> print() #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> #> ✔ Number of observations: 2000 #> ✔ c: 3.4374999989243 #> ✔ Probability of acceptance (1/c): 0.290909091000125 #> ✔ Observations: 1 2 4 1 2 3 3 2 2 3... #> #> ────────────────────────────────────────────────────────────────────────────────"},{"path":"/news/index.html","id":"acceptreject-010","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.0","title":"AcceptReject 0.1.0","text":"Initial CRAN submission.","code":""}] +[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" 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 3 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, see . Copyright (C) This program 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."},{"path":"/articles/accept_reject.html","id":"understanding-the-method","dir":"Articles","previous_headings":"","what":"Understanding the Method","title":"Acceptance and rejection method","text":"situations use inversion method (situations obtaining quantile function possible) neither know transformation involving random variable can generate observations, can make use acceptance-rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. Furthermore, suppose exists constant \\(c\\) \\[\\frac{f(x)}{g(y)} \\leq c,\\] every value \\(x\\), \\(f(x) > 0\\). use acceptance-rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Important: important chosen random variable \\(Y\\) can easily generate observations. acceptance-rejection method computationally intensive direct methods transformation method inversion method, requires generation pseudo-random numbers uniform distribution. Algorithm Acceptance-Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) go back step 1. Proof: Consider discrete case, , \\(X\\) \\(Y\\) random variables pfs \\(f\\) \\(g\\), respectively. step 3 algorithm , \\(\\{accept\\} = \\{x = y\\} = u < \\frac{f(y)}{cg(y)}\\). , \\[P(accept | Y = y) = \\frac{P(accept \\cap \\{Y = y\\})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\] Hence, Law Total Probability, : \\[P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\] Therefore, acceptance-rejection method, accept occurrence \\(Y\\) occurrence \\(X\\) probability \\(1/c\\). Moreover, Bayes’ Theorem, \\[P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\] result shows accepting \\(x = y\\) algorithm’s procedure equivalent accepting value \\(X\\) pf \\(f\\). continuous case, proof similar. Important: Notice reduce computational cost method, choose \\(c\\) way can maximize \\(P(accept)\\). Therefore, choosing excessively large value constant \\(c\\) reduce probability accepting observation \\(Y\\) observation random variable \\(X\\). Note: Computationally, convenient consider \\(Y\\) random variable uniform distribution support \\(f\\), since generating observations uniform distribution straightforward computer. discrete case, considering \\(Y\\) discrete uniform distribution might good alternative.","code":""},{"path":"/articles/accept_reject.html","id":"installation-and-loading-the-package","dir":"Articles","previous_headings":"","what":"Installation and loading the package","title":"Acceptance and rejection method","text":"AcceptReject package available CRAN can installed using following command:","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/articles/accept_reject.html","id":"using-the-accept_reject-function","dir":"Articles","previous_headings":"Installation and loading the package","what":"Using the accept_reject Function","title":"Acceptance and rejection method","text":"Among various functions provided AcceptReject library, acceptance_rejection function implements acceptance-rejection method. AcceptReject::accept_reject() function following signature: Many arguments user need change, AcceptReject::accept_reject() function already default values . However, important note f argument probability density function (pdf) probability function (pf) random variable \\(X\\) observations desired generated. args_f argument list arguments passed f function. c argument value constant c used acceptance-rejection method. user provide value c, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). Note: need define c argument using AcceptReject::accept_reject() function. default, c = NULL, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). However, want set value c, simply pass value c argument. Details optimization c: arguments linesearch_algorithm, max_iterations, epsilon, start_c, ... arguments control optimization algorithm c value. linesearch_algorithm argument line search algorithm used optimization c value. max_iterations argument maximum number iterations optimization algorithm perform. epsilon argument stopping criterion optimization algorithm. start_c argument initial value c used optimization algorithm. arguments passed lbfgs::lbfgs() function, generally, need change .","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/articles/accept_reject.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"Acceptance and rejection method","text":"examples using AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. noted case \\(X\\) discrete random variable, necessary provide argument continuous = FALSE, whereas case \\(X\\) continuous (default), must consider continuous = TRUE.","code":""},{"path":"/articles/accept_reject.html","id":"generating-discrete-observations","dir":"Articles","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance and rejection method","text":"example, let \\(X \\sim Poisson(\\lambda = 0.7)\\). generate \\(n = 1000\\) observations \\(X\\) using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability \\(X\\) assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}). Note necessary specify nature random variable observations desired generated. case discrete variables, argument continuous = FALSE must passed. Now, consider want generate observations random variable \\(X \\sim Binomial(n = 5, p = 0.7)\\). , generate \\(n = 2000\\) observations \\(X\\).","code":"library(AcceptReject) # Ensuring Reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 1000 #> ✔ c: 10.4282913773332 #> ✔ Probability of acceptance (1/c): 0.0958929860910474 #> ✔ Observations: 0 0 0 0 1 0 0 2 1 2... #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dpois(values, lambda = 0.7) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid() library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 2000 #> ✔ c: 6.56249999733451 #> ✔ Probability of acceptance (1/c): 0.152380952442845 #> ✔ Observations: 3 4 4 2 3 1 2 4 2 2... #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dbinom(values, size = 5, prob = 0.5) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid()"},{"path":"/articles/accept_reject.html","id":"generating-continuous-observations","dir":"Articles","previous_headings":"Examples","what":"Generating continuous observations","title":"Acceptance and rejection method","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable \\(X \\sim \\mathcal{N}(\\mu = 0, \\sigma^2 = 1)\\). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. examples , graphs built without using AcceptReject::plot() function. just show can manipulate returning object using AcceptReject::accept_reject() function, , class object accept_reject. However, AcceptReject::plot() function can used generate graphs simpler way. , example use AcceptReject::plot() function generate probability density plot normal distribution. However, note AcceptReject::plot() function makes plotting task simpler direct. See following example: See another example, discrete case:","code":"library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 2000 #> ✔ c: 3.19153824335755 #> ✔ Probability of acceptance (1/c): 0.313328534314533 #> ✔ Observations: -1.023 -0.0184 -0.9111 0.7965 0.4243 2.3148 -0.1822 -2.0416 0.1491 2.1305... #> #> ──────────────────────────────────────────────────────────────────────────────── hist( data, main = \"Generating Gaussian observations\", xlab = \"x\", probability = TRUE, ylim = c(0, 0.4) ) x <- seq(-4, 4, length.out = 500L) y <- dnorm(x, mean = 0, sd = 1) lines(x, y, col = \"red\", lwd = 2) legend(\"topright\", legend = \"True density\", col = \"red\", lwd = 2) library(AcceptReject) library(patchwork) # install.packages(\"pacthwork\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) } # Inspecting p1 <- simulation(n = 250L) |> plot() p2 <- simulation(n = 2500L) |> plot() p3 <- simulation(n = 25000L) |> plot() p4 <- simulation(n = 250000L) |> plot() p1 + p2 + p3 + p4 library(AcceptReject) library(patchwork) # install.packages(\"patchwork\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) } p1 <- simulation(25L) |> plot() p2 <- simulation(250L) |> plot() p3 <- simulation(2500L) |> plot() p4 <- simulation(25000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/articles/accept_reject.html","id":"accessing-metadata","dir":"Articles","previous_headings":"Examples","what":"Accessing metadata","title":"Acceptance and rejection method","text":"AcceptReject::accept_reject() function returns object class accept_reject. executing print() function object class, organized output shown. However, can operate instance accept_reject class atomic vector. example , notice can obtain histogram hist() function check size vector observations generated using length() function. want access metadata, use attr() function. Check list attributes : case, important highlight , general, need access attributes. greatest interest access vector observations generated. want access observation values directly atomic vector R without attributes, without organized printout, simply coerce object using .vector() function, shown following example: Important: need coerce object accept_reject class atomic vector attributes unless specific reason . object accept_reject class atomic vector attributes, can operate like atomic vector. Everything can atomic vector, can object accept_reject class.","code":"library(AcceptReject) data <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) # Creating a histogram hist(data) # Checking the size of the vector of observations length(x) #> [1] 500 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) attributes(data) #> $class #> [1] \"accept_reject\" #> #> $f #> function (x, mean = 0, sd = 1, log = FALSE) #> .Call(C_dnorm, x, mean, sd, log) #> #> #> #> $args_f #> $args_f$mean #> [1] 0 #> #> $args_f$sd #> [1] 1 #> #> #> $c #> [1] 3.191538 #> #> $continuous #> [1] TRUE # Accessing the value c attr(data, \"c\") #> [1] 3.191538 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) class(data) #> [1] \"accept_reject\" print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Number of observations: 100 #> ✔ c: 3.19153824335755 #> ✔ Probability of acceptance (1/c): 0.313328534314533 #> ✔ Observations: -1.5387 0.3894 -1.1376 -1.1119 0.9404 1.0471 -0.617 0.1396 -0.6566 1.9164... #> #> ──────────────────────────────────────────────────────────────────────────────── # Coercing the object into an atomic vector without attributes data <- as.vector(data) print(data) #> [1] -1.53870467 0.38939574 -1.13758586 -1.11193044 0.94041345 1.04709638 #> [7] -0.61698095 0.13963057 -0.65663915 1.91636525 -0.12336472 -0.49628675 #> [13] 0.31267925 -0.56685336 0.78333928 -1.65211592 -1.57053891 2.70437769 #> [19] -0.88338146 -1.25963761 -1.76581944 -0.26738425 -0.51704984 0.19508744 #> [25] 1.16429157 -0.65323033 0.42140778 -1.58613284 1.05725540 1.71607799 #> [31] 1.56007421 1.24794785 -0.52846813 1.09929632 -0.03209583 -0.31734041 #> [37] -0.26176246 0.05915411 -1.36006397 0.57914058 -1.14458484 0.13927373 #> [43] 1.11677352 1.05017015 -1.92517745 -1.47765510 0.19147936 0.31150732 #> [49] -0.32513807 0.50762851 -0.13175768 0.49965012 -0.79175195 0.12672810 #> [55] 0.14944701 0.03548614 -0.29588091 -1.18112264 1.49476458 0.84075588 #> [61] 0.49501813 0.98546915 1.06355776 0.90327224 -0.97355275 -0.54394192 #> [67] 1.36181954 -1.54269020 -0.59670195 -0.56469662 -1.83341560 -0.57205664 #> [73] 0.10227137 0.01935146 -0.55981698 -1.19642650 0.94177106 0.21643013 #> [79] -0.59901242 0.65251458 0.21879227 1.25072688 1.27202878 -1.30618769 #> [85] -0.76321989 1.12885593 1.01499283 -0.81376197 0.59667628 -0.34872457 #> [91] 0.85112555 1.33809701 -0.51935011 0.92024392 0.20225682 -1.29229795 #> [97] 0.28451799 0.51134847 0.37151868 -0.05340494"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Pedro Rafael D. Marinho. Author, maintainer. Vera Lucia Damasceno Tomazella. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"D. Marinho P, Tomazella V (2024). AcceptReject: Acceptance-Rejection Method Generating Pseudo-Random Observations. R package version 0.1.0, https://prdm0.github.io/AcceptReject/.","code":"@Manual{, title = {AcceptReject: Acceptance-Rejection Method for Generating Pseudo-Random Observations}, author = {Pedro Rafael {D. Marinho} and Vera Lucia Damasceno Tomazella}, year = {2024}, note = {R package version 0.1.0}, url = {https://prdm0.github.io/AcceptReject/}, }"},{"path":"/index.html","id":"acceptreject-","dir":"","previous_headings":"","what":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Generating pseudo-random observations probability distribution common task statistics. able generate pseudo-random observations probability distribution useful simulating scenarios, Monte-Carlo methods, useful evaluating various statistical models. inversion method common way , always possible find closed-form formula inverse function cumulative distribution function random variable X, , q(u) = F−1(u) = x (quantile function), F cumulative distribution function X u uniformly distributed random variable interval (0,1). Whenever possible, preferable use inversion method generate pseudo-random observations probability distribution. However, possible find closed-form formula inverse function cumulative distribution function random variable, necessary resort methods. One way acceptance-rejection method, Monte-Carlo procedure. package aims provide function implements Acceptance Rejection method generating pseudo-random observations probability distributions difficult sample directly. package AcceptReject provides AcceptReject::accept_reject() function implements acceptance-rejection method optimized manner generate pseudo-random observations discrete continuous random variables. AcceptReject::accept_reject() function operates parallel Unix-based operating systems Linux MacOS operates sequentially Windows-based operating systems; however, still exhibits good performance. default, Unix-based systems, observations generated sequentially, possible generate observations parallel desired, using parallel = TRUE argument. AcceptReject::accept_reject() function, default, attempts maximize probability acceptance pseudo-random observations generated. Suppose X Y random variables probability density function (pdf) probability function (pf) f g, respectively. Furthermore, suppose exists constant c $$\\frac{f_X(x)}{g_Y(y)} \\leq c.$$ default, accept_reject function attempts find value c maximizes probability acceptance pseudo-random observations generated. However, possible provide value c AcceptReject::accept_reject() function argument c, Y random variable know generate observations. AcceptReject::accept_reject() function, necessary specify probability function probability density function Y generate observations X discrete continuous cases, respectively. discrete continuous cases, Y follows discrete uniform distribution function continuous uniform distribution function, respectively. Since probability acceptance 1/c, AcceptReject::accept_reject() function attempts find minimum value c satisfies description . Unless compelling reasons provide value c argument AcceptReject::accept_reject() function, recommended use c = NULL (default), allowing value c automatically determined.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"package versioned GitHub. can install development version AcceptReject, , must first install remotes package run following command: force = TRUE argument necessary. needed situations already installed package want reinstall new version.","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/index.html","id":"examples","dir":"","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Please note examples use AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. details, refer function’s documentation Reference Vignette.","code":""},{"path":"/index.html","id":"generating-discrete-observations","dir":"","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"example, let X ∼ Poisson(λ=0.7). generate n = 1000 observations X using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability X assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}).","code":"library(AcceptReject) library(patchwork) # install.packages(\"patchwork\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = TRUE ) } p1 <- simulation(25L) |> plot() p2 <- simulation(250L) |> plot() p3 <- simulation(2500L) |> plot() p4 <- simulation(25000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/index.html","id":"generating-continuous-observations","dir":"","previous_headings":"","what":"Generating continuous observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable X ∼ 𝒩(μ=0,σ2=1). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE.","code":"library(AcceptReject) library(patchwork) # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = TRUE ) } # Inspecting p1 <- simulation(n = 250L) |> plot() p2 <- simulation(n = 2500L) |> plot() p3 <- simulation(n = 25000L) |> plot() p4 <- simulation(n = 250000L) |> plot() p1 + p2 + p3 + p4"},{"path":"/reference/accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Acceptance-Rejection Method — accept_reject","title":"Acceptance-Rejection Method — accept_reject","text":"function implements acceptance-rejection method generating random numbers given probability density function (pdf).","code":""},{"path":"/reference/accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/reference/accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Acceptance-Rejection Method — accept_reject","text":"n number random numbers generate. continuous logical value indicating whether pdf continuous discrete. Default TRUE. f probability density function (continuous = TRUE), continuous case probability mass function, discrete case (continuous = FALSE). args_f list arguments passed pdf function. xlim vector specifying range values random numbers form c(min, max). Default c(0, 100). c constant value used acceptance-rejection method. NULL, estimated using lbfgs::lbfgs() optimization algorithm. Default NULL. linesearch_algorithm linesearch algorithm used lbfgs::lbfgs() optimization. Default \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\". max_iterations maximum number iterations lbfgs::lbfgs() optimization. Default 1000. epsilon convergence criterion lbfgs::lbfgs() optimization. Default 1e-6. start_c initial value constant c lbfgs::lbfgs() optimization. Default 25. parallel logical value indicating whether use parallel processing generating random numbers. Default FALSE. ... Additional arguments passed lbfgs::lbfgs() optimization algorithm. details, see lbfgs::lbfgs().","code":""},{"path":"/reference/accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Acceptance-Rejection Method — accept_reject","text":"vector random numbers generated using acceptance-rejection method.","code":""},{"path":"/reference/accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Acceptance-Rejection Method — accept_reject","text":"situations use inversion method (situations possible obtain quantile function) know transformation involves random variable can generate observations, can use acceptance rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. addition, suppose constant \\(c\\) $$f(x) \\leq c \\cdot g(x), \\quad \\forall x \\\\mathbb{R}.$$ values \\(t\\), \\(f(t)>0\\). use acceptance rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Algorithm Acceptance Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) return step 1. Proof: consider discrete case, , \\(X\\) \\(Y\\) random variables pf's \\(f\\) \\(g\\), respectively. step 3 algorithm, \\({accept} = {x = y} = u < \\frac{f(y)}{cg(y)}\\). , \\(P(accept | Y = y) = \\frac{P(accept \\cap {Y = y})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\) Hence, Total Probability Theorem, : \\(P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\) Therefore, acceptance rejection method accept occurrence $Y$ occurrence \\(X\\) probability \\(1/c\\). addition, Bayes' Theorem, \\(P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\) result shows accepting \\(x = y\\) procedure algorithm equivalent accepting value \\(X\\) pf \\(f\\). argument c = NULL default. Thus, function accept_reject() estimates value c using optimization algorithm lbfgs::lbfgs(). details, see lbfgs::lbfgs(). value c provided, function accept_reject() use value generate random observations. inappropriate choice c can lead low efficiency acceptance rejection method. Unix-based operating systems, function accept_reject() can executed parallel. , simply set argument parallel = TRUE. function accept_reject() utilizes parallel::mclapply() function execute acceptance rejection method parallel. Windows operating systems, code seral even parallel = TRUE set.","code":""},{"path":"/reference/accept_reject.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Acceptance-Rejection Method — accept_reject","text":"CASELLA, George; ROBERT, Christian P.; WELLS, Martin T. Generalized accept-reject sampling schemes. Lecture Notes-Monograph Series, p. 342-347, 2004. NEAL, Radford M. Slice sampling. annals statistics, v. 31, n. 3, p. 705-767, 2003. BISHOP, Christopher. 11.4: Slice sampling. Pattern Recognition Machine Learning. Springer, 2006.","code":""},{"path":[]},{"path":"/reference/accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> plot() accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) |> plot()"},{"path":"/reference/plot.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Accept-Reject — plot.accept_reject","title":"Plot Accept-Reject — plot.accept_reject","text":"Inspects probability function (discrete case) probability density (continuous case) comparing theoretical case observed one.","code":""},{"path":"/reference/plot.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"# S3 method for accept_reject plot( x, color_observed_density = \"#FBBA78\", color_true_density = \"#1D7DA5\", color_bar = \"#FCEFC3\", color_observable_point = \"#7BBDB3\", color_real_point = \"#FE4F0E\", alpha = 0.3, ... )"},{"path":"/reference/plot.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Accept-Reject — plot.accept_reject","text":"x object class accept reject color_observed_density Observed density color (continuous case). color_true_density True density color (continuous case) color_bar Bar chart fill color (discrete case) color_observable_point Color generated points (discrete case) color_real_point Color real probability points (discrete case) alpha Bar chart transparency (discrete case) observed density (continuous case) ... Additional arguments.","code":""},{"path":"/reference/plot.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Accept-Reject — plot.accept_reject","text":"object class gg ggplot package ggplot2. function plot.accept_reject() expects object class accept_reject argument.","code":""},{"path":"/reference/plot.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot Accept-Reject — plot.accept_reject","text":"function plot.accept_reject() responsible plotting probability function (discrete case) probability density (continuous case), comparing theoretical case observed one. useful, therefore, inspecting quality samples generated acceptance-rejection method. returned plot object classes gg ggplot. Easily, can customize plot. function plot.accept_reject(), simply plot(), constructs plot inspection expects object class accept_reject argument.","code":""},{"path":[]},{"path":"/reference/plot.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> plot() accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) |> plot()"},{"path":"/reference/print.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for accept_reject objects — print.accept_reject","title":"Print method for accept_reject objects — print.accept_reject","text":"Print method accept_reject objects","code":""},{"path":"/reference/print.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"# S3 method for accept_reject print(x, n_min = 10L, ...)"},{"path":"/reference/print.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for accept_reject objects — print.accept_reject","text":"x accept_reject object n_min Minimum number observations print ... Additional arguments","code":""},{"path":"/reference/print.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print method for accept_reject objects — print.accept_reject","text":"object class character, providing formatted output information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() enables formatting executing object class 'accept_reject' console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":"/reference/print.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Print method for accept_reject objects — print.accept_reject","text":"function print.accept_reject() responsible printing object class accept_reject formatted manner, providing information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() delivers formatted output executing object class accept_reject console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":[]},{"path":"/reference/print.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) |> print() #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> #> ✔ Number of observations: 2000 #> ✔ c: 3.4374999989243 #> ✔ Probability of acceptance (1/c): 0.290909091000125 #> ✔ Observations: 1 2 4 1 2 3 3 2 2 3... #> #> ────────────────────────────────────────────────────────────────────────────────"},{"path":"/news/index.html","id":"acceptreject-010","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.0","title":"AcceptReject 0.1.0","text":"Initial CRAN submission.","code":""}] diff --git a/man/figures/README-unnamed-chunk-2-1.png b/man/figures/README-unnamed-chunk-2-1.png index 205f717..82f202d 100644 Binary files a/man/figures/README-unnamed-chunk-2-1.png and b/man/figures/README-unnamed-chunk-2-1.png differ diff --git a/man/figures/README-unnamed-chunk-3-1.png b/man/figures/README-unnamed-chunk-3-1.png index cf831ce..d67f1d0 100644 Binary files a/man/figures/README-unnamed-chunk-3-1.png and b/man/figures/README-unnamed-chunk-3-1.png differ