diff --git a/.Rbuildignore b/.Rbuildignore index 13e458c..7cf69bf 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,6 @@ -^.*\.Rproj$ -^\.Rproj\.user$ +^.*\.Rproj$ +^\.Rproj\.user$ +^LICENSE\.md$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ diff --git a/DESCRIPTION b/DESCRIPTION index bf018be..c568ac4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,26 +1,47 @@ -Package: tobalcepi -Type: Package -Title: Risk functions and attributable fractions for tobacco and alcohol -Version: 0.1.0 -Author: Duncan Gillespie -Maintainer: Duncan Gillespie -Description: Functions to assign relative risks of disease to individuals based on their tobacco and/or alcohol consumption, and to estimate the attributable fractions of disease. -License: For internal University of Sheffield use only -Encoding: UTF-8 -LazyData: true -Suggests: - knitr, - rmarkdown, - roxygen2, - usethis -Depends: - data.table -Imports: - boot, - VGAM, - stringr, - readxl, - testthat, - dplyr -VignetteBuilder: knitr -RoxygenNote: 6.1.1 +Package: tobalcepi +Type: Package +Title: Risk Functions and Attributable Fractions for Tobacco and Alcohol +Version: 1.0.0 +Authors@R: + c( + person(given = "Duncan", + family = "Gillespie", + role = c("aut", "cre"), + email = "duncan.gillespie@sheffield.ac.uk", + comment = c(ORCID = "0000-0003-3450-5747")), + person(given = "Laura", + family = "Webster", + role = c("aut")), + person(given = "Maddy", + family = "Henney", + role = c("aut")), + person(given = "Colin", + family = "Angus", + role = c("aut"), + email = "c.r.angus@sheffield.ac.uk"), + person(given = "Alan", + family = "Brennan", + role = c("aut"), + email = "a.brennan@sheffield.ac.uk") + ) +Description: Functions to assign relative risks of disease to individuals based on their tobacco and/or alcohol consumption, and to estimate the attributable fractions of disease. +License: GPL-3 +Encoding: UTF-8 +LazyData: true +Suggests: + knitr, + rmarkdown, + roxygen2, + usethis +Imports: + boot, + VGAM, + stringr, + readxl, + testthat, + dplyr, + data.table +VignetteBuilder: knitr +RoxygenNote: 7.1.0 +Depends: + R (>= 2.10) diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..17d33fc --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,595 @@ +GNU General Public License +========================== + +_Version 3, 29 June 2007_ +_Copyright © 2007 Free Software Foundation, Inc. <>_ + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + + Copyright (C) 2020 The University of Sheffield + + 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 . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + tobalcepi Copyright (C) 2020 The University of Sheffield + 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. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/NAMESPACE b/NAMESPACE index c35deca..2a5cfa2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,8 +5,13 @@ export(AlcLags) export(ExpandCodes) export(PArisk) export(RRFunc) +export(RRTobDR) export(RRalc) export(RRtob) export(TobAlcInt) export(TobLags) export(subgroupRisk) +import(data.table) +importFrom(data.table,":=") +importFrom(data.table,setDT) +importFrom(data.table,setnames) diff --git a/R/AlcBinge.R b/R/AlcBinge.R index dbfdd4d..e12063e 100644 --- a/R/AlcBinge.R +++ b/R/AlcBinge.R @@ -1,362 +1,365 @@ - -#' Calculate variables to inform alcohol binge model -#' -#' Uses survey data and previously estimated coefficients to describe -#' the patterns of single occassion drinking. -#' -#' This is based on a study by Hill-McManus 2014, -#' who analysed drinking occasions using data from detailed diaries in the National Diet and Nutrition Survey 2000/2001. -#' Using the results, it possible to model each individual's expected number of drinking occasions across the year, -#' the average amount they drunk on an occasion, the variability in the amount drunk among occasions, -#' and how these vary socio-demographically. -#' -#' @param data Data table of individual characteristics. -#' -#' @return Returns data plus the estimated variables. -#' @export -#' -#' @examples -#' -#' # Simulate individual data -#' -#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 -#' n <- 1e3 -#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) -#' -#' data <- data.table( -#' weekmean = grams_ethanol_day * 7 / 8, -#' peakday = grams_ethanol_day / 8, -#' age = rpois(n, 30), -#' sex = sample(x = c("Male", "Female"), size = n, replace = T), -#' income5cat = "1_lowest income", -#' imd_quintile = "5_most_deprived", -#' kids = "0", -#' social_grade = "C2DE", -#' eduend4cat = "16-18", # age finished education -#' ethnic2cat = "white", # white / non-white -#' employ2cat = "yes", # employed / not -#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg -#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m -#' ) -#' -#' test_data <- AlcBinge(data) -#' -#' -AlcBinge <- function( - - data - -) { - - ################################################################################## - # check variables - temp <- nrow(data[is.na(age)]) - if(temp > 0) warning(paste0(temp, " missing values in age"), immediate. = T) - - temp <- nrow(data[is.na(income5cat)]) - if(temp > 0) warning(paste0(temp, " missing values in income5cat"), immediate. = T) - - temp <- nrow(data[is.na(kids)]) - if(temp > 0) warning(paste0(temp, " missing values in kids"), immediate. = T) - - temp <- nrow(data[is.na(social_grade)]) - if(temp > 0) warning(paste0(temp, " missing values in social_grade"), immediate. = T) - - temp <- nrow(data[is.na(eduend4cat)]) - if(temp > 0) warning(paste0(temp, " missing values in eduend4cat"), immediate. = T) - - temp <- nrow(data[is.na(ethnic2cat)]) - if(temp > 0) warning(paste0(temp, " missing values in ethnic2cat"), immediate. = T) - - temp <- nrow(data[is.na(employ2cat)]) - if(temp > 0) warning(paste0(temp, " missing values in employ2cat"), immediate. = T) - - ################################################################################## - - data[ , age_temp := c( - "<16", "16-17", "18-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", - "50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+")[ - findInterval(age, c(-1, 16, 18, seq(20, 90, 5)))]] - - ################################################################################## - # coefficients based on 2013 Hill-McManus paper - - # negative binomial regression model for the number of weekly drinking occasions - Table 3 - - freq_model_coef <- c( - - 0.422, # log weekly mean consumption - - 0.323, # age 25-34 - 0.467, # age 35-44 - 0.661, # age 45-54 - 0.745, # age 55-64 - - -0.168, # income: in poverty - - -0.254, # ethnicity: non-white - - -0.413, # age left education: none - -0.346, # age left education: 15 - -0.220, # age left education: 16-18 - - -0.037, # children: 1 - 0.137, # children: 2 - -0.166, # children: 3+ - - -0.221, # social class: manual - - 0.063 # constant - ) - - - # fitted Heckman selection model for probability that - # an individual drinks on at least 3 separate occasions during the diary period - Table 5 - - select_model_ceof <- c( - - 0.592, # log weekly mean consumption - - 0.686, # age 25-34 - 0.757, # age 35-44 - 0.978, # age 45-54 - 1.092, # age 55-64 - - -0.31, # income: in poverty - - 0.062, # Not employed - - -0.576, # ethn:non-white - - -0.380, # age left education: none - -0.545, # age left education: 15 - -0.395, # age left education: 16-18 - - -0.032, # children: 1 - 0.205, # children: 2 - -0.253, # children: 3+ - - -0.285, # social class: manual - - -1.349 # constant - ) - - # fitted Heckman outcome regression results for the standard deviation - #in the quantity of alcohol consumed in a drinking occasion. - - sdv_model_coef <- c( - - 0.829, # log weekly mean consumption - - -0.438, # income:in poverty - - 1.194 # imr - ) - - ################################################################################## - - # calculate expected number of weekly drinking occasions, using freq_model_coef - # This just creates a new column for each variable, - # and allocates the individual a coefficient based on their characteristics. - - data[ , mean_consump_coef := freq_model_coef[1]] - - data[ , age_coef := 0] - data[age_temp %in% c("25-29", "30-34"), age_coef := freq_model_coef[2]] - data[age_temp %in% c("35-39", "40-44"), age_coef := freq_model_coef[3]] - data[age_temp %in% c("45-49", "50-54"), age_coef := freq_model_coef[4]] - - # model applied to population below 65 years, but assume effect at 55-65 applies at older ages too - data[age_temp %in% c("55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+"), - age_coef := freq_model_coef[5]] - - data[ , income_coef := 0] - data[income5cat == "1_lowest income", income_coef := freq_model_coef[6]] - - data[ , ethn_coef := 0] - data[ethnic2cat == "nonwhite", ethn_coef := freq_model_coef[7]] - - data[ , leaveed_coef := 0] - data[eduend4cat == "never_went_to_school", leaveed_coef := freq_model_coef[8]] - data[eduend4cat == "15_or_under", leaveed_coef := freq_model_coef[9]] - data[eduend4cat == "16-18", leaveed_coef := freq_model_coef[10]] - - data[ , child_coef := 0] - data[kids == "1", child_coef := freq_model_coef[11]] - data[kids == "2", child_coef := freq_model_coef[12]] - data[kids == "3+", child_coef := freq_model_coef[13]] - - data[ , class_coef := 0] - data[social_grade == "C2DE", class_coef := freq_model_coef[14]] - - data[ , const_coef := freq_model_coef[15]] - - # make the calculation - - data[ , drink_freq := exp(mean_consump_coef * log(weekmean) + - age_coef + income_coef + ethn_coef + leaveed_coef + child_coef + class_coef + const_coef)] - - data[ , `:=`(mean_consump_coef = NULL, age_coef = NULL, income_coef = NULL, ethn_coef = NULL, - leaveed_coef = NULL, child_coef = NULL, class_coef = NULL, const_coef = NULL)] - - data[weekmean == 0, drink_freq := 0] - - # calculate expected standard deviation of a drinking occasions, using sdv_model_coef - - # step one: calculate probability of having 3 or more drinking occasions in a week - - data[ , mean_consump_coef := select_model_ceof[1]] - - data[ , age_coef := 0] - data[age_temp %in% c("25-29", "30-34"), age_coef := select_model_ceof[2]] - data[age_temp %in% c("35-39", "40-44"), age_coef := select_model_ceof[3]] - data[age_temp %in% c("45-49", "50-54"), age_coef := select_model_ceof[4]] - data[age_temp %in% c("55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+"), - age_coef := select_model_ceof[5]] - - data[ , employ_coef := 0] - data[employ2cat == "no", employ_coef := select_model_ceof[6]] - - data[ , income_coef := 0] - data[income5cat == "1_lowest income", income_coef := select_model_ceof[7]] - - data[ , ethn_coef := 0] - data[ethnic2cat == "nonwhite", ethn_coef := select_model_ceof[8]] - - data[ , leaveed_coef := 0] - data[eduend4cat == "never_went_to_school", leaveed_coef := select_model_ceof[9]] - data[eduend4cat == "15_or_under", leaveed_coef := select_model_ceof[10]] - data[eduend4cat == "16-18", leaveed_coef := select_model_ceof[11]] - - data[ , child_coef := 0] - data[kids == "1", child_coef := select_model_ceof[12]] - data[kids == "2", child_coef := select_model_ceof[13]] - data[kids == "3+", child_coef := select_model_ceof[14]] - - data[ , class_coef := 0] - data[social_grade == "C2DE", class_coef := select_model_ceof[15]] - - data[ , const_coef := select_model_ceof[16]] - - # make the calculation - - data[ , drink_3_or_more := VGAM::probit(mean_consump_coef * log(weekmean) + - age_coef + employ_coef + income_coef + ethn_coef + leaveed_coef + child_coef + class_coef + const_coef, inverse = T)] - - data[ , `:=`(mean_consump_coef = NULL, age_coef = NULL, employ_coef = NULL, income_coef = NULL, - ethn_coef = NULL, leaveed_coef = NULL, child_coef = NULL, class_coef = NULL, const_coef = NULL)] - - data[weekmean == 0, drink_3_or_more := 0] - - - # step 2 : calculate inverse mills ratio - - # Formula taken from Hill-McManus 2014 - # standard normal density function / (1 - standard normal cumulative distribution function) - - data[ , imr := dnorm(drink_3_or_more) / (1 - pnorm(drink_3_or_more))] - - - # step 3 : calculate the predicted occasion level standard deviation - # (variation in the quantity consumed in a drinking occasion) - - data[ , mean_consump_coef := sdv_model_coef[1]] - - data[ , income_coef := 0] - data[income5cat == "1_lowest income", income_coef := sdv_model_coef[2]] - - data[ , imr_coef := sdv_model_coef[3]] - - data[ , occ_sd := exp(mean_consump_coef * log(weekmean) + income_coef + imr_coef * imr) / 8] - - # The paper appears to say it is linear regression, but after confirming with Dan, the y (i.e., standard deviation) - # is acutally logged. The paper also not clear regarding measurements. - # But it turned to be units for all weekly consumption (independent variable) and gram for standard deviation of the model. - # hence divided by 8. - - data[ , `:=`(mean_consump_coef = NULL, income_coef = NULL, imr_coef = NULL)] - - - # calculate the average quantity of alcohol consumed during a drinking occasion, - # obtained using the mean weekly consumption divided - # by the predicted number of weekly drinking occasions. - - data[ , mean_sod := weekmean / drink_freq] - data[weekmean == 0, mean_sod := 0] - - - # weights from the coefficients at the bottom of sAPM Binge code - #Weight = ifelse(sex == 2, 63.42913136, 77.12631198) - - # Calculate the Wildemark r value for each individual using their weight and height from the HSE - # described in Watson 1981 - - # From SAPM binge code - #data[sex == "Male", rwatson := 0.55] - #data[sex == "Female", rwatson := 0.68] - - data[sex == "Male", rwatson := 0.39834 + ((12.725 * htval - 0.11275 * age + 2.8993) / wtval)] - data[sex == "Female", rwatson := 0.29218 + ((12.666 * htval - 2.4846) / wtval)] - - - data[ , age_temp := NULL] - -return(data) -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +#' Calculate variables to inform alcohol binge model +#' +#' Uses survey data and previously estimated coefficients to describe +#' the patterns of single occassion drinking. +#' +#' This is based on a study by Hill-McManus 2014, +#' who analysed drinking occasions using data from detailed diaries in the National Diet and Nutrition Survey 2000/2001. +#' Using the results, it possible to model each individual's expected number of drinking occasions across the year, +#' the average amount they drunk on an occasion, the variability in the amount drunk among occasions, +#' and how these vary socio-demographically. +#' +#' @param data Data table of individual characteristics. +#' +#' @return Returns data plus the estimated variables. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#'\dontrun{ +#' +#' # Simulate individual data +#' +#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 +#' n <- 1e3 +#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) +#' +#' data <- data.table( +#' weekmean = grams_ethanol_day * 7 / 8, +#' peakday = grams_ethanol_day / 8, +#' age = rpois(n, 30), +#' sex = sample(x = c("Male", "Female"), size = n, replace = T), +#' income5cat = "1_lowest income", +#' imd_quintile = "5_most_deprived", +#' kids = "0", +#' social_grade = "C2DE", +#' eduend4cat = "16-18", # age finished education +#' ethnic2cat = "white", # white / non-white +#' employ2cat = "yes", # employed / not +#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg +#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m +#' ) +#' +#' test_data <- AlcBinge(data) +#'} +#' +AlcBinge <- function( + + data + +) { + + ################################################################################## + # check variables + temp <- nrow(data[is.na(age)]) + if(temp > 0) warning(paste0(temp, " missing values in age"), immediate. = T) + + temp <- nrow(data[is.na(income5cat)]) + if(temp > 0) warning(paste0(temp, " missing values in income5cat"), immediate. = T) + + temp <- nrow(data[is.na(kids)]) + if(temp > 0) warning(paste0(temp, " missing values in kids"), immediate. = T) + + temp <- nrow(data[is.na(social_grade)]) + if(temp > 0) warning(paste0(temp, " missing values in social_grade"), immediate. = T) + + temp <- nrow(data[is.na(eduend4cat)]) + if(temp > 0) warning(paste0(temp, " missing values in eduend4cat"), immediate. = T) + + temp <- nrow(data[is.na(ethnic2cat)]) + if(temp > 0) warning(paste0(temp, " missing values in ethnic2cat"), immediate. = T) + + temp <- nrow(data[is.na(employ2cat)]) + if(temp > 0) warning(paste0(temp, " missing values in employ2cat"), immediate. = T) + + ################################################################################## + + data[ , age_temp := c( + "<16", "16-17", "18-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", + "50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+")[ + findInterval(age, c(-1, 16, 18, seq(20, 90, 5)))]] + + ################################################################################## + # coefficients based on 2013 Hill-McManus paper + + # negative binomial regression model for the number of weekly drinking occasions - Table 3 + + freq_model_coef <- c( + + 0.422, # log weekly mean consumption + + 0.323, # age 25-34 + 0.467, # age 35-44 + 0.661, # age 45-54 + 0.745, # age 55-64 + + -0.168, # income: in poverty + + -0.254, # ethnicity: non-white + + -0.413, # age left education: none + -0.346, # age left education: 15 + -0.220, # age left education: 16-18 + + -0.037, # children: 1 + 0.137, # children: 2 + -0.166, # children: 3+ + + -0.221, # social class: manual + + 0.063 # constant + ) + + + # fitted Heckman selection model for probability that + # an individual drinks on at least 3 separate occasions during the diary period - Table 5 + + select_model_ceof <- c( + + 0.592, # log weekly mean consumption + + 0.686, # age 25-34 + 0.757, # age 35-44 + 0.978, # age 45-54 + 1.092, # age 55-64 + + -0.31, # income: in poverty + + 0.062, # Not employed + + -0.576, # ethn:non-white + + -0.380, # age left education: none + -0.545, # age left education: 15 + -0.395, # age left education: 16-18 + + -0.032, # children: 1 + 0.205, # children: 2 + -0.253, # children: 3+ + + -0.285, # social class: manual + + -1.349 # constant + ) + + # fitted Heckman outcome regression results for the standard deviation + #in the quantity of alcohol consumed in a drinking occasion. + + sdv_model_coef <- c( + + 0.829, # log weekly mean consumption + + -0.438, # income:in poverty + + 1.194 # imr + ) + + ################################################################################## + + # calculate expected number of weekly drinking occasions, using freq_model_coef + # This just creates a new column for each variable, + # and allocates the individual a coefficient based on their characteristics. + + data[ , mean_consump_coef := freq_model_coef[1]] + + data[ , age_coef := 0] + data[age_temp %in% c("25-29", "30-34"), age_coef := freq_model_coef[2]] + data[age_temp %in% c("35-39", "40-44"), age_coef := freq_model_coef[3]] + data[age_temp %in% c("45-49", "50-54"), age_coef := freq_model_coef[4]] + + # model applied to population below 65 years, but assume effect at 55-65 applies at older ages too + data[age_temp %in% c("55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+"), + age_coef := freq_model_coef[5]] + + data[ , income_coef := 0] + data[income5cat == "1_lowest income", income_coef := freq_model_coef[6]] + + data[ , ethn_coef := 0] + data[ethnic2cat == "nonwhite", ethn_coef := freq_model_coef[7]] + + data[ , leaveed_coef := 0] + data[eduend4cat == "never_went_to_school", leaveed_coef := freq_model_coef[8]] + data[eduend4cat == "15_or_under", leaveed_coef := freq_model_coef[9]] + data[eduend4cat == "16-18", leaveed_coef := freq_model_coef[10]] + + data[ , child_coef := 0] + data[kids == "1", child_coef := freq_model_coef[11]] + data[kids == "2", child_coef := freq_model_coef[12]] + data[kids == "3+", child_coef := freq_model_coef[13]] + + data[ , class_coef := 0] + data[social_grade == "C2DE", class_coef := freq_model_coef[14]] + + data[ , const_coef := freq_model_coef[15]] + + # make the calculation + + data[ , drink_freq := exp(mean_consump_coef * log(weekmean) + + age_coef + income_coef + ethn_coef + leaveed_coef + child_coef + class_coef + const_coef)] + + data[ , `:=`(mean_consump_coef = NULL, age_coef = NULL, income_coef = NULL, ethn_coef = NULL, + leaveed_coef = NULL, child_coef = NULL, class_coef = NULL, const_coef = NULL)] + + data[weekmean == 0, drink_freq := 0] + + # calculate expected standard deviation of a drinking occasions, using sdv_model_coef + + # step one: calculate probability of having 3 or more drinking occasions in a week + + data[ , mean_consump_coef := select_model_ceof[1]] + + data[ , age_coef := 0] + data[age_temp %in% c("25-29", "30-34"), age_coef := select_model_ceof[2]] + data[age_temp %in% c("35-39", "40-44"), age_coef := select_model_ceof[3]] + data[age_temp %in% c("45-49", "50-54"), age_coef := select_model_ceof[4]] + data[age_temp %in% c("55-59", "60-64", "65-69", "70-74", "75-79", "80-84", "85-89", "90+"), + age_coef := select_model_ceof[5]] + + data[ , employ_coef := 0] + data[employ2cat == "no", employ_coef := select_model_ceof[6]] + + data[ , income_coef := 0] + data[income5cat == "1_lowest income", income_coef := select_model_ceof[7]] + + data[ , ethn_coef := 0] + data[ethnic2cat == "nonwhite", ethn_coef := select_model_ceof[8]] + + data[ , leaveed_coef := 0] + data[eduend4cat == "never_went_to_school", leaveed_coef := select_model_ceof[9]] + data[eduend4cat == "15_or_under", leaveed_coef := select_model_ceof[10]] + data[eduend4cat == "16-18", leaveed_coef := select_model_ceof[11]] + + data[ , child_coef := 0] + data[kids == "1", child_coef := select_model_ceof[12]] + data[kids == "2", child_coef := select_model_ceof[13]] + data[kids == "3+", child_coef := select_model_ceof[14]] + + data[ , class_coef := 0] + data[social_grade == "C2DE", class_coef := select_model_ceof[15]] + + data[ , const_coef := select_model_ceof[16]] + + # make the calculation + + data[ , drink_3_or_more := VGAM::probit(mean_consump_coef * log(weekmean) + + age_coef + employ_coef + income_coef + ethn_coef + leaveed_coef + child_coef + class_coef + const_coef, inverse = T)] + + data[ , `:=`(mean_consump_coef = NULL, age_coef = NULL, employ_coef = NULL, income_coef = NULL, + ethn_coef = NULL, leaveed_coef = NULL, child_coef = NULL, class_coef = NULL, const_coef = NULL)] + + data[weekmean == 0, drink_3_or_more := 0] + + + # step 2 : calculate inverse mills ratio + + # Formula taken from Hill-McManus 2014 + # standard normal density function / (1 - standard normal cumulative distribution function) + + data[ , imr := stats::dnorm(drink_3_or_more) / (1 - stats::pnorm(drink_3_or_more))] + + + # step 3 : calculate the predicted occasion level standard deviation + # (variation in the quantity consumed in a drinking occasion) + + data[ , mean_consump_coef := sdv_model_coef[1]] + + data[ , income_coef := 0] + data[income5cat == "1_lowest income", income_coef := sdv_model_coef[2]] + + data[ , imr_coef := sdv_model_coef[3]] + + data[ , occ_sd := exp(mean_consump_coef * log(weekmean) + income_coef + imr_coef * imr) / 8] + + # The paper appears to say it is linear regression, but after confirming with Dan, the y (i.e., standard deviation) + # is acutally logged. The paper also not clear regarding measurements. + # But it turned to be units for all weekly consumption (independent variable) and gram for standard deviation of the model. + # hence divided by 8. + + data[ , `:=`(mean_consump_coef = NULL, income_coef = NULL, imr_coef = NULL)] + + + # calculate the average quantity of alcohol consumed during a drinking occasion, + # obtained using the mean weekly consumption divided + # by the predicted number of weekly drinking occasions. + + data[ , mean_sod := weekmean / drink_freq] + data[weekmean == 0, mean_sod := 0] + + + # weights from the coefficients at the bottom of sAPM Binge code + #Weight = ifelse(sex == 2, 63.42913136, 77.12631198) + + # Calculate the Wildemark r value for each individual using their weight and height from the HSE + # described in Watson 1981 + + # From SAPM binge code + #data[sex == "Male", rwatson := 0.55] + #data[sex == "Female", rwatson := 0.68] + + data[sex == "Male", rwatson := 0.39834 + ((12.725 * htval - 0.11275 * age + 2.8993) / wtval)] + data[sex == "Female", rwatson := 0.29218 + ((12.666 * htval - 2.4846) / wtval)] + + + data[ , age_temp := NULL] + +return(data[]) +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/R/AlcLags.R b/R/AlcLags.R index 71bd079..9626b2d 100644 --- a/R/AlcLags.R +++ b/R/AlcLags.R @@ -1,141 +1,142 @@ - -#' Alcohol lag times -#' -#' Prepare the disease specific functions that describe how a change in alcohol consumption -#' gradually has an effect on the relative risk of disease incidence over time (up to 20 years) -#' since alcohol consumption changed. -#' -#' All lag times are taken from the review by Holmes et al. 2012, -#' and are the numbers used in the current version of SAPM. -#' -#' @param disease_name Character - the name of the disease under consideration. -#' @param n_years Integer - the number of years from 1 to n over which the effect of a change in -#' consumption emerges. Defaults to 20 years to fit with the current lag data. -#' -#' @return Returns a data table with two columns - one for the years since consumption changed, and the other -#' that gives the proportion by which the effect of a change in consumption -#' on an individual's relative risk of disease has so far emerged. -#' @export -#' -#' @examples -#' -#' AlcLags("Pharynx") -#' -AlcLags <- function( - disease_name = c("Pharynx", "Oral_cavity"), - n_years = 20 -) { - - ################################# - # List the specific diseases that fall under each functional form of lag time - - cancer_lags <- c("Pharynx", "Oral_cavity", "Oesophageal_SCC", "Colorectal", "Liver", - "Larynx", "Pancreas", "Breast") - - alc_specific_lags <- c("Alcohol_induced_pseudoCushings_syndrome", "Degeneration", "Alcoholic_polyneuropathy", - "Alcoholic_myopathy", "Alcoholic_cardiomyopathy") - - maternal_care_lag <- "Maternal_care_for_suspected_damage_to_foetus_from_alcohol" - - digestive_lags <- c("LiverCirrhosis", "Chronic_Pancreatitis", "Acute_Pancreatitis", - "Acute_pancreatitis_alcohol_induced", "Chronic_pancreatitis_alcohol_induced") - - alc_liver_disease <- "Alcoholic_liver_disease" - - diabetes_lags <- c("Diabetes", "HypertensiveHeartDisease", "Cardiac_Arrhythmias") - - cvd_lags <- c("Ischaemic_heart_disease", "Haemorrhagic_Stroke", "Ischaemic_Stroke") - - epilepsy_lag <- "Epilepsy" - - alcoholic_gastritis_lag <- "Alcoholic_gastritis" - - respiratory_lags <- c("Tuberculosis", "Influenza_clinically_diagnosed", - "Influenza_microbiologically_confirmed", "Pneumonia") - - ################################# - # Specify the functional forms of the lags - # The numbers are taken from SAPM - Holmes et al. 2012 - - # Set the default as an instant reduction of risk e.g. for acute conditions - lag_func <- c(100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - - if(disease_name %in% cancer_lags) { - lag_func <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10) - } - - if(disease_name %in% alc_specific_lags) { - lag_func <- c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5) - } - - if(disease_name %in% maternal_care_lag) { - lag_func <- c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - if(disease_name %in% digestive_lags) { - lag_func <- c(20.2333, 16.1866, 12.9493, 10.3594, 8.2875, 6.6300, 5.3040, 4.2432, 3.3946, 2.7157, 2.1725, 1.7380, 1.3904, 1.1123, 0.8899, 0.7119, 0.5695, 0.4556, 0.3645, 0.2916) - } - - if(disease_name %in% alc_liver_disease) { - lag_func <- c(20.6721, 13.1575, 9.2027, 7.0416, 5.7902, 5.0057, 4.4657, 4.0583, 3.7268, 3.4422, 3.1894, 2.9602, 2.7500, 2.5561, 2.3764, 2.2097, 2.0548, 1.9109, 1.7771, 1.6527) - } - - if(disease_name %in% diabetes_lags) { - lag_func <- c(22.4058, 17.9246, 14.3397, 11.4718, 9.1774, 7.3419, 5.8735, 4.6988, 3.7591, 3.0073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - if(disease_name %in% cvd_lags) { - lag_func <- c(30.8721, 21.6104, 15.1273, 10.5891, 7.4124, 5.1887, 3.6321, 2.5424, 1.7797, 1.2458, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - if(disease_name %in% epilepsy_lag) { - lag_func <- c(43.3727, 26.0236, 15.6142, 9.3685, 5.6211, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - if(disease_name %in% alcoholic_gastritis_lag) { - lag_func <- c(50.0489, 25.0244, 12.5122, 6.2561, 3.1281, 1.5640, 0.7820, 0.3910, 0.1955, 0.0978, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - if(disease_name %in% respiratory_lags) { - lag_func <- c(60.6208, 24.2483, 9.6993, 3.8797, 1.5519, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) - } - - ################################# - # Format the output - - # The numbers above are currently in the form of a percentage change per year - # Re-format so they show the cumulative proportion by which risk reduces over time - # i.e. after 20 years, all excess risk has gone, so the cumulative proportion of risk reduction = 1 - - lag_data <- data.table( - years_since_change = 1:n_years, - prop_risk_reduction = cumsum(lag_func) / 100 - ) - -return(lag_data) -} - - - - - - - - - - - - - - - - - - - - - - - - - + +#' Alcohol lag times +#' +#' Prepare the disease specific functions that describe how a change in alcohol consumption +#' gradually has an effect on the relative risk of disease incidence over time (up to 20 years) +#' since alcohol consumption changed. +#' +#' All lag times are taken from the review by Holmes et al. 2012, +#' and are the numbers used in the current version of SAPM. +#' +#' @param disease_name Character - the name of the disease under consideration. +#' @param n_years Integer - the number of years from 1 to n over which the effect of a change in +#' consumption emerges. Defaults to 20 years to fit with the current lag data. +#' +#' @return Returns a data table with two columns - one for the years since consumption changed, and the other +#' that gives the proportion by which the effect of a change in consumption +#' on an individual's relative risk of disease has so far emerged. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' \dontrun{ +#' AlcLags("Pharynx") +#'} +AlcLags <- function( + disease_name = c("Pharynx", "Oral_cavity"), + n_years = 20 +) { + + ################################# + # List the specific diseases that fall under each functional form of lag time + + cancer_lags <- c("Pharynx", "Oral_cavity", "Oesophageal_SCC", "Colorectal", "Liver", + "Larynx", "Pancreas", "Breast") + + alc_specific_lags <- c("Alcohol_induced_pseudoCushings_syndrome", "Degeneration", "Alcoholic_polyneuropathy", + "Alcoholic_myopathy", "Alcoholic_cardiomyopathy") + + maternal_care_lag <- "Maternal_care_for_suspected_damage_to_foetus_from_alcohol" + + digestive_lags <- c("LiverCirrhosis", "Chronic_Pancreatitis", "Acute_Pancreatitis", + "Acute_pancreatitis_alcohol_induced", "Chronic_pancreatitis_alcohol_induced") + + alc_liver_disease <- "Alcoholic_liver_disease" + + diabetes_lags <- c("Diabetes", "HypertensiveHeartDisease", "Cardiac_Arrhythmias") + + cvd_lags <- c("Ischaemic_heart_disease", "Haemorrhagic_Stroke", "Ischaemic_Stroke") + + epilepsy_lag <- "Epilepsy" + + alcoholic_gastritis_lag <- "Alcoholic_gastritis" + + respiratory_lags <- c("Tuberculosis", "Influenza_clinically_diagnosed", + "Influenza_microbiologically_confirmed", "Pneumonia") + + ################################# + # Specify the functional forms of the lags + # The numbers are taken from SAPM - Holmes et al. 2012 + + # Set the default as an instant reduction of risk e.g. for acute conditions + lag_func <- c(100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + if(disease_name %in% cancer_lags) { + lag_func <- c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10) + } + + if(disease_name %in% alc_specific_lags) { + lag_func <- c(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5) + } + + if(disease_name %in% maternal_care_lag) { + lag_func <- c(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + if(disease_name %in% digestive_lags) { + lag_func <- c(20.2333, 16.1866, 12.9493, 10.3594, 8.2875, 6.6300, 5.3040, 4.2432, 3.3946, 2.7157, 2.1725, 1.7380, 1.3904, 1.1123, 0.8899, 0.7119, 0.5695, 0.4556, 0.3645, 0.2916) + } + + if(disease_name %in% alc_liver_disease) { + lag_func <- c(20.6721, 13.1575, 9.2027, 7.0416, 5.7902, 5.0057, 4.4657, 4.0583, 3.7268, 3.4422, 3.1894, 2.9602, 2.7500, 2.5561, 2.3764, 2.2097, 2.0548, 1.9109, 1.7771, 1.6527) + } + + if(disease_name %in% diabetes_lags) { + lag_func <- c(22.4058, 17.9246, 14.3397, 11.4718, 9.1774, 7.3419, 5.8735, 4.6988, 3.7591, 3.0073, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + if(disease_name %in% cvd_lags) { + lag_func <- c(30.8721, 21.6104, 15.1273, 10.5891, 7.4124, 5.1887, 3.6321, 2.5424, 1.7797, 1.2458, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + if(disease_name %in% epilepsy_lag) { + lag_func <- c(43.3727, 26.0236, 15.6142, 9.3685, 5.6211, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + if(disease_name %in% alcoholic_gastritis_lag) { + lag_func <- c(50.0489, 25.0244, 12.5122, 6.2561, 3.1281, 1.5640, 0.7820, 0.3910, 0.1955, 0.0978, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + if(disease_name %in% respiratory_lags) { + lag_func <- c(60.6208, 24.2483, 9.6993, 3.8797, 1.5519, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + } + + ################################# + # Format the output + + # The numbers above are currently in the form of a percentage change per year + # Re-format so they show the cumulative proportion by which risk reduces over time + # i.e. after 20 years, all excess risk has gone, so the cumulative proportion of risk reduction = 1 + + lag_data <- data.table::data.table( + years_since_change = 1:n_years, + prop_risk_reduction = cumsum(lag_func) / 100 + ) + +return(lag_data[]) +} + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/R/ExpandCodes.R b/R/ExpandCodes.R index 3f6de55..bd6f3f6 100644 --- a/R/ExpandCodes.R +++ b/R/ExpandCodes.R @@ -1,71 +1,72 @@ - - -#' Convert groups of ICD-10 codes to single codes -#' -#' Creates the lookup files for search for single ICD-10 codes related to tobacco and/or alcohol. -#' -#' For example, if one disease category is C00-C06 (oral cancer), this includes the single codes -#' C00,C01,C02,C03,C04,C05,C06. The number of rows will be expanded to give each single code -#' its own row. -#' -#' @param lkup Data frame containing the disease list. -#' -#' @return Returns a data frame containing a row for each single ICD-10 code to be searched for. -#' @export -#' -#' @examples -#' -#' \dontrun{ -#' -#' ExpandCodes(lkup) -#' -#' } -#' -ExpandCodes <- function(lkup) { - - colnames(lkup) <- tolower(colnames(lkup)) - - ICD_names <- unique(lkup$icd10_lookups) - - lkup <- dplyr::distinct(lkup, condition, icd10_lookups) - - for (ind in ICD_names) { - # ind <- ICD_names[1] - - temp1 <- dplyr::filter(lkup, icd10_lookups == ind) - - subcodes <- stringr::str_split(temp1$icd10_lookups[1], ",", simplify = T) - - n <- length(subcodes) - - if (n == 1) { - out <- temp1 - } - - if (n > 1) { - for (i in 1:n) { - temp1$icd10_lookups <- subcodes[i] - - if (i == 1) { - out <- temp1 - - } else { - out <- rbind(out, temp1) - } - } - } - - if (ind == ICD_names[1]) { - lkup1 <- out - - } else { - lkup1 <- rbind(lkup1, out) - } - } - - setDT(lkup1) - -return(lkup1) -} - - + + +#' Convert groups of ICD-10 codes to single codes +#' +#' Creates the lookup files for search for single ICD-10 codes related to tobacco and/or alcohol. +#' +#' For example, if one disease category is C00-C06 (oral cancer), this includes the single codes +#' C00,C01,C02,C03,C04,C05,C06. The number of rows will be expanded to give each single code +#' its own row. +#' +#' @param lkup Data frame containing the disease list. +#' +#' @return Returns a data frame containing a row for each single ICD-10 code to be searched for. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#' \dontrun{ +#' +#' ExpandCodes(lkup) +#' +#' } +#' +ExpandCodes <- function(lkup) { + + colnames(lkup) <- tolower(colnames(lkup)) + + ICD_names <- unique(lkup$icd10_lookups) + + lkup <- dplyr::distinct(lkup, condition, icd10_lookups) + + for (ind in ICD_names) { + # ind <- ICD_names[1] + + temp1 <- dplyr::filter(lkup, icd10_lookups == ind) + + subcodes <- stringr::str_split(temp1$icd10_lookups[1], ",", simplify = T) + + n <- length(subcodes) + + if (n == 1) { + out <- temp1 + } + + if (n > 1) { + for (i in 1:n) { + temp1$icd10_lookups <- subcodes[i] + + if (i == 1) { + out <- temp1 + + } else { + out <- rbind(out, temp1) + } + } + } + + if (ind == ICD_names[1]) { + lkup1 <- out + + } else { + lkup1 <- rbind(lkup1, out) + } + } + + data.table::setDT(lkup1) + +return(lkup1[]) +} + + diff --git a/R/PArisk.R b/R/PArisk.R index b07bba0..9c96b1f 100644 --- a/R/PArisk.R +++ b/R/PArisk.R @@ -1,275 +1,280 @@ - - -#' Relative risks for alcohol-related injuries -#' -#' Uses the 'new' binge model methods to calculate a relative risk -#' for each individual for experiencing each cause during one year. -#' -#' This calculation treats an ocassion as a single point in time and therefore does not detail -#' about the rate of alcohol absorbtion (i.e. there is no alcohol absorbtion rate constant) -#' or the time interval between drinks within an occassion. This could introduce inaccuracies if -#' e.g. a drinking occassion lasted several hours. The methods to calculate the total time spent intoxicated -#' (with blood alcohol content greater than zero) are discussed in Taylor et al 2011 -#' and the discussion paper by Hill-McManus 2014. The relative risks for alcohol-related injuries -#' are taken from Cherpitel et al 2015. -#' -#' @param SODMean Numeric vector - the average amount that each individual is expected to -#' drink on a single drinking occassion. -#' @param SODSDV Numeric vector - the standard deviation of the amount that each individual is expected to -#' drink on a single drinking occassion. -#' @param SODFreq Numeric vector - the expected number of drinking occassions that -#' each individual has each week. -#' @param Weight Numeric vector - each individual's body weight in kg. -#' @param Widmark_r Numeric vector - the fraction of the body mass in which alcohol would be present -#' if it were distributed at concentrations equal to that in blood. -#' See examples of use of the Widmark equation in Watson (1981) and Posey and Mozayani (2007). -#' @param cause Charcter - the acute cause being considered. -#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure -#' ethanol in one UK standard unit of alcohol. -#' @param grams_ethanol_per_std_drink Numeric value giving the conversion factor for -#' the number of grams of ethanol in one standard drink. -#' @param liver_clearance_rate_h The rate at which blood alcohol concentration declines (percent / hour). -#' -#' @return Returns a numeric vector of each individual's relative risk of the acute consequences of drinking. -#' @export -#' -#' @examples -#' # For a male with the following characteristics: -#' Weight <- 70 # weight in kg -#' Height <- 2 # height in m -#' Age <- 25 # age in years -#' -#' # We can estimate their r value from the Widmark equation using parameter values from Posey and Mozayani (2007) -#' Widmark_r <- 0.39834 + ((12.725 * Height - 0.11275 * Age + 2.8993) / Weight) -#' -#' # They might drink from 1 to 100 grams of ethanol on one occassion -#' grams_ethanol <- 1:100 -#' -#' # In minutes, We would expect them to remain intoxicated (with blood alcohol content > 0 percent) for -#' Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * (liver_clearance_rate_h / 60)) -#' -#' # and hours -#' Duration_h <- Duration_m / 60 -#' -#' # Duration is the length of time taken to clear all alcohol from the blood -#' # so we don't apply any thresholds of intoxication, -#' # we just calculate the expected length of time with a bac greater than 0. -#' -#' # Now suppose that on average our example male has 5 drinking occasions per week, and that -#' # on average they drink 3 units of alcohol on an occasion, -#' # and that the standard deviation of amount drunk on an occasion is 14 units. -#' -#' # The cumulative probability distribution of each amount of alcohol being drunk on an occassion is -#' x <- pnorm(grams_ethanol, 2 * 8, 14 * 8) -#' -#' # Convert from the cumulative distribution to the -#' # probability that each level of alcohol is consumed on a drinking occasion -#' interval_prob <- x - c(0, x[1:(length(x) - 1)]) -#' -#' # The probability-weighted distribution of time spent intoxicated during a year (52 weeks) is -#' Time_intox <- 5 * 52 * interval_prob * Duration_h -#' -#' # And the expected total time spent intoxicated is -#' Time_intox_sum <- sum(Time_intox) -#' -#' # The relative risk of a transport injury corresponding to each amount drunk on a single occasion -#' # corresponds to the number of standard drinks consumed -#' -#' # We convert to standard drinking and apply the risk parameters from Cherpitel -#' -#' v <- grams_ethanol / 12.8 -#' v1 <- (v + 1) / 100 -#' -#' # Parameters from Cherpitel -#' b1 <- 3.973538882 -#' b2 <- 6.65184e-6 -#' b3 <- 0.837637 -#' b4 <- 1.018824 -#' -#' # Apply formula for the risk curve from Cherpital -#' lvold_1 <- log(v1) + b1 -#' lvold_2 <- (v1^3) - b2 -#' logitp <- lvold_1 * b3 + lvold_2 * b4 -#' p <- boot::inv.logit(logitp) -#' -#' # The relative risk associated with each amount drunk on an occasion -#' rr <- p / p[1] -#' -#' # The relative risk multiplied by the time exposed to that level of risk -#' Current_risk <- rr * Time_intox -#' -#' # The sum of the relative risk associated with the time spent intoxicated during one year -#' Risk_sum <- sum(Current_risk) -#' -#' # The average annual relative risk, considering that time in the year spent with a -#' # blood alcohol content of zero has a relative risk of 1. -#' Annual_risk <- min( -#' (Risk_sum + 1 * (365 * 24 - Time_intox_sum)) / (365 * 24), -#' 365 * 24, na.rm = T) -#' -#' -#' \dontrun{ -#' -#' # THE FOLLOWING ARE NOT CONSIDERED IN THIS CALCULATION -#' -#' # Elapsed time in minutes since consuming alcohol -#' t <- 30 -#' -#' # Alcohol absorbtion rate constant -#' k_empty_stomach <- 6.5 / 60 # grams of ethanol per minute -#' -#' # Alcohol absorbtion -#' alcohol_absorbed <- grams_ethanol * (1 - exp(-k_empty_stomach * t)) -#' -#' # Calculate blood alcohol content using the Wildemark eqn -#' bac <- (100 * alcohol_absorbed / (Widmark_r * Weight * 1000)) - ((liver_clearance_rate_h / 60) * t) -#' } -#' -PArisk <- function( - SODMean, - SODSDV, - SODFreq, - Weight, - Widmark_r, - cause = "Transport", - grams_ethanol_per_unit = 8, - grams_ethanol_per_std_drink = 12.8, - liver_clearance_rate_h = 0.017 - ) { - - # The amounts of alcohol (g ethanol) that could be consumed on an occasion - # i.e. the mass of alcohol ingested - grams_ethanol <- 1:100 # units * ConvertToGramOfAlcohol#1:100 - - # Duration is calculated in minutes - - # Convert liver clearance rate from per hour to per minute - liver_clearance_rate_m <- liver_clearance_rate_h / 60 - - Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * liver_clearance_rate_m) - - # Convert to hours - Duration_h <- Duration_m / 60 - - ####################### - # Calculate the cumulative probability distribution of each amount of alcohol (1 to 100 g) being drunk on an occassion - x <- pnorm( - grams_ethanol, - SODMean * grams_ethanol_per_unit, # mean - SODSDV * grams_ethanol_per_unit # variance - ) - - ####################### - # Convert from the cumulative distribution to the - # probability that each level of alcohol is consumed on a drinking occasion - interval_prob <- x - c(0, x[1:(length(x) - 1)]) - - ####################### - # Calculate the total annual time spent intoxicated - # here we use 'intoxicated' to mean having a bac > 0 - # freq_drinks * 52 * interval_prob * duration - - Time_intox <- - SODFreq * # expected number of weekly drinking occasions [number] - 52 * # multiply by the number of weeks in a year [number] - interval_prob * # the probability that each level of alcohol is consumed on a drinking occassion [vector] - Duration_h # the duration of intoxication (1 to 100g) for each amount of alcohol that could be drunk [vector] - - # Total annual time spent intoxicated over all levels of conusumption - Time_intox_sum <- sum(Time_intox) - - ####################### - # Apply risk function - - # all risk functions from Cherpitel et al 2015 - - # NOTE THAT VOLUME IS IN STANDARD DRINKS, NOT GRAMS, PER OCCASION. 1 STD. DRINK = 16ml (12.8g) OF ETHANOL - - v <- grams_ethanol / grams_ethanol_per_std_drink - - v1 <- (v + 1) / 100 - - # Traffic - if(cause == "Transport") { - - b1 <- 3.973538882 - b2 <- 6.65184e-6 - b3 <- 0.837637 - b4 <- 1.018824 - - lvold_1 <- log(v1) + b1 - lvold_2 <- (v1^3) - b2 - logitp <- lvold_1 * b3 + lvold_2 * b4 - p <- boot::inv.logit(logitp) - #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) - rr <- p / p[1] - - } - - # Violence - if(cause == "Violence") { - - b1 <- 5.084489629 - b2 <- 0.0000578783 - b3 <- 0.42362 - b4 <- 0.562549 - - lvold_1 <- (v1^-.5) - b1 - lvold_2 <- (v1^3) - b2 - logitp <- lvold_1 * -b3 + lvold_2 * b4 - p <- boot::inv.logit(logitp) - #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) - rr <- p / p[1] - - } - - # Fall - if(cause == "Fall") { - - b1 <- 0.1398910338 - b2 <- 0.0195695013 - b3 <- 17.84434 - b4 <- 17.6229 - - lvold_1 <- (v1^.5) - b1 - lvold_2 <- v1 - b2 - logitp <- lvold_1 * b3 + lvold_2 * -b4 - p <- boot::inv.logit(logitp) - #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) - rr <- p / p[1] - - } - - # Other - if(cause == "Other") { - - b1 <- 7.965292902 - b2 <- 0.015761462 - b3 <- 0.28148 - b4 <- 2.00946 - - lvold_1 <- (v1^-.5) - b1 - lvold_2 <- v1 - b2 - logitp <- lvold_1 * -b3 + lvold_2 * -b4 - p <- boot::inv.logit(logitp) - #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) - rr <- p / p[1] - - } - - # Risk at that level of grams - Current_risk <- rr * Time_intox - - # Total risk - Risk_sum <- sum(Current_risk) - - # Annual risk - Annual_risk <- min((Risk_sum + 1 * (365 * 24 - Time_intox_sum)) / (365 * 24), (365 * 24), na.rm = T) - -return(Annual_risk) -} - - - - - + + +#' Relative risks for alcohol-related injuries +#' +#' Uses the 'new' binge model methods to calculate a relative risk +#' for each individual for experiencing each cause during one year. +#' +#' This calculation treats an ocassion as a single point in time and therefore does not detail +#' about the rate of alcohol absorbtion (i.e. there is no alcohol absorbtion rate constant) +#' or the time interval between drinks within an occassion. This could introduce inaccuracies if +#' e.g. a drinking occassion lasted several hours. The methods to calculate the total time spent intoxicated +#' (with blood alcohol content greater than zero) are discussed in Taylor et al 2011 +#' and the discussion paper by Hill-McManus 2014. The relative risks for alcohol-related injuries +#' are taken from Cherpitel et al 2015. +#' +#' @param SODMean Numeric vector - the average amount that each individual is expected to +#' drink on a single drinking occassion. +#' @param SODSDV Numeric vector - the standard deviation of the amount that each individual is expected to +#' drink on a single drinking occassion. +#' @param SODFreq Numeric vector - the expected number of drinking occassions that +#' each individual has each week. +#' @param Weight Numeric vector - each individual's body weight in kg. +#' @param Widmark_r Numeric vector - the fraction of the body mass in which alcohol would be present +#' if it were distributed at concentrations equal to that in blood. +#' See examples of use of the Widmark equation in Watson (1981) and Posey and Mozayani (2007). +#' @param cause Charcter - the acute cause being considered. +#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure +#' ethanol in one UK standard unit of alcohol. +#' @param grams_ethanol_per_std_drink Numeric value giving the conversion factor for +#' the number of grams of ethanol in one standard drink. +#' @param liver_clearance_rate_h The rate at which blood alcohol concentration declines (percent / hour). +#' +#' @return Returns a numeric vector of each individual's relative risk of the acute consequences of drinking. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#' \dontrun{ +#' # For a male with the following characteristics: +#' Weight <- 70 # weight in kg +#' Height <- 2 # height in m +#' Age <- 25 # age in years +#' +#' # We can estimate their r value from the Widmark equation +#' # using parameter values from Posey and Mozayani (2007) +#' Widmark_r <- 0.39834 + ((12.725 * Height - 0.11275 * Age + 2.8993) / Weight) +#' +#' # They might drink from 1 to 100 grams of ethanol on one occassion +#' grams_ethanol <- 1:100 +#' +#' # In minutes, We would expect them to remain intoxicated +#' # (with blood alcohol content > 0 percent) for +#' Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * (liver_clearance_rate_h / 60)) +#' +#' # and hours +#' Duration_h <- Duration_m / 60 +#' +#' # Duration is the length of time taken to clear all alcohol from the blood +#' # so we don't apply any thresholds of intoxication, +#' # we just calculate the expected length of time with a bac greater than 0. +#' +#' # Now suppose that on average our example male has 5 drinking occasions per week, and that +#' # on average they drink 3 units of alcohol on an occasion, +#' # and that the standard deviation of amount drunk on an occasion is 14 units. +#' +#' # The cumulative probability distribution of each amount of alcohol being drunk on an occassion is +#' x <- pnorm(grams_ethanol, 2 * 8, 14 * 8) +#' +#' # Convert from the cumulative distribution to the +#' # probability that each level of alcohol is consumed on a drinking occasion +#' interval_prob <- x - c(0, x[1:(length(x) - 1)]) +#' +#' # The probability-weighted distribution of time spent intoxicated during a year (52 weeks) is +#' Time_intox <- 5 * 52 * interval_prob * Duration_h +#' +#' # And the expected total time spent intoxicated is +#' Time_intox_sum <- sum(Time_intox) +#' +#' # The relative risk of a transport injury corresponding to each amount drunk on a single occasion +#' # corresponds to the number of standard drinks consumed +#' +#' # We convert to standard drinking and apply the risk parameters from Cherpitel +#' +#' v <- grams_ethanol / 12.8 +#' v1 <- (v + 1) / 100 +#' +#' # Parameters from Cherpitel +#' b1 <- 3.973538882 +#' b2 <- 6.65184e-6 +#' b3 <- 0.837637 +#' b4 <- 1.018824 +#' +#' # Apply formula for the risk curve from Cherpital +#' lvold_1 <- log(v1) + b1 +#' lvold_2 <- (v1^3) - b2 +#' logitp <- lvold_1 * b3 + lvold_2 * b4 +#' p <- boot::inv.logit(logitp) +#' +#' # The relative risk associated with each amount drunk on an occasion +#' rr <- p / p[1] +#' +#' # The relative risk multiplied by the time exposed to that level of risk +#' Current_risk <- rr * Time_intox +#' +#' # The sum of the relative risk associated with the time spent intoxicated during one year +#' Risk_sum <- sum(Current_risk) +#' +#' # The average annual relative risk, considering that time in the year spent with a +#' # blood alcohol content of zero has a relative risk of 1. +#' Annual_risk <- min( +#' (Risk_sum + 1 * (365 * 24 - Time_intox_sum)) / (365 * 24), +#' 365 * 24, na.rm = T) +#' +#' +#' +#' # THE FOLLOWING ARE NOT CONSIDERED IN THIS CALCULATION +#' +#' # Elapsed time in minutes since consuming alcohol +#' t <- 30 +#' +#' # Alcohol absorbtion rate constant +#' k_empty_stomach <- 6.5 / 60 # grams of ethanol per minute +#' +#' # Alcohol absorbtion +#' alcohol_absorbed <- grams_ethanol * (1 - exp(-k_empty_stomach * t)) +#' +#' # Calculate blood alcohol content using the Wildemark eqn +#' bac <- (100 * alcohol_absorbed / (Widmark_r * Weight * 1000)) - ((liver_clearance_rate_h / 60) * t) +#' } +#' +PArisk <- function( + SODMean, + SODSDV, + SODFreq, + Weight, + Widmark_r, + cause = "Transport", + grams_ethanol_per_unit = 8, + grams_ethanol_per_std_drink = 12.8, + liver_clearance_rate_h = 0.017 + ) { + + # The amounts of alcohol (g ethanol) that could be consumed on an occasion + # i.e. the mass of alcohol ingested + grams_ethanol <- 1:100 # units * ConvertToGramOfAlcohol#1:100 + + # Duration is calculated in minutes + + # Convert liver clearance rate from per hour to per minute + liver_clearance_rate_m <- liver_clearance_rate_h / 60 + + Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * liver_clearance_rate_m) + + # Convert to hours + Duration_h <- Duration_m / 60 + + ####################### + # Calculate the cumulative probability distribution of each amount of alcohol (1 to 100 g) being drunk on an occassion + x <- stats::pnorm( + grams_ethanol, + SODMean * grams_ethanol_per_unit, # mean + SODSDV * grams_ethanol_per_unit # variance + ) + + ####################### + # Convert from the cumulative distribution to the + # probability that each level of alcohol is consumed on a drinking occasion + interval_prob <- x - c(0, x[1:(length(x) - 1)]) + + ####################### + # Calculate the total annual time spent intoxicated + # here we use 'intoxicated' to mean having a bac > 0 + # freq_drinks * 52 * interval_prob * duration + + Time_intox <- + SODFreq * # expected number of weekly drinking occasions [number] + 52 * # multiply by the number of weeks in a year [number] + interval_prob * # the probability that each level of alcohol is consumed on a drinking occassion [vector] + Duration_h # the duration of intoxication (1 to 100g) for each amount of alcohol that could be drunk [vector] + + # Total annual time spent intoxicated over all levels of conusumption + Time_intox_sum <- sum(Time_intox) + + ####################### + # Apply risk function + + # all risk functions from Cherpitel et al 2015 + + # NOTE THAT VOLUME IS IN STANDARD DRINKS, NOT GRAMS, PER OCCASION. 1 STD. DRINK = 16ml (12.8g) OF ETHANOL + + v <- grams_ethanol / grams_ethanol_per_std_drink + + v1 <- (v + 1) / 100 + + # Traffic + if(cause == "Transport") { + + b1 <- 3.973538882 + b2 <- 6.65184e-6 + b3 <- 0.837637 + b4 <- 1.018824 + + lvold_1 <- log(v1) + b1 + lvold_2 <- (v1^3) - b2 + logitp <- lvold_1 * b3 + lvold_2 * b4 + p <- boot::inv.logit(logitp) + #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) + rr <- p / p[1] + + } + + # Violence + if(cause == "Violence") { + + b1 <- 5.084489629 + b2 <- 0.0000578783 + b3 <- 0.42362 + b4 <- 0.562549 + + lvold_1 <- (v1^-0.5) - b1 + lvold_2 <- (v1^3) - b2 + logitp <- lvold_1 * -b3 + lvold_2 * b4 + p <- boot::inv.logit(logitp) + #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) + rr <- p / p[1] + + } + + # Fall + if(cause == "Fall") { + + b1 <- 0.1398910338 + b2 <- 0.0195695013 + b3 <- 17.84434 + b4 <- 17.6229 + + lvold_1 <- (v1^0.5) - b1 + lvold_2 <- v1 - b2 + logitp <- lvold_1 * b3 + lvold_2 * -b4 + p <- boot::inv.logit(logitp) + #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) + rr <- p / p[1] + + } + + # Other + if(cause == "Other") { + + b1 <- 7.965292902 + b2 <- 0.015761462 + b3 <- 0.28148 + b4 <- 2.00946 + + lvold_1 <- (v1^-0.5) - b1 + lvold_2 <- v1 - b2 + logitp <- lvold_1 * -b3 + lvold_2 * -b4 + p <- boot::inv.logit(logitp) + #or <- (p / (1 - p)) / (p[1] / (1 - p[1])) + rr <- p / p[1] + + } + + # Risk at that level of grams + Current_risk <- rr * Time_intox + + # Total risk + Risk_sum <- sum(Current_risk) + + # Annual risk + Annual_risk <- min((Risk_sum + 1 * (365 * 24 - Time_intox_sum)) / (365 * 24), (365 * 24), na.rm = T) + + +return(Annual_risk) +} + + + + + diff --git a/R/RRAlc.R b/R/RRAlc.R index 725e755..cf10383 100644 --- a/R/RRAlc.R +++ b/R/RRAlc.R @@ -1,986 +1,992 @@ - - -#' Relative risks for alcohol related diseases -#' -#' Computes the relative risks for each alcohol related disease based on the published risk curves. -#' -#' Relative risks for partially attributable chronic come from published risk functions whose parameters have been -#' hard-coded within this function rather than being read from an external spreadsheet. For some conditions there are -#' separate risk functions for morbidity and mortality. For conditions that show a J-shaped risk function that -#' indicates protective effects of alcohol, there is an option to remove the protective effect by setting all -#' RR < 1 = 1. Relative risks for partially attributable acute are computed by the PArisk function called from within -#' this function. Relative risks for wholly attributable chronic and wholly attributable acute conditions are calculated -#' based on the extent to which either weekly or daily consumption exceeds a pre-specified threshold. -#' -#' @param data Data table of individual characteristics. -#' @param disease Character - the name of the disease for which the relative risks will be computed. -#' @param av_weekly_grams_per_day_var Character - the name of the variable containing each individual's -#' average weekly consumption of alcohol in grams of ethanol per day. -#' @param peak_grams_per_day_var Character - the name of the variable containing the amount of alcohol -#' that each individual consumed on their heaviest drinking day of the week. -#' @param sex_var Character - the name of the variable containing individual sex. -#' @param age_var Character - the name of the variable containing individual age in single years. -#' @param mort_or_morb Character - for alcohol related diseases that have separate -#' relative risk curves for mortality and morbidity, should the curve corresponding to -#' mortality ("mort") or morbidity ("morb") be used. -#' @param protective Logical - whether to include the protective effects of -#' alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1. -#' @param alc_wholly_chronic_thresholds Numeric vector - the thresholds in grams of ethanol /week over -#' which individuals begin to experience an elevated risk -#' for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female). -#' @param alc_wholly_acute_thresholds Numeric vector - the thresholds in grams of ethanol /day over -#' which individuals begin to experience an elevated risk -#' for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female). -#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure -#' ethanol in one UK standard unit of alcohol. -#' -#' @return Returns a numeric vector of each individual's relative risks for the alcohol related disease specified by "disease". -#' @export -#' -#' @examples -#' -#' # Draw disease specific risk functions -#' -#' # Example data -#' data <- data.table( -#' GPerDay = 0:100, -#' peakday_grams = 0:100, -#' sex = "Female", -#' age = 30 -#' ) -#' -#' # Apply the function -#' test1 <- RRalc( -#' data, -#' disease = "Pharynx", -#' mort_or_morb = "mort" -#' ) -#' -#' test2 <- RRalc( -#' data, -#' disease = "Ischaemic_heart_disease", -#' mort_or_morb = "morb" -#' ) -#' -#' test3 <- RRalc( -#' data, -#' disease = "LiverCirrhosis", -#' mort_or_morb = "mort" -#' ) -#' -#' # Plot the risk functions -#' plot(test1 ~ I(0:100), type = "l", ylim = c(0, 10), ylab = "rr", main = "Females, age 30", xlab = "g per day") -#' lines(test2 ~ I(0:100), col = 2) -#' lines(test3 ~ I(0:100), col = 3) -#' legend("topleft", c("Pharyngeal cancer", "Ischaemic heart disease morbidity", "Liver Cirrhosis mortality"), lty = 1, col = 1:3) -#' -RRalc <- function( - data, - disease = "Pharynx", - av_weekly_grams_per_day_var = "GPerDay", - peak_grams_per_day_var = "peakday_grams", - sex_var = "sex", - age_var = "age", - mort_or_morb = c("mort", "morb"), - protective = TRUE, - alc_wholly_chronic_thresholds = c(6, 8), - alc_wholly_acute_thresholds = c(6, 8), - grams_ethanol_per_unit = 8 - ) { - - n <- nrow(data) - - x <- data[ , get(av_weekly_grams_per_day_var)] - p <- data[ , get(peak_grams_per_day_var)] - sex <- data[ , get(sex_var)] - age <- data[ , get(age_var)] - - # Convert age in single years into categories - age <- c("<16", "16-17", "18-24", "25-34", "35-49", "50-64", "65-74", "75-89", "90+")[ - findInterval(age, c(-1, 16, 18, 25, 35, 50, 65, 75, 90))] - - # Create the vector of relative risks to be returned - # Initially set everyone's value to 1 - risk_indiv <- rep(1, n) - - - ################################################################################ - # Partial chronic-------- - - - ########### - # Cancers # - ########### - - - # Cancer of the oral cavity and pharynx---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease %in% c("Pharynx", "Oral_cavity", "Pharynx_and_Oral_cavity", "Oropharyngeal")) { - - b1 <- 0.02474 - b2 <- 0.00004 - - risk_indiv <- exp(b1 * x - b2 * (x^2)) - - } - - # Cancer of the oesophagus---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease %in% c("Oesophagus", "Oesophageal", "Oesophageal_SCC")) { - - b1 <- 0.05593 - b2 <- 0.00789 - - risk_indiv <- exp(b1 * x - b2 * x * log(x)) - - } - - # Cancer of the colon and rectum---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease == "Colorectal") { - - b1 <- 0.006279 - - risk_indiv <- exp(b1 * x) - - } - - # Cancer of the liver and intrahepatic bile ducts---- - # Chuang et al 2015 - - if(disease == "Liver") { - - b1 <- 0.4100701 - y <- (x + 12) / 100 - b2 <- 0.6728571429 - b3 <- 0.6101417 - b4 <- 0.4527367347 - b5 <- 0.4939596 - - risk_indiv <- exp(b1 * (y - b2) + b3 * ((y^2) - b4) + b5) - - } - - # Cancer of the pancreas---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease %in% c("Pancreas", "Pancreatic")) { - - b1 <- 0.002089 - - risk_indiv <- exp(b1 * x) - - } - - # Cancer of the larynx---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease %in% c("Larynx", "Laryngeal")) { - - b1 <- 0.01462 - b2 <- 0.00002 - - risk_indiv <- exp(b1 * x - b2 * (x^2)) - - } - - # Cancer of the breast---- - # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 - - if(disease == "Breast") { - - b1 <- 0.01018 - - risk_indiv <- exp(b1 * x) - - risk_indiv[sex == "Male"] <- 1 - - } - - - ################## - # Cardiovascular # - ################## - - - # Hypertensive heart disease---- - # Roerecke et al. (in press) - - if(disease == "HypertensiveHeartDisease") { - - # Male - m1 <- 0.0150537 - m2 <- 0.0156155 - - rr.ma <- exp(m1 * x - m2 * (x^3) / (75^2)) - rr.mb <- exp(m1 * x - m2 * (((x^3) - ((x - 21)^3 * 75) / 54) / (75^2))) - rr.mc <- exp(m1 * x - m2 * ((x^3) - ((x - 21)^3 * 75 - (x - 75)^3 * 21) / 54) / (75^2)) - - rr.m <- ifelse(x < 21, rr.ma, ifelse(x >= 21 & x < 75, rr.mb, rr.mc)) - - # Female - f1 <- 0 - f2 <- 0.0154196 - f3 <- 0.0217586 - f4 <- 0.9649937 - - rr.fa <- exp(f1) - rr.fb <- exp(-f2 * x + f3 * (x^3 - ((x - 10)^3 * 20 - (x - 20)^3 * 10) / 10) / 20^2) - rr.fc <- exp(f4) - - rr.f <- ifelse(x < 18.9517, rr.fa, ifelse(x >= 18.9517 & x < 75, rr.fb, rr.fc)) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - - - # Ischaemic heart disease---- - - if(tolower(disease) %in% c("ischaemic_heart_disease", "ischaemic_heart_disease_morb")) { - - # Mortality - # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 - - if(mort_or_morb == "mort") { - - y <- (x + 0.0099999997764826) / 100 - - b1 <- 1.111874 # 16-34 - b2 <- 1.035623 # 35-64 - b3 <- 0.757104 # 65+ - - - # Male - - m1 <- 0.4870068 - m2 <- 1.550984 - m3 <- 0 - m4 <- 0.012 - - # 16-34 - rr.ma1 <- exp(b1 * (-m1 * sqrt(y) + m2 * y^3)) - rr.mb1 <- exp(m3) - rr.mc1 <- exp(m4 * (x - 100)) - - rr.m1 <- ifelse(x <= 60, rr.ma1, ifelse(x > 60 & x < 100, rr.mb1, rr.mc1)) - - # 35-64 - rr.ma2 <- exp(b2 * (-m1 * sqrt(y) + m2 * y^3)) - rr.mb2 <- exp(m3) - rr.mc2 <- exp(m4 * (x - 100)) - - rr.m2 <- ifelse(x <= 60, rr.ma2, ifelse(x > 60 & x < 100, rr.mb2, rr.mc2)) - - # 65+ - rr.ma3 <- exp(b3 * (-m1 * sqrt(y) + m2 * y^3)) - rr.mb3 <- exp(m3) - rr.mc3 <- exp(m4 * (x - 100)) - - rr.m3 <- ifelse(x <= 60, rr.ma3, ifelse(x > 60 & x < 100, rr.mb3, rr.mc3)) - - - rr.m <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.m1, - ifelse(age %in% c("35-49", "50-64"), rr.m2, - ifelse(age %in% c("65-74", "75-89"), rr.m3, NA))) - - # Female - - f1 <- 1.832441 - f2 <- 1.538557 - f3 <- 0.01 - f4 <- 0.0093 - f5 <- 0.0068 - f6 <- 30.3814 - - # 16-34 - rr.fa1 <- exp(b1 * (f1 * y + f2 * y * log(y))) - rr.fb1 <- exp(f3 * (x - f6)) - - rr.f1 <- ifelse(x < f6, rr.fa1, rr.fb1) - - # 35-64 - rr.fa2 <- exp(b2 * (f1 * y + f2 * y * log(y))) - rr.fb2 <- exp(f4 * (x - f6)) - - rr.f2 <- ifelse(x < f6, rr.fa2, rr.fb2) - - # 65+ - rr.fa3 <- exp(b3 * (f1 * y + f2 * y * log(y))) - rr.fb3 <- exp(f5 * (x - f6)) - - rr.f3 <- ifelse(x < f6, rr.fa3, rr.fb3) - - - rr.f <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.f1, - ifelse(age %in% c("35-49", "50-64"), rr.f2, - ifelse(age %in% c("65-74", "75-89"), rr.f3, NA))) - - - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - - # Morbidity - # ROERECKE, M., & REHM, J. (2012). The cardioprotective association of average alcohol consumption and ischaemic heart disease: a systematic review and meta‐analysis. Addiction, 107(7), 1246-1260. - # All protective effects removed for binge drinkers (>60g/day) - # ROERECKE, M., & REHM, J. (2010). Irregular heavy drinking occasions and risk of ischemic heart disease: a systematic review and meta-analysis. American journal of epidemiology, 171(6), 633-644 - - - if(mort_or_morb == "morb") { - - # Male - - m1 <- 0.1178113 - m2 <- 0.0189 - - rr.ma <- exp(-m1 * sqrt(x) + m2 * sqrt(x) * log(x)) - rr.mb <- exp(0) - - rr.m <- ifelse(x < 60, rr.ma, rr.mb) - - - # Female - - f1 <- 0.296842 - f2 <- 0.0392805 - - rr.f <- exp(-f1 * sqrt(x) + f2 * x) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - # remove protective effect for people who binge drink > 60 g/day - risk_indiv[risk_indiv < 1 & p > 60] <- 1 - - } - - if(!isTRUE(protective)) { - - risk_indiv[risk_indiv < 1] <- 1 - - } - - } - - - # Cardiac arrhythmias---- - # SAMOKHVALOV A. V., IRVING H. M., REHM J. Alcohol as a risk factor for atrial fibrillation: a systematic review and meta-analysis. Eur J Cardiovasc Prev Rehabil 2010; 17: 706–712 - - if(disease == "Cardiac_Arrhythmias") { - - b1 <- 0.0575183 - y <- (x + 0.0499992370605469) / 10 - - risk_indiv <- exp(b1 * y) - - } - - - - # Haemorrhagic and other non-ischaemic stroke---- - # PATRA, J., TAYLOR, B., IRVING, H. et al. (2010) Alcohol consumption and the risk of morbidity and mortality for different stroke types--a systematic review and meta-analysis, BMC Public Health, 10, 258 - - if(tolower(disease) %in% c("haemorrhagic_stroke", "haemorrhagic_stroke_morb")) { - - # Mortality - - if(mort_or_morb == "mort") { - - # Male - - m1 <- 1.006943 - m2 <- 0.6898937 - m3 <- 0.0028572082519531 - - rr.ma <- exp(log(1 - x * (1 - m1))) - rr.mb <- exp(m2 * ((x + m3) / 100)) - - rr.m <- ifelse(x <= 1, rr.ma, rr.mb) - - # Female - - f1 <- 1.014815 - f2 <- 1.466406 - f3 <- 0.0028572082519531 - - rr.fa <- exp(log(1 - x * (1 - f1))) - rr.fb <- exp(f2 * ((x + f3) / 100)) - - rr.f <- ifelse(x <= 1, rr.fa, rr.fb) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - - # Morbidity - - if(mort_or_morb == "morb") { - - # Male - - m1 <- 0.007695021 - - rr.m <- exp(x * m1) - - # Female - - f1 <- 0.340861 - f2 <- 0.0944208 - - rr.f <- exp(-f1 * sqrt(x) + f2 * sqrt(x) * log(x)) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - if(!isTRUE(protective)) { - - risk_indiv[risk_indiv < 1] <- 1 - - } - - } - - - # Ischaemic stroke---- - - if(tolower(disease) %in% c("ischaemic_stroke", "ischaemic_stroke_morb")) { - - # Mortality - # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 - - if(mort_or_morb == "mort") { - - a1 <- 1.111874 - a2 <- 1.035623 - a3 <- 0.757104 - - m1 <- 0.4030081 - m2 <- 0.3877538 - - f1 <- 2.48768 - f2 <- 3.708724 - - e1 <- 0.03521 - e2 <- 0.03279 - e3 <- 0.02397 - e4 <- 0.37987 - e5 <- 0.35382 - e6 <- 0.25866 - - y <- (x + 0.0028572082519531) / 100 - - - # Male - - # 16-34 - rr.ma1 <- 1 - x * (1 - exp(-e1)) - rr.mb1 <- exp(a1 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) - - rr.m1 <- ifelse(x <= 1, rr.ma1, rr.mb1) - - # 35-64 - rr.ma2 <- 1 - x * (1 - exp(-e2)) - rr.mb2 <- exp(a2 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) - - rr.m2 <- ifelse(x <= 1, rr.ma2, rr.mb2) - - # 65+ - rr.ma3 <- 1 - x * (1 - exp(-e3)) - rr.mb3 <- exp(a3 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) - - rr.m3 <- ifelse(x <= 1, rr.ma3, rr.mb3) - - rr.m <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.m1, - ifelse(age %in% c("35-49", "50-64"), rr.m2, - ifelse(age %in% c("65-74", "75-89"), rr.m3, NA))) - - # Female - - # 16-34 - rr.fa1 <- 1 - x * (1 - exp(-e4)) - rr.fb1 <- exp(a1 * (-f1 * sqrt(y) + f2 * y)) - - rr.f1 <- ifelse(x <= 1, rr.fa1, rr.fb1) - - # 35-64 - rr.fa2 <- 1 - x * (1 - exp(-e5)) - rr.fb2 <- exp(a2 * (-f1 * sqrt(y) + f2 * y)) - - rr.f2 <- ifelse(x <= 1, rr.fa2, rr.fb2) - - # Female, 65+ - rr.fa3 <- 1 - x * (1 - exp(-e6)) - rr.fb3 <- exp(a3 * (-f1 * sqrt(y) + f2 * y)) - - rr.f3 <- ifelse(x <= 1, rr.fa3, rr.fb3) - - rr.f <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.f1, - ifelse(age %in% c("35-49", "50-64"), rr.f2, - ifelse(age %in% c("65-74", "75-89"), rr.f3, NA))) - - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - - # Morbidity - # PATRA, J., TAYLOR, B., IRVING, H. et al. (2010) Alcohol consumption and the risk of morbidity and mortality for different stroke types--a systematic review and meta-analysis, BMC Public Health, 10, 258 - # All protective effects removed for binge drinkers (>60g/day) - # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 - - if(mort_or_morb == "morb") { - - # Male - - m1 <- 0.132894 - m2 <- 0.03677422 - - rr.m <- exp(-m1 * sqrt(x) + m2 * sqrt(x) * log(x)) - - # Female - - f1 <- 0.114287 - f2 <- 0.01680936 - - rr.f <- exp(-f1 * sqrt(x) + f2 * x) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - # remove protective effect for people who binge drink > 60 g/day - risk_indiv[risk_indiv < 1 & p > 60] <- 1 - - } - - if(!isTRUE(protective)) { - - risk_indiv[risk_indiv < 1] <- 1 - - } - - } - - - - - ############# - # Digestive # - ############# - - - # Fibrosis and cirrhosis of the liver---- - # REHM, J., TAYLOR, B., MOHAPATRA, S. et al. (2010) Alcohol as a risk factor for liver cirrhosis: a systematic review and meta-analysis, Drug and Alcohol Review, 29, 437-45 - - if(tolower(disease) %in% c("livercirrhosis", "livercirrhosis_morb")) { - - - # Mortality - - if(mort_or_morb == "mort") { - - y <- (x + 0.1699981689453125) / 100 - - # Male - - m1 <- 1.033224 - m2 <- 2.793524 - - rr.ma <- exp(log(1 + x * (m1 - 1))) - rr.mb <- exp(m2 * y) - - rr.m <- ifelse(x <= 1, rr.ma, rr.mb) - - # Female - - f1 <- 1.421569 - f2 <- 3.252035 - - rr.fa <- exp(log(1 + x * (f1 - 1))) - rr.fb <- exp(f2 * sqrt(y)) - - rr.f <- ifelse(x <= 1, rr.fa, rr.fb) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - # Morbidity - - if(mort_or_morb == "morb") { - - # Male - - m1 <- 0.01687111 - - rr.m <- exp(m1 * x) - - # Female - - f1 <- 0.2351821 - - rr.f <- exp(f1 * sqrt(x)) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - } - - } - - - # Acute pancreatitis---- - # SAMOKHVALOV, A. V., REHM, J. & ROERECKE, M. (2015) Alcohol consumption as a risk factor for acute and chronic pancreatitis: a systematic review and a series of meta-analyses, EBioMedicine, 2, 1996-2002 - - if(disease == "Acute_Pancreatitis") { - - # Male - - m1 <- 0.013 - - rr.m <- exp(m1 * x) - - # Female - - f1 <- 0.0272886 - f2 <- 0.0611466 - f3 <- 2.327965 - - rr.f1 <- exp(-f1 * x) - rr.f2 <- exp(-f1 * x + f2 * ((x - 3)^3) / ((40 - 3)^2)) - rr.f3 <- exp(-f1 * x + f2 * ( ((x - 3)^3) - ( ( ((x - 15)^3) * (40 - 3) ) / (40 - 15) ) ) / ((40 - 3)^2) ) - rr.f4 <- exp(-f1 * x + f2 * ( ((x - 3)^3) - ( ( ((x - 15)^3) * (40 - 3) - ((x - 40)^3) * (15 - 3) ) / (40 - 15) ) ) / ((40 - 3)^2) ) - rr.f5 <- exp(f3) - - rr.f <- ifelse(x < 3, rr.f1, - ifelse(x >= 3 & x < 15, rr.f2, - ifelse(x >= 15 & x < 40, rr.f3, - ifelse(x >= 40 & x < 108, rr.f4, - ifelse(x >= 108, rr.f5, NA))))) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - if(!isTRUE(protective)) { - - risk_indiv[risk_indiv < 1] <- 1 - - } - - } - - # Chronic pancreatitis---- - # SAMOKHVALOV, A. V., REHM, J. & ROERECKE, M. (2015) Alcohol consumption as a risk factor for acute and chronic pancreatitis: a systematic review and a series of meta-analyses, EBioMedicine, 2, 1996-2002 - - if(disease == "Chronic_Pancreatitis") { - - risk_indiv <- exp(0.018 * x) - - } - - - # Acute and Chronic pancreatitis---- - # Irving et al 2009 - # this is the old version of the pancreatitis risk function - # in the newer version of the model it has been replaced by separate risk functions for acute and chronic - # included here as needed for alc costs to pc work that was based on the old disease list - # that grouped acute and chronic together - - if(disease == "Acute_and_Chronic_Pancreatitis") { - - risk_indiv <- exp(1.259e-5 + x * 8.67933e-5 + (x^2) * 0.00015) - - } - - - - - ############# - # Endocrine # - ############# - - - # Type II Diabetes---- - # KNOTT, C., BELL, S., & BRITTON, A. (2015). Alcohol consumption and the risk of type 2 diabetes: a systematic review and dose-response meta-analysis of more than 1.9 million individuals from 38 observational studies. Diabetes care, 38(9), 1804-1812. - - if(disease == "Diabetes") { - - # Male - m1 <- 0.00001763703 - m2 <- 0.0000000728256 - - rr.m <- exp(m1 * (x^2) - m2 * (x^3)) - - # Female - f1 <- 0.1313991 - f2 <- 0.01014239 - - rr.f <- exp(-f1 * sqrt(x) + f2 * x) - - # Combine - risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) - - if(!isTRUE(protective)) { - - risk_indiv[risk_indiv < 1] <- 1 - - } - - } - - - - - ################## - # Nervous system # - ################## - - - # Epilepsy---- - # SAMOKHVALOV, A. V., IRVING, H., MOHAPATRA, S. & REHM, J. (2010) Alcohol consumption, unprovoked seizures and epilepsy: a systematic review and meta-analysis, Epilepsia, 51, 1177-1184 - - if(disease == "Epilepsy") { - - risk_indiv <- exp(1.22861 * (x + 0.5) / 100) - - } - - - - - ############### - # Respiratory # - ############### - - # Tuberculosis---- - # IMTIAZ, S., SHIELD, K. D., ROERECKE, M., SAMOKHVALOV, A.V., LONNROTH, K., REHM, J. (2017) Alcohol consumption as a risk factor fortuberculosis: meta-analyses and burden of disease. European Respiratory Journal, 50(1), 1700216 - - if(disease == "Tuberculosis") { - - risk_indiv <- exp(0.0179695 * x) - - } - - # Lower respiratory tract infections / Pneumonia---- - # SAMOKHVALOV, A. V., IRVING, H. M. & REHM, J. (2010) Alcohol consumption as a risk factor for pneumonia: systematic review and meta-analysis, Epidemiology and Infection, 138, 1789-1795 - - if(disease %in% c("Pneumonia", "Influenza_clinically_diagnosed", "Influenza_microbiologically_confirmed", "Lower_respiratory_tract_infections")) { - - risk_indiv <- exp(0.4764038 * (x + 0.0399999618530273) / 100) - - } - - # Just to be sure - and fix errors due to log(0) = -Inf - risk_indiv[x == 0] <- 1 - - ################################################################################ - # Partial acute-------- - - - # Transport injuries---- - - if(disease == "Transport_injuries") { - - data[ , rr := sapply(1:n, function(z) { - - tobalcepi::PArisk( - SODMean = mean_sod[z], - SODSDV = occ_sd[z], - SODFreq = drink_freq[z], - Weight = wtval[z], - Widmark_r = rwatson[z], - cause = "Transport", - grams_ethanol_per_unit = grams_ethanol_per_unit - ) - })] - - risk_indiv <- data[ , rr] - - data[ , rr := NULL] - - } - - - # Fall injuries---- - - if(disease == "Fall_injuries") { - - data[ , rr := sapply(1:n, function(z) { - tobalcepi::PArisk( - SODMean = mean_sod[z], - SODSDV = occ_sd[z], - SODFreq = drink_freq[z], - Weight = wtval[z], - Widmark_r = rwatson[z], - cause = "Fall", - grams_ethanol_per_unit = grams_ethanol_per_unit - ) - })] - - risk_indiv <- data[ , rr] - - data[ , rr := NULL] - - } - - # Violence---- - - if(disease %in% c("Assault", "Other_intentional_injuries")) { - - data[ , rr := sapply(1:n, function(z) { - tobalcepi::PArisk( - SODMean = mean_sod[z], - SODSDV = occ_sd[z], - SODFreq = drink_freq[z], - Weight = wtval[z], - Widmark_r = rwatson[z], - cause = "Violence", - grams_ethanol_per_unit = grams_ethanol_per_unit - ) - })] - - risk_indiv <- data[ , rr] - - data[ , rr := NULL] - - } - - # Other---- - - if(disease %in% c("Mechanical_forces", "Drowning", "Other_unintentional_injuries", "intentional_self_harm", "Accidental_poisoning", "Fire_injuries")) { - - data[ , rr := sapply(1:n, function(z) { - tobalcepi::PArisk( - SODMean = mean_sod[z], - SODSDV = occ_sd[z], - SODFreq = drink_freq[z], - Weight = wtval[z], - Widmark_r = rwatson[z], - cause = "Other", - grams_ethanol_per_unit = grams_ethanol_per_unit - ) - })] - - risk_indiv <- data[ , rr] - - data[ , rr := NULL] - - } - - - - - ################################################################################ - # Wholly attributable acute-------- - - # Calculate the absolute rather than the relative risk - - if(disease %in% c( - "Excessive_Blood_Level_of_Alcohol", - "Toxic_effect_of_alcohol", - "Alcohol_poisoning", - "Evidence_of_alcohol_involvement_determined_by_blood_alcohol_level", - "Acute_intoxication") - ) { - - data[sex == "Female", threshold := alc_wholly_acute_thresholds[1]] - data[sex == "Male", threshold := alc_wholly_acute_thresholds[2]] - - data[ , ar := 0] - data[ , diff := p - threshold] - #data[diff > 0, ar := diff / grams_ethanol_per_unit] - data[diff > 0, ar := diff] - - risk_indiv <- 1 + data[ , ar] # add 1 to remove 0/0 = Not a number error later - - data[ , `:=`(ar = NULL, threshold = NULL, diff = NULL)] - - } - - ################################################################################ - # Wholly attributable chronic-------- - - # Calculate the absolute rather than the relative risk - - if(disease %in% c( - "Alcoholic_cardiomyopathy", - "Alcoholic_gastritis", - "Alcoholic_liver_disease", - "Acute_pancreatitis_alcohol_induced", - "Chronic_pancreatitis_alcohol_induced", - "Alcohol_induced_pseudoCushings_syndrome", - "Alcoholic_myopathy", - "Alcoholic_polyneuropathy", - "Maternal_care_for_suspected_damage_to_foetus_from_alcohol", - "Degeneration", - "Mental_and_behavioural_disorders_due_to_use_of_alcohol") - ) { - - data[sex == "Female", threshold := alc_wholly_chronic_thresholds[1]] - data[sex == "Male", threshold := alc_wholly_chronic_thresholds[2]] - - data[ , ar := 0] - data[ , diff := x - threshold] - #data[diff > 0, ar := diff * (7 / grams_ethanol_per_unit)] - data[diff > 0, ar := diff] - - risk_indiv <- 1 + data[ , ar] - - data[ , `:=`(ar = NULL, threshold = NULL, diff = NULL)] - - } - - -return(risk_indiv) -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +#' Relative risks for alcohol related diseases +#' +#' Computes the relative risks for each alcohol related disease based on the published risk curves. +#' +#' Relative risks for partially attributable chronic come from published risk functions whose parameters have been +#' hard-coded within this function rather than being read from an external spreadsheet. For some conditions there are +#' separate risk functions for morbidity and mortality. For conditions that show a J-shaped risk function that +#' indicates protective effects of alcohol, there is an option to remove the protective effect by setting all +#' RR < 1 = 1. Relative risks for partially attributable acute are computed by the PArisk function called from within +#' this function. Relative risks for wholly attributable chronic and wholly attributable acute conditions are calculated +#' based on the extent to which either weekly or daily consumption exceeds a pre-specified threshold. +#' +#' @param data Data table of individual characteristics. +#' @param disease Character - the name of the disease for which the relative risks will be computed. +#' @param av_weekly_grams_per_day_var Character - the name of the variable containing each individual's +#' average weekly consumption of alcohol in grams of ethanol per day. +#' @param peak_grams_per_day_var Character - the name of the variable containing the amount of alcohol +#' that each individual consumed on their heaviest drinking day of the week. +#' @param sex_var Character - the name of the variable containing individual sex. +#' @param age_var Character - the name of the variable containing individual age in single years. +#' @param mort_or_morb Character - for alcohol related diseases that have separate +#' relative risk curves for mortality and morbidity, should the curve corresponding to +#' mortality ("mort") or morbidity ("morb") be used. +#' @param protective Logical - whether to include the protective effects of +#' alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1. +#' @param alc_wholly_chronic_thresholds Numeric vector - the thresholds in grams of ethanol /week over +#' which individuals begin to experience an elevated risk +#' for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female). +#' @param alc_wholly_acute_thresholds Numeric vector - the thresholds in grams of ethanol /day over +#' which individuals begin to experience an elevated risk +#' for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female). +#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure +#' ethanol in one UK standard unit of alcohol. +#' +#' @return Returns a numeric vector of each individual's relative risks for the alcohol related disease specified by "disease". +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#'\dontrun{ +#' +#' # Draw disease specific risk functions +#' +#' # Example data +#' data <- data.table( +#' GPerDay = 0:100, +#' peakday_grams = 0:100, +#' sex = "Female", +#' age = 30 +#' ) +#' +#' # Apply the function +#' test1 <- RRalc( +#' data, +#' disease = "Pharynx", +#' mort_or_morb = "mort" +#' ) +#' +#' test2 <- RRalc( +#' data, +#' disease = "Ischaemic_heart_disease", +#' mort_or_morb = "morb" +#' ) +#' +#' test3 <- RRalc( +#' data, +#' disease = "LiverCirrhosis", +#' mort_or_morb = "mort" +#' ) +#' +#' # Plot the risk functions +#' plot(test1 ~ I(0:100), type = "l", ylim = c(0, 10), ylab = "rr", +#' main = "Females, age 30", xlab = "g per day") +#' lines(test2 ~ I(0:100), col = 2) +#' lines(test3 ~ I(0:100), col = 3) +#' legend("topleft", +#' c("Pharyngeal cancer", "Ischaemic heart disease morbidity", "Liver Cirrhosis mortality"), +#' lty = 1, col = 1:3) +#'} +RRalc <- function( + data, + disease = "Pharynx", + av_weekly_grams_per_day_var = "GPerDay", + peak_grams_per_day_var = "peakday_grams", + sex_var = "sex", + age_var = "age", + mort_or_morb = c("mort", "morb"), + protective = TRUE, + alc_wholly_chronic_thresholds = c(6, 8), + alc_wholly_acute_thresholds = c(6, 8), + grams_ethanol_per_unit = 8 + ) { + + n <- nrow(data) + + x <- data[ , get(av_weekly_grams_per_day_var)] + p <- data[ , get(peak_grams_per_day_var)] + sex <- data[ , get(sex_var)] + age <- data[ , get(age_var)] + + # Convert age in single years into categories + age <- c("<16", "16-17", "18-24", "25-34", "35-49", "50-64", "65-74", "75-89", "90+")[ + findInterval(age, c(-1, 16, 18, 25, 35, 50, 65, 75, 90))] + + # Create the vector of relative risks to be returned + # Initially set everyone's value to 1 + risk_indiv <- rep(1, n) + + + ################################################################################ + # Partial chronic-------- + + + ########### + # Cancers # + ########### + + + # Cancer of the oral cavity and pharynx---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease %in% c("Pharynx", "Oral_cavity", "Pharynx_and_Oral_cavity", "Oropharyngeal")) { + + b1 <- 0.02474 + b2 <- 0.00004 + + risk_indiv <- exp(b1 * x - b2 * (x^2)) + + } + + # Cancer of the oesophagus---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease %in% c("Oesophagus", "Oesophageal", "Oesophageal_SCC")) { + + b1 <- 0.05593 + b2 <- 0.00789 + + risk_indiv <- exp(b1 * x - b2 * x * log(x)) + + } + + # Cancer of the colon and rectum---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease == "Colorectal") { + + b1 <- 0.006279 + + risk_indiv <- exp(b1 * x) + + } + + # Cancer of the liver and intrahepatic bile ducts---- + # Chuang et al 2015 + + if(disease == "Liver") { + + b1 <- 0.4100701 + y <- (x + 12) / 100 + b2 <- 0.6728571429 + b3 <- 0.6101417 + b4 <- 0.4527367347 + b5 <- 0.4939596 + + risk_indiv <- exp(b1 * (y - b2) + b3 * ((y^2) - b4) + b5) + + } + + # Cancer of the pancreas---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease %in% c("Pancreas", "Pancreatic")) { + + b1 <- 0.002089 + + risk_indiv <- exp(b1 * x) + + } + + # Cancer of the larynx---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease %in% c("Larynx", "Laryngeal")) { + + b1 <- 0.01462 + b2 <- 0.00002 + + risk_indiv <- exp(b1 * x - b2 * (x^2)) + + } + + # Cancer of the breast---- + # BAGNARDI, V., ROTA, M., BOTTERI, E. et al. (2015) Alcohol consumption and site-specific cancer risk: a comprehensive dose-response meta-analysis, British Journal of Cancer, 112, 580-593 + + if(disease == "Breast") { + + b1 <- 0.01018 + + risk_indiv <- exp(b1 * x) + + risk_indiv[sex == "Male"] <- 1 + + } + + + ################## + # Cardiovascular # + ################## + + + # Hypertensive heart disease---- + # Roerecke et al. (in press) + + if(disease == "HypertensiveHeartDisease") { + + # Male + m1 <- 0.0150537 + m2 <- 0.0156155 + + rr.ma <- exp(m1 * x - m2 * (x^3) / (75^2)) + rr.mb <- exp(m1 * x - m2 * (((x^3) - ((x - 21)^3 * 75) / 54) / (75^2))) + rr.mc <- exp(m1 * x - m2 * ((x^3) - ((x - 21)^3 * 75 - (x - 75)^3 * 21) / 54) / (75^2)) + + rr.m <- ifelse(x < 21, rr.ma, ifelse(x >= 21 & x < 75, rr.mb, rr.mc)) + + # Female + f1 <- 0 + f2 <- 0.0154196 + f3 <- 0.0217586 + f4 <- 0.9649937 + + rr.fa <- exp(f1) + rr.fb <- exp(-f2 * x + f3 * (x^3 - ((x - 10)^3 * 20 - (x - 20)^3 * 10) / 10) / 20^2) + rr.fc <- exp(f4) + + rr.f <- ifelse(x < 18.9517, rr.fa, ifelse(x >= 18.9517 & x < 75, rr.fb, rr.fc)) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + + + # Ischaemic heart disease---- + + if(tolower(disease) %in% c("ischaemic_heart_disease", "ischaemic_heart_disease_morb")) { + + # Mortality + # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 + + if(mort_or_morb == "mort") { + + y <- (x + 0.0099999997764826) / 100 + + b1 <- 1.111874 # 16-34 + b2 <- 1.035623 # 35-64 + b3 <- 0.757104 # 65+ + + + # Male + + m1 <- 0.4870068 + m2 <- 1.550984 + m3 <- 0 + m4 <- 0.012 + + # 16-34 + rr.ma1 <- exp(b1 * (-m1 * sqrt(y) + m2 * y^3)) + rr.mb1 <- exp(m3) + rr.mc1 <- exp(m4 * (x - 100)) + + rr.m1 <- ifelse(x <= 60, rr.ma1, ifelse(x > 60 & x < 100, rr.mb1, rr.mc1)) + + # 35-64 + rr.ma2 <- exp(b2 * (-m1 * sqrt(y) + m2 * y^3)) + rr.mb2 <- exp(m3) + rr.mc2 <- exp(m4 * (x - 100)) + + rr.m2 <- ifelse(x <= 60, rr.ma2, ifelse(x > 60 & x < 100, rr.mb2, rr.mc2)) + + # 65+ + rr.ma3 <- exp(b3 * (-m1 * sqrt(y) + m2 * y^3)) + rr.mb3 <- exp(m3) + rr.mc3 <- exp(m4 * (x - 100)) + + rr.m3 <- ifelse(x <= 60, rr.ma3, ifelse(x > 60 & x < 100, rr.mb3, rr.mc3)) + + + rr.m <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.m1, + ifelse(age %in% c("35-49", "50-64"), rr.m2, + ifelse(age %in% c("65-74", "75-89"), rr.m3, NA))) + + # Female + + f1 <- 1.832441 + f2 <- 1.538557 + f3 <- 0.01 + f4 <- 0.0093 + f5 <- 0.0068 + f6 <- 30.3814 + + # 16-34 + rr.fa1 <- exp(b1 * (f1 * y + f2 * y * log(y))) + rr.fb1 <- exp(f3 * (x - f6)) + + rr.f1 <- ifelse(x < f6, rr.fa1, rr.fb1) + + # 35-64 + rr.fa2 <- exp(b2 * (f1 * y + f2 * y * log(y))) + rr.fb2 <- exp(f4 * (x - f6)) + + rr.f2 <- ifelse(x < f6, rr.fa2, rr.fb2) + + # 65+ + rr.fa3 <- exp(b3 * (f1 * y + f2 * y * log(y))) + rr.fb3 <- exp(f5 * (x - f6)) + + rr.f3 <- ifelse(x < f6, rr.fa3, rr.fb3) + + + rr.f <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.f1, + ifelse(age %in% c("35-49", "50-64"), rr.f2, + ifelse(age %in% c("65-74", "75-89"), rr.f3, NA))) + + + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + + # Morbidity + # ROERECKE, M., & REHM, J. (2012). The cardioprotective association of average alcohol consumption and ischaemic heart disease: a systematic review and meta‐analysis. Addiction, 107(7), 1246-1260. + # All protective effects removed for binge drinkers (>60g/day) + # ROERECKE, M., & REHM, J. (2010). Irregular heavy drinking occasions and risk of ischemic heart disease: a systematic review and meta-analysis. American journal of epidemiology, 171(6), 633-644 + + + if(mort_or_morb == "morb") { + + # Male + + m1 <- 0.1178113 + m2 <- 0.0189 + + rr.ma <- exp(-m1 * sqrt(x) + m2 * sqrt(x) * log(x)) + rr.mb <- exp(0) + + rr.m <- ifelse(x < 60, rr.ma, rr.mb) + + + # Female + + f1 <- 0.296842 + f2 <- 0.0392805 + + rr.f <- exp(-f1 * sqrt(x) + f2 * x) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + # remove protective effect for people who binge drink > 60 g/day + risk_indiv[risk_indiv < 1 & p > 60] <- 1 + + } + + if(!isTRUE(protective)) { + + risk_indiv[risk_indiv < 1] <- 1 + + } + + } + + + # Cardiac arrhythmias---- + # SAMOKHVALOV A. V., IRVING H. M., REHM J. Alcohol as a risk factor for atrial fibrillation: a systematic review and meta-analysis. Eur J Cardiovasc Prev Rehabil 2010; 17: 706–712 + + if(disease == "Cardiac_Arrhythmias") { + + b1 <- 0.0575183 + y <- (x + 0.0499992370605469) / 10 + + risk_indiv <- exp(b1 * y) + + } + + + + # Haemorrhagic and other non-ischaemic stroke---- + # PATRA, J., TAYLOR, B., IRVING, H. et al. (2010) Alcohol consumption and the risk of morbidity and mortality for different stroke types--a systematic review and meta-analysis, BMC Public Health, 10, 258 + + if(tolower(disease) %in% c("haemorrhagic_stroke", "haemorrhagic_stroke_morb")) { + + # Mortality + + if(mort_or_morb == "mort") { + + # Male + + m1 <- 1.006943 + m2 <- 0.6898937 + m3 <- 0.0028572082519531 + + rr.ma <- exp(log(1 - x * (1 - m1))) + rr.mb <- exp(m2 * ((x + m3) / 100)) + + rr.m <- ifelse(x <= 1, rr.ma, rr.mb) + + # Female + + f1 <- 1.014815 + f2 <- 1.466406 + f3 <- 0.0028572082519531 + + rr.fa <- exp(log(1 - x * (1 - f1))) + rr.fb <- exp(f2 * ((x + f3) / 100)) + + rr.f <- ifelse(x <= 1, rr.fa, rr.fb) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + + # Morbidity + + if(mort_or_morb == "morb") { + + # Male + + m1 <- 0.007695021 + + rr.m <- exp(x * m1) + + # Female + + f1 <- 0.340861 + f2 <- 0.0944208 + + rr.f <- exp(-f1 * sqrt(x) + f2 * sqrt(x) * log(x)) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + if(!isTRUE(protective)) { + + risk_indiv[risk_indiv < 1] <- 1 + + } + + } + + + # Ischaemic stroke---- + + if(tolower(disease) %in% c("ischaemic_stroke", "ischaemic_stroke_morb")) { + + # Mortality + # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 + + if(mort_or_morb == "mort") { + + a1 <- 1.111874 + a2 <- 1.035623 + a3 <- 0.757104 + + m1 <- 0.4030081 + m2 <- 0.3877538 + + f1 <- 2.48768 + f2 <- 3.708724 + + e1 <- 0.03521 + e2 <- 0.03279 + e3 <- 0.02397 + e4 <- 0.37987 + e5 <- 0.35382 + e6 <- 0.25866 + + y <- (x + 0.0028572082519531) / 100 + + + # Male + + # 16-34 + rr.ma1 <- 1 - x * (1 - exp(-e1)) + rr.mb1 <- exp(a1 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) + + rr.m1 <- ifelse(x <= 1, rr.ma1, rr.mb1) + + # 35-64 + rr.ma2 <- 1 - x * (1 - exp(-e2)) + rr.mb2 <- exp(a2 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) + + rr.m2 <- ifelse(x <= 1, rr.ma2, rr.mb2) + + # 65+ + rr.ma3 <- 1 - x * (1 - exp(-e3)) + rr.mb3 <- exp(a3 * (m1 * sqrt(y) + m2 * sqrt(y) * log(y))) + + rr.m3 <- ifelse(x <= 1, rr.ma3, rr.mb3) + + rr.m <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.m1, + ifelse(age %in% c("35-49", "50-64"), rr.m2, + ifelse(age %in% c("65-74", "75-89"), rr.m3, NA))) + + # Female + + # 16-34 + rr.fa1 <- 1 - x * (1 - exp(-e4)) + rr.fb1 <- exp(a1 * (-f1 * sqrt(y) + f2 * y)) + + rr.f1 <- ifelse(x <= 1, rr.fa1, rr.fb1) + + # 35-64 + rr.fa2 <- 1 - x * (1 - exp(-e5)) + rr.fb2 <- exp(a2 * (-f1 * sqrt(y) + f2 * y)) + + rr.f2 <- ifelse(x <= 1, rr.fa2, rr.fb2) + + # Female, 65+ + rr.fa3 <- 1 - x * (1 - exp(-e6)) + rr.fb3 <- exp(a3 * (-f1 * sqrt(y) + f2 * y)) + + rr.f3 <- ifelse(x <= 1, rr.fa3, rr.fb3) + + rr.f <- ifelse(age %in% c("16-17", "18-24", "25-34"), rr.f1, + ifelse(age %in% c("35-49", "50-64"), rr.f2, + ifelse(age %in% c("65-74", "75-89"), rr.f3, NA))) + + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + + # Morbidity + # PATRA, J., TAYLOR, B., IRVING, H. et al. (2010) Alcohol consumption and the risk of morbidity and mortality for different stroke types--a systematic review and meta-analysis, BMC Public Health, 10, 258 + # All protective effects removed for binge drinkers (>60g/day) + # REHM, J., SHIELD, K. D., ROERECKE, M. & GMEL, G. (2016) Modelling the impact of alcohol consumption on cardiovascular disease mortality for comparative risk assessments: an overview BMC Public Health, 16, 363 + + if(mort_or_morb == "morb") { + + # Male + + m1 <- 0.132894 + m2 <- 0.03677422 + + rr.m <- exp(-m1 * sqrt(x) + m2 * sqrt(x) * log(x)) + + # Female + + f1 <- 0.114287 + f2 <- 0.01680936 + + rr.f <- exp(-f1 * sqrt(x) + f2 * x) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + # remove protective effect for people who binge drink > 60 g/day + risk_indiv[risk_indiv < 1 & p > 60] <- 1 + + } + + if(!isTRUE(protective)) { + + risk_indiv[risk_indiv < 1] <- 1 + + } + + } + + + + + ############# + # Digestive # + ############# + + + # Fibrosis and cirrhosis of the liver---- + # REHM, J., TAYLOR, B., MOHAPATRA, S. et al. (2010) Alcohol as a risk factor for liver cirrhosis: a systematic review and meta-analysis, Drug and Alcohol Review, 29, 437-45 + + if(tolower(disease) %in% c("livercirrhosis", "livercirrhosis_morb")) { + + + # Mortality + + if(mort_or_morb == "mort") { + + y <- (x + 0.1699981689453125) / 100 + + # Male + + m1 <- 1.033224 + m2 <- 2.793524 + + rr.ma <- exp(log(1 + x * (m1 - 1))) + rr.mb <- exp(m2 * y) + + rr.m <- ifelse(x <= 1, rr.ma, rr.mb) + + # Female + + f1 <- 1.421569 + f2 <- 3.252035 + + rr.fa <- exp(log(1 + x * (f1 - 1))) + rr.fb <- exp(f2 * sqrt(y)) + + rr.f <- ifelse(x <= 1, rr.fa, rr.fb) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + # Morbidity + + if(mort_or_morb == "morb") { + + # Male + + m1 <- 0.01687111 + + rr.m <- exp(m1 * x) + + # Female + + f1 <- 0.2351821 + + rr.f <- exp(f1 * sqrt(x)) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + } + + } + + + # Acute pancreatitis---- + # SAMOKHVALOV, A. V., REHM, J. & ROERECKE, M. (2015) Alcohol consumption as a risk factor for acute and chronic pancreatitis: a systematic review and a series of meta-analyses, EBioMedicine, 2, 1996-2002 + + if(disease == "Acute_Pancreatitis") { + + # Male + + m1 <- 0.013 + + rr.m <- exp(m1 * x) + + # Female + + f1 <- 0.0272886 + f2 <- 0.0611466 + f3 <- 2.327965 + + rr.f1 <- exp(-f1 * x) + rr.f2 <- exp(-f1 * x + f2 * ((x - 3)^3) / ((40 - 3)^2)) + rr.f3 <- exp(-f1 * x + f2 * ( ((x - 3)^3) - ( ( ((x - 15)^3) * (40 - 3) ) / (40 - 15) ) ) / ((40 - 3)^2) ) + rr.f4 <- exp(-f1 * x + f2 * ( ((x - 3)^3) - ( ( ((x - 15)^3) * (40 - 3) - ((x - 40)^3) * (15 - 3) ) / (40 - 15) ) ) / ((40 - 3)^2) ) + rr.f5 <- exp(f3) + + rr.f <- ifelse(x < 3, rr.f1, + ifelse(x >= 3 & x < 15, rr.f2, + ifelse(x >= 15 & x < 40, rr.f3, + ifelse(x >= 40 & x < 108, rr.f4, + ifelse(x >= 108, rr.f5, NA))))) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + if(!isTRUE(protective)) { + + risk_indiv[risk_indiv < 1] <- 1 + + } + + } + + # Chronic pancreatitis---- + # SAMOKHVALOV, A. V., REHM, J. & ROERECKE, M. (2015) Alcohol consumption as a risk factor for acute and chronic pancreatitis: a systematic review and a series of meta-analyses, EBioMedicine, 2, 1996-2002 + + if(disease == "Chronic_Pancreatitis") { + + risk_indiv <- exp(0.018 * x) + + } + + + # Acute and Chronic pancreatitis---- + # Irving et al 2009 + # this is the old version of the pancreatitis risk function + # in the newer version of the model it has been replaced by separate risk functions for acute and chronic + # included here as needed for alc costs to pc work that was based on the old disease list + # that grouped acute and chronic together + + if(disease == "Acute_and_Chronic_Pancreatitis") { + + risk_indiv <- exp(1.259e-5 + x * 8.67933e-5 + (x^2) * 0.00015) + + } + + + + + ############# + # Endocrine # + ############# + + + # Type II Diabetes---- + # KNOTT, C., BELL, S., & BRITTON, A. (2015). Alcohol consumption and the risk of type 2 diabetes: a systematic review and dose-response meta-analysis of more than 1.9 million individuals from 38 observational studies. Diabetes care, 38(9), 1804-1812. + + if(disease == "Diabetes") { + + # Male + m1 <- 0.00001763703 + m2 <- 0.0000000728256 + + rr.m <- exp(m1 * (x^2) - m2 * (x^3)) + + # Female + f1 <- 0.1313991 + f2 <- 0.01014239 + + rr.f <- exp(-f1 * sqrt(x) + f2 * x) + + # Combine + risk_indiv <- ifelse(sex == "Male", rr.m, ifelse(sex == "Female", rr.f, NA)) + + if(!isTRUE(protective)) { + + risk_indiv[risk_indiv < 1] <- 1 + + } + + } + + + + + ################## + # Nervous system # + ################## + + + # Epilepsy---- + # SAMOKHVALOV, A. V., IRVING, H., MOHAPATRA, S. & REHM, J. (2010) Alcohol consumption, unprovoked seizures and epilepsy: a systematic review and meta-analysis, Epilepsia, 51, 1177-1184 + + if(disease == "Epilepsy") { + + risk_indiv <- exp(1.22861 * (x + 0.5) / 100) + + } + + + + + ############### + # Respiratory # + ############### + + # Tuberculosis---- + # IMTIAZ, S., SHIELD, K. D., ROERECKE, M., SAMOKHVALOV, A.V., LONNROTH, K., REHM, J. (2017) Alcohol consumption as a risk factor fortuberculosis: meta-analyses and burden of disease. European Respiratory Journal, 50(1), 1700216 + + if(disease == "Tuberculosis") { + + risk_indiv <- exp(0.0179695 * x) + + } + + # Lower respiratory tract infections / Pneumonia---- + # SAMOKHVALOV, A. V., IRVING, H. M. & REHM, J. (2010) Alcohol consumption as a risk factor for pneumonia: systematic review and meta-analysis, Epidemiology and Infection, 138, 1789-1795 + + if(disease %in% c("Pneumonia", "Influenza_clinically_diagnosed", "Influenza_microbiologically_confirmed", "Lower_respiratory_tract_infections")) { + + risk_indiv <- exp(0.4764038 * (x + 0.0399999618530273) / 100) + + } + + # Just to be sure - and fix errors due to log(0) = -Inf + risk_indiv[x == 0] <- 1 + + ################################################################################ + # Partial acute-------- + + + # Transport injuries---- + + if(disease == "Transport_injuries") { + + data[ , rr := sapply(1:n, function(z) { + + tobalcepi::PArisk( + SODMean = mean_sod[z], + SODSDV = occ_sd[z], + SODFreq = drink_freq[z], + Weight = wtval[z], + Widmark_r = rwatson[z], + cause = "Transport", + grams_ethanol_per_unit = grams_ethanol_per_unit + ) + })] + + risk_indiv <- data[ , rr] + + data[ , rr := NULL] + + } + + + # Fall injuries---- + + if(disease == "Fall_injuries") { + + data[ , rr := sapply(1:n, function(z) { + tobalcepi::PArisk( + SODMean = mean_sod[z], + SODSDV = occ_sd[z], + SODFreq = drink_freq[z], + Weight = wtval[z], + Widmark_r = rwatson[z], + cause = "Fall", + grams_ethanol_per_unit = grams_ethanol_per_unit + ) + })] + + risk_indiv <- data[ , rr] + + data[ , rr := NULL] + + } + + # Violence---- + + if(disease %in% c("Assault", "Other_intentional_injuries")) { + + data[ , rr := sapply(1:n, function(z) { + tobalcepi::PArisk( + SODMean = mean_sod[z], + SODSDV = occ_sd[z], + SODFreq = drink_freq[z], + Weight = wtval[z], + Widmark_r = rwatson[z], + cause = "Violence", + grams_ethanol_per_unit = grams_ethanol_per_unit + ) + })] + + risk_indiv <- data[ , rr] + + data[ , rr := NULL] + + } + + # Other---- + + if(disease %in% c("Mechanical_forces", "Drowning", "Other_unintentional_injuries", "intentional_self_harm", "Accidental_poisoning", "Fire_injuries")) { + + data[ , rr := sapply(1:n, function(z) { + tobalcepi::PArisk( + SODMean = mean_sod[z], + SODSDV = occ_sd[z], + SODFreq = drink_freq[z], + Weight = wtval[z], + Widmark_r = rwatson[z], + cause = "Other", + grams_ethanol_per_unit = grams_ethanol_per_unit + ) + })] + + risk_indiv <- data[ , rr] + + data[ , rr := NULL] + + } + + + + + ################################################################################ + # Wholly attributable acute-------- + + # Calculate the absolute rather than the relative risk + + if(disease %in% c( + "Excessive_Blood_Level_of_Alcohol", + "Toxic_effect_of_alcohol", + "Alcohol_poisoning", + "Evidence_of_alcohol_involvement_determined_by_blood_alcohol_level", + "Acute_intoxication") + ) { + + data[sex == "Female", threshold := alc_wholly_acute_thresholds[1]] + data[sex == "Male", threshold := alc_wholly_acute_thresholds[2]] + + data[ , ar := 0] + data[ , diff := p - threshold] + #data[diff > 0, ar := diff / grams_ethanol_per_unit] + data[diff > 0, ar := diff] + + risk_indiv <- 1 + data[ , ar] # add 1 to remove 0/0 = Not a number error later + + data[ , `:=`(ar = NULL, threshold = NULL, diff = NULL)] + + } + + ################################################################################ + # Wholly attributable chronic-------- + + # Calculate the absolute rather than the relative risk + + if(disease %in% c( + "Alcoholic_cardiomyopathy", + "Alcoholic_gastritis", + "Alcoholic_liver_disease", + "Acute_pancreatitis_alcohol_induced", + "Chronic_pancreatitis_alcohol_induced", + "Alcohol_induced_pseudoCushings_syndrome", + "Alcoholic_myopathy", + "Alcoholic_polyneuropathy", + "Maternal_care_for_suspected_damage_to_foetus_from_alcohol", + "Degeneration", + "Mental_and_behavioural_disorders_due_to_use_of_alcohol") + ) { + + data[sex == "Female", threshold := alc_wholly_chronic_thresholds[1]] + data[sex == "Male", threshold := alc_wholly_chronic_thresholds[2]] + + data[ , ar := 0] + data[ , diff := x - threshold] + #data[diff > 0, ar := diff * (7 / grams_ethanol_per_unit)] + data[diff > 0, ar := diff] + + risk_indiv <- 1 + data[ , ar] + + data[ , `:=`(ar = NULL, threshold = NULL, diff = NULL)] + + } + + +return(risk_indiv) +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/R/RRFunc.R b/R/RRFunc.R index d002c4b..d996202 100644 --- a/R/RRFunc.R +++ b/R/RRFunc.R @@ -1,516 +1,517 @@ - -#' Individual relative risks of disease -#' -#' This function takes a sample of individuals and computes each individual's relative risk -#' for each disease according to their current tobacco and alcohol consumption. There is an option to tailor this -#' to the alcohol only, tobacco only, or joint tobacco and alcohol contexts. -#' -#' ALCOHOL -#' -#' For alcohol, the relative risk for each individual for each disease is calculated based on their average weekly alcohol consumption. -#' For diseases that have separate mortality and morbidity risk functions, separate variables are created containing -#' the relative risks for each for the same disease. -#' Individuals are not recorded as being former drinkers -- instead their alcohol consumption just falls to zero and their -#' relative risk for disease changes accordingly. -#' -#' Alcohol lags: -#' -#' To account for the lagged effects of individual drinking history on their -#' current risk of disease, we add memory by storing each individual's past trajectory of their relative risk for each disease. -#' In the model, the current relative risk is then adjusted to take account of each individual's stored drinking histories - -#' this adjustment takes the form of a weighted average of current and past relative risk where the weights are proportional to -#' the disease specific lag function that describes the gradual emergence of an effect of changed consumption on risk over time. -#' This uses a slightly different method to SAPM. -#' -#' TOBACCO -#' -#' For tobacco, the relative risk for each individual is calculated based on whether they are a current, former or never smoker. -#' Currently, all current smokers have the same relative risk regardless of the amount they currently smoke or have smoked in the past. -#' -#' Tobacco lags: -#' -#' Former smokers are initially given the relative risk associated with current smokers, which we then scale according to a disease-specific -#' function that describes how risk declines after quitting smoking. -#' -#' ALCOHOL AND TOBACCO -#' -#' If both tobacco and alcohol are being considered in a joint model, -#' we combine the relative risks for current drinkers and smokers. For oral, pharyngeal, laryngeal and oesophageal cancers we also -#' have the option of scaling the joint risks by a 'synergy index', which takes the result of a meta-analysis of the additional -#' risk faced by people because they consume both tobacco and alcohol. -#' -#' @param data Data table of individual characteristics - this function uses current smoking and drinking status/amount. -#' @param substance Whether to compute relative risks for just alcohol ("alc"), -#' just tobacco ("tob") or joint risks for tobacco and alcohol ("tobalc"). -#' @param k_year Integer giving the current year of the simulation. -#' @param alc_diseases Character vector of alcohol related diseases. -#' @param alc_mort_and_morb Character vector of alcohol related diseases that have separate risk functions for -#' mortality and morbidity. -#' @param alc_risk_lags Logical - should each individual's relative risks for alcohol be lagged according to -#' their past trajectory of relative risks. Defaults to FALSE. This should only be set to TRUE for a model run that simulates individual trajctories, -#' and should be FALSE if used as part of the current method for calculating attributable fractions. -#' @param alc_indiv_risk_trajectories_store Data table that stores the individual history of relative risks for alcohol related diseases. -#' @param alc_protective Logical - whether to include the protective effects of -#' alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1. -#' @param alc_wholly_chronic_thresholds Numeric vector - the thresholds in units/week over -#' which individuals begin to experience an elevated risk -#' for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female). -#' @param alc_wholly_acute_thresholds Numeric vector - the thresholds in units/day over -#' which individuals begin to experience an elevated risk -#' for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female). -#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure -#' ethanol in one UK standard unit of alcohol. -#' @param tob_diseases Character vector of tobacco related diseases. -#' @param tob_include_risk_in_former_smokers Logical - whether the residual risks of smoking in former smokers -#' should be considered (defaults to TRUE). -#' @param tobalc_include_int Logical - in computing joint relative risks for tobacco and alcohol, -#' should a (synergystic/multiplicative) interaction between exposure to tobacco and alcohol be included. -#' Defaults to FALSE. If TRUE, then only interactive effects for oesophageal, pharynx, oral cavity and larynx cancers -#' are considered. -#' @param tobalc_int_data Data table containing the disease-specific interactions between tobacco and alcohol. -#' @param show_progress Logical - Should the progress of the loop through diseases be shown. Defaults to FALSE. -#' -#' @return Two data tables are returned: -#' \itemize{ -#' \item "data_plus_rr" is a copy of "data" with added columns that give each -#' individual's relative risk for each disease. -#' \item "new_alc_indiv_risk_trajectories_store" is a copy of "alc_indiv_risk_trajectories_store" with -#' the relative risks for the current year added to the store. -#' } -#' @export -#' -#' @examples -#' -#' ############################# -#' ## ALCOHOL -#' -#' # Simulate individual data -#' -#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 -#' n <- 1e4 -#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) -#' -#' # Note: the socioeconomic and other variables are needed for the binge model -#' -#' data <- data.table( -#' year = 2016, -#' weekmean = grams_ethanol_day * 7 / 8, -#' peakday = 2 * grams_ethanol_day / 8, -#' age = rpois(n, 30), -#' sex = sample(x = c("Male", "Female"), size = n, replace = T), -#' income5cat = "1_lowest income", -#' imd_quintile = "5_most_deprived", -#' kids = "0", -#' social_grade = "C2DE", -#' eduend4cat = "16-18", # age finished education -#' ethnic2cat = "white", # white / non-white -#' employ2cat = "yes", # employed / not -#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg -#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m -#' ) -#' -#' # Add individual ids to the data -#' data <- MakeSeeds(data, n = 0) -#' -#' # Disease names -#' alc_disease_names <- c( -#' "Pharynx", -#' "Ischaemic_heart_disease", -#' "LiverCirrhosis", -#' "Transport_injuries", -#' "Alcohol_poisoning", -#' "Alcoholic_gastritis" -#' ) -#' -#' test_data <- copy(data) -#' -#' test_data1 <- RRFunc( -#' data = test_data, -#' substance = "alc", -#' k_year = 2017, -#' alc_diseases = alc_disease_names, -#' alc_indiv_risk_trajectories_store = NULL, -#' alc_wholly_chronic_thresholds = c(2, 2), -#' alc_wholly_acute_thresholds = c(3, 3), -#' show_progress = TRUE -#' ) -#' -#' test_data1 -#' -#' test_data <- copy(data) -#' test_data[ , year := 2017] -#' -#' test_data2 <- RRFunc( -#' data = test_data, -#' substance = "alc", -#' k_year = 2018, -#' alc_diseases = alc_disease_names, -#' alc_indiv_risk_trajectories_store = test_data1$new_alc_indiv_risk_trajectories_store, -#' alc_wholly_chronic_thresholds = c(2, 2), -#' alc_wholly_acute_thresholds = c(3, 3), -#' show_progress = TRUE -#' ) -#' -#' test_data2 -#' -#' -#' ############################# -#' ## TOBACCO -#' -#' tob_disease_names <- c( -#' "Pharynx", -#' "Chronic_obstructive_pulmonary_disease", -#' "Ischaemic_heart_disease", -#' "Lung", -#' "Influenza_clinically_diagnosed", -#' "Diabetes", -#' "Schizophrenia" -#' ) -#' -#' n <- 1e4 -#' -#' data <- data.table( -#' smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), -#' time_since_quit = sample(x = 0:40, size = n, replace = T), -#' age = rpois(n, 30), -#' sex = sample(x = c("Male", "Female"), size = n, replace = T) -#' ) -#' -#' data[smk.state != "former", time_since_quit := NA] -#' -#' # Tobacco relative risks for Pharygeal cancer -#' RRFunc( -#' data = data, -#' substance = "tob", -#' tob_diseases = tob_disease_names, -#' show_progress = TRUE -#' ) -#' -#' -#' ############################# -#' ## TOBACCO AND ALCOHOL -#' -#' -RRFunc <- function( - data, - substance = c("tob", "alc", "tobalc"), - k_year = NULL, - alc_diseases = c("Pharynx", "Oral_cavity"), - alc_mort_and_morb = c("Ischaemic_heart_disease", "LiverCirrhosis"), - alc_risk_lags = TRUE, - alc_indiv_risk_trajectories_store = NULL, - alc_protective = TRUE, - alc_wholly_chronic_thresholds = c(6, 8), - alc_wholly_acute_thresholds = c(6, 8), - grams_ethanol_per_unit = 8, - tob_diseases = c("Pharynx", "Oral_cavity"), - tob_include_risk_in_former_smokers = TRUE, - tobalc_include_int = FALSE, - tobalc_int_data = NULL, - show_progress = FALSE -) { - - - data <- copy(data) - - # Organise disease lists - - if(substance == "alc") { - # For the diseases that have separate risk functions for mortality and morbidity - # expand the list of diseases so that the mortality and morbidity versions - # are included as separate variables - - # Set the default as mortality - # and mark the additions to the disease list with the postscript "_morb" - alc_diseases <- c(alc_diseases, paste0(alc_mort_and_morb, "_morb")) - diseases <- alc_diseases - } - if(substance == "tob") { - diseases <- tob_diseases - } - if(substance == "tobalc") { - diseases <- union(alc_diseases, tob_diseases) - mort_and_morb_diseases <- union(alc_mort_and_morb, diseases) - diseases <- c(diseases, paste0(mort_and_morb_diseases, "_morb")) - } - - dn <- length(diseases) - - message(paste0("\t\tCalculating risk for ", dn, " conditions")) - - for (i in 1:dn) { - - d <- as.character(diseases[i]) - - if(isTRUE(show_progress)) message(paste0("\t\t\t", d, " ", round(100 * i / dn, 0), "%")) - - ############################################################# - # Relative risks - alcohol - - if(d %in% alc_diseases & substance %in% c("alc", "tobalc")) { - - # Calculate the parameters of the binge model - based on average weekly consumption - data <- tobalcepi::AlcBinge(data) - - # Convert units to grams of alcohol / truncate - data[ , GPerDay := weekmean * (grams_ethanol_per_unit / 7)] - data[GPerDay >= 150, GPerDay := 150] - data[ , peakday_grams := peakday * grams_ethanol_per_unit] - - # Setup names of temporary variables - d_alc <- paste0(d, "_alc") - d_alc_adj <- paste0(d, "_alc_adj") - - alc_mort_or_morb <- ifelse(stringr::str_detect(d, "_morb"), "morb", "mort") - - # Apply function that computes each individual's relative risk for a condition - data[ , (d_alc) := tobalcepi::RRalc( - data = data, - disease = d, - mort_or_morb = alc_mort_or_morb, - protective = alc_protective, - alc_wholly_chronic_thresholds = alc_wholly_acute_thresholds * grams_ethanol_per_unit, - alc_wholly_acute_thresholds = alc_wholly_acute_thresholds * grams_ethanol_per_unit - )] - - # Remove the variables that give alcohol consumption in grams - data[ , `:=`(GPerDay = NULL, peakday_grams = NULL)] - - if(isTRUE(alc_risk_lags) & !is.null(alc_indiv_risk_trajectories_store)) { - - # For the individuals present in the population sample for the current year, - # add the relative risks for the current year - # to the trajectories of past relative risks that have been stored for each individual - indiv_risk_trajectories_alc <- rbindlist(list( - data[ , c("ran_id", "year", d_alc), with = F], # current alcohol risks - alc_indiv_risk_trajectories_store[ran_id %in% data[ , ran_id], c("ran_id", "year", d_alc), with = F] # past relative risk trajectories - ), use.names = T) - - # Calculate the time differences to the current year - indiv_risk_trajectories_alc[ , years_since_change := year - k_year + 2] - indiv_risk_trajectories_alc[years_since_change > 20, years_since_change := 20] - - # Merge into the data the proportional reduction in relative risk - # according to the time since alcohol consumption changed - # Matching on the time difference to the current year - indiv_risk_trajectories_alc <- merge( - indiv_risk_trajectories_alc, # the individual trajectories of relative risk - tobalcepi::AlcLags(d), # the proportional reductions in relative risk - by = c("years_since_change"), all.x = T, all.y = F, sort = F) - - # Adjust the relative risk for the current year - # to take into account the individual's past trajectory of relative risk - # The adjusted relative risk for the current year is a weighted average of - # the relative risks for all past years for which the individual was tracked - # where the weights are the expected proportional reduction in risk - # which means that the relative risk for the current year always has the lowest weight - # reflecting the lagged link between current consumption and relative risk - indiv_risk_trajectories_alc_adjusted <- indiv_risk_trajectories_alc[ , - .(rr_adj = sum(get(d_alc) * (1 + prop_risk_reduction), na.rm = T) / sum(1 + prop_risk_reduction, na.rm = T)), - by = "ran_id"] - - # Remove the unadjusted relative risks from the data - data[ , (d_alc) := NULL] - - # Assign the adjusted relative risk the appropriate disease-specific name - setnames(indiv_risk_trajectories_alc_adjusted, "rr_adj", d_alc) - - # Marge the adjused relative risks into the data - data <- merge( - data, - indiv_risk_trajectories_alc_adjusted[ , c("ran_id", d_alc), with = F], - by = "ran_id", sort = F) - - } - - # If the relative risk for alcohol does not need to feed forward - # into a further calculation of joint relative risk for the disease being considered, - # then the temporary name can be changed to be just the name of disease - if(substance == "alc" | (substance == "tobalc" & !(d %in% intersect(alc_diseases, tob_diseases)))) { - data[ , (d) := get(d_alc)] - } - - } - - ############################################################# - # Relative risks - tobacco - - if(d %in% tob_diseases & substance %in% c("tob", "tobalc")) { - - # Setup names of temporary variables - d_tob <- paste0(d, "_tob") - d_tob_temp <- paste0(d, "_tob_temp") - - # Apply function that computes each individual's relative risk for a condition - # Note - this applies the risk associated with current smoking to current and former smokers - # to prepare for the later step in the calculation where the risk in former smokers - # is adjusted to account for the decline in risk by time since quitting - data[, (d_tob_temp) := tobalcepi::RRtob( - data = data, - disease = d # the name of the disease - )] - - # After someone has been quit for 40 years, assume their risk is the same as a never smoker - data[time_since_quit > 40, time_since_quit := 40] - - # Merge the proportional reduction in risk among former smokers into the data - # Matching on the time since quit - data <- merge( - data, - tobalcepi::TobLags(d), - by = c("time_since_quit"), all.x = T, all.y = F, sort = F) - - data[is.na(prop_risk_reduction), prop_risk_reduction := 0L] - - # Calculate the relative risk for former smokers - # by scaling the relative risk for current smokers for the change in risk expected - # for each former smoker's number of years since quitting - data[ , (d_tob) := (1 + (get(d_tob_temp) - 1) * (1 - prop_risk_reduction))] - - data[ , prop_risk_reduction := NULL] - data[ , (d_tob_temp) := NULL] - - # If we don't want to consider the residual risks in former smokers, - # then set the relative risks in former smokers to 1 i.e. the same as never smokers - if(!isTRUE(tob_include_risk_in_former_smokers)) { - data[smk.state == "former", (d_tob) := 1] - } - - data[is.na(get(d_tob)), (d_tob) := 1] - - # If the relative risk for alcohol does not need to feed forward - # into a further calculation of joint relative risk for the disease being considered, - # then the temporary name can be changed to be just the name of disease - if(substance == "tob" | (substance == "tobalc" & !(d %in% intersect(alc_diseases, tob_diseases)))) { - setnames(data, d_tob, d) - } - - } - - ############################################################# - # Relative risks - tobacco and alcohol - - if(d %in% intersect(alc_diseases, tob_diseases) & substance == "tobalc") { - - if(isTRUE(tobalc_include_int)) { - - # Synergy index - d_si <- paste0(d, "_si") - - data[ , (d_si) := tobalcepi::TobAlcInt( - condition_TobAlcInt = d, - cons_alc_TobAlcInt = "weekmean", - cons_tob_TobAlcInt = "smk.state", - rr.data_TobAlcInt = tobalc_int_data, - data_TobAlcInt = data - )] - - data[ , (d) := (1 + ((get(d_alc) - 1) + (get(d_tob) - 1)) * get(d_si))] - - data[ , (d_si) := NULL] - - } else { - - data[ , (d) := 1 + ((get(d_alc) - 1) + (get(d_tob) - 1))] - - } - - #data[ , (d_alc) := NULL] - data[ , (d_tob) := NULL] - - } - - if(isTRUE(show_progress)) message("\t\t\t\tdone") - - } - - - - ############################################################# - # Store relative risks for alcohol for the current year - - if(stringr::str_detect(substance, "alc")) { - - if(isTRUE(alc_risk_lags)) { - - if(is.null(alc_indiv_risk_trajectories_store)) { - - # If the first year, then create the storage data table - alc_indiv_risk_trajectories_store <- copy(data[ , c("ran_id", "year", paste0(alc_diseases, "_alc")), with = F]) - - } else { - - # Otherwise append the relative risks for the current year to the stored data table - alc_indiv_risk_trajectories_store <- rbindlist(list( - alc_indiv_risk_trajectories_store, - copy(data[ , c("ran_id", "year", paste0(alc_diseases, "_alc")), with = F]) - ), use.names = T) - - } - } - - # After storing, remove unadjusted alcohol relative risks for the current year - data <- data[ , colnames(data)[sapply(colnames(data), function(x) !stringr::str_detect(x, "_alc"))], with = F] - - } - - - # Outputs - - if(is.null(alc_indiv_risk_trajectories_store)) { - return(copy(data)) - } else { - - return(list( - data_plus_rr = copy(data), - new_alc_indiv_risk_trajectories_store = alc_indiv_risk_trajectories_store - )) - } -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +#' Individual relative risks of disease +#' +#' This function takes a sample of individuals and computes each individual's relative risk +#' for each disease according to their current tobacco and alcohol consumption. There is an option to tailor this +#' to the alcohol only, tobacco only, or joint tobacco and alcohol contexts. +#' +#' ALCOHOL +#' +#' For alcohol, the relative risk for each individual for each disease is calculated based on their average weekly alcohol consumption. +#' For diseases that have separate mortality and morbidity risk functions, separate variables are created containing +#' the relative risks for each for the same disease. +#' Individuals are not recorded as being former drinkers -- instead their alcohol consumption just falls to zero and their +#' relative risk for disease changes accordingly. +#' +#' Alcohol lags: +#' +#' To account for the lagged effects of individual drinking history on their +#' current risk of disease, we add memory by storing each individual's past trajectory of their relative risk for each disease. +#' In the model, the current relative risk is then adjusted to take account of each individual's stored drinking histories - +#' this adjustment takes the form of a weighted average of current and past relative risk where the weights are proportional to +#' the disease specific lag function that describes the gradual emergence of an effect of changed consumption on risk over time. +#' This uses a slightly different method to SAPM. +#' +#' TOBACCO +#' +#' For tobacco, the relative risk for each individual is calculated based on whether they are a current, former or never smoker. +#' Currently, all current smokers have the same relative risk regardless of the amount they currently smoke or have smoked in the past. +#' +#' Tobacco lags: +#' +#' Former smokers are initially given the relative risk associated with current smokers, which we then scale according to a disease-specific +#' function that describes how risk declines after quitting smoking. +#' +#' ALCOHOL AND TOBACCO +#' +#' If both tobacco and alcohol are being considered in a joint model, +#' we combine the relative risks for current drinkers and smokers. For oral, pharyngeal, laryngeal and oesophageal cancers we also +#' have the option of scaling the joint risks by a 'synergy index', which takes the result of a meta-analysis of the additional +#' risk faced by people because they consume both tobacco and alcohol. +#' +#' @param data Data table of individual characteristics - this function uses current smoking and drinking status/amount. +#' @param substance Whether to compute relative risks for just alcohol ("alc"), +#' just tobacco ("tob") or joint risks for tobacco and alcohol ("tobalc"). +#' @param k_year Integer giving the current year of the simulation. +#' @param alc_diseases Character vector of alcohol related diseases. +#' @param alc_mort_and_morb Character vector of alcohol related diseases that have separate risk functions for +#' mortality and morbidity. +#' @param alc_risk_lags Logical - should each individual's relative risks for alcohol be lagged according to +#' their past trajectory of relative risks. Defaults to FALSE. This should only be set to TRUE for a model run that simulates individual trajctories, +#' and should be FALSE if used as part of the current method for calculating attributable fractions. +#' @param alc_indiv_risk_trajectories_store Data table that stores the individual history of relative risks for alcohol related diseases. +#' @param alc_protective Logical - whether to include the protective effects of +#' alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1. +#' @param alc_wholly_chronic_thresholds Numeric vector - the thresholds in units/week over +#' which individuals begin to experience an elevated risk +#' for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female). +#' @param alc_wholly_acute_thresholds Numeric vector - the thresholds in units/day over +#' which individuals begin to experience an elevated risk +#' for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female). +#' @param grams_ethanol_per_unit Numeric value giving the conversion factor for the number of grams of pure +#' ethanol in one UK standard unit of alcohol. +#' @param tob_diseases Character vector of tobacco related diseases. +#' @param tob_include_risk_in_former_smokers Logical - whether the residual risks of smoking in former smokers +#' should be considered (defaults to TRUE). +#' @param tobalc_include_int Logical - in computing joint relative risks for tobacco and alcohol, +#' should a (synergystic/multiplicative) interaction between exposure to tobacco and alcohol be included. +#' Defaults to FALSE. If TRUE, then only interactive effects for oesophageal, pharynx, oral cavity and larynx cancers +#' are considered. +#' @param tobalc_int_data Data table containing the disease-specific interactions between tobacco and alcohol. +#' @param show_progress Logical - Should the progress of the loop through diseases be shown. Defaults to FALSE. +#' +#' @return Two data tables are returned: +#' \itemize{ +#' \item "data_plus_rr" is a copy of "data" with added columns that give each +#' individual's relative risk for each disease. +#' \item "new_alc_indiv_risk_trajectories_store" is a copy of "alc_indiv_risk_trajectories_store" with +#' the relative risks for the current year added to the store. +#' } +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' \dontrun{ +#' ############################# +#' ## ALCOHOL +#' +#' # Simulate individual data +#' +#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 +#' n <- 1e4 +#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) +#' +#' # Note: the socioeconomic and other variables are needed for the binge model +#' +#' data <- data.table( +#' year = 2016, +#' weekmean = grams_ethanol_day * 7 / 8, +#' peakday = 2 * grams_ethanol_day / 8, +#' age = rpois(n, 30), +#' sex = sample(x = c("Male", "Female"), size = n, replace = T), +#' income5cat = "1_lowest income", +#' imd_quintile = "5_most_deprived", +#' kids = "0", +#' social_grade = "C2DE", +#' eduend4cat = "16-18", # age finished education +#' ethnic2cat = "white", # white / non-white +#' employ2cat = "yes", # employed / not +#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg +#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m +#' ) +#' +#' # Add individual ids to the data +#' data <- MakeSeeds(data, n = 0) +#' +#' # Disease names +#' alc_disease_names <- c( +#' "Pharynx", +#' "Ischaemic_heart_disease", +#' "LiverCirrhosis", +#' "Transport_injuries", +#' "Alcohol_poisoning", +#' "Alcoholic_gastritis" +#' ) +#' +#' test_data <- copy(data) +#' +#' test_data1 <- RRFunc( +#' data = test_data, +#' substance = "alc", +#' k_year = 2017, +#' alc_diseases = alc_disease_names, +#' alc_indiv_risk_trajectories_store = NULL, +#' alc_wholly_chronic_thresholds = c(2, 2), +#' alc_wholly_acute_thresholds = c(3, 3), +#' show_progress = TRUE +#' ) +#' +#' test_data1 +#' +#' test_data <- copy(data) +#' test_data[ , year := 2017] +#' +#' test_data2 <- RRFunc( +#' data = test_data, +#' substance = "alc", +#' k_year = 2018, +#' alc_diseases = alc_disease_names, +#' alc_indiv_risk_trajectories_store = test_data1$new_alc_indiv_risk_trajectories_store, +#' alc_wholly_chronic_thresholds = c(2, 2), +#' alc_wholly_acute_thresholds = c(3, 3), +#' show_progress = TRUE +#' ) +#' +#' test_data2 +#' +#' +#' ############################# +#' ## TOBACCO +#' +#' tob_disease_names <- c( +#' "Pharynx", +#' "Chronic_obstructive_pulmonary_disease", +#' "Ischaemic_heart_disease", +#' "Lung", +#' "Influenza_clinically_diagnosed", +#' "Diabetes", +#' "Schizophrenia" +#' ) +#' +#' n <- 1e4 +#' +#' data <- data.table( +#' smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), +#' time_since_quit = sample(x = 0:40, size = n, replace = T), +#' age = rpois(n, 30), +#' sex = sample(x = c("Male", "Female"), size = n, replace = T) +#' ) +#' +#' data[smk.state != "former", time_since_quit := NA] +#' +#' # Tobacco relative risks for Pharygeal cancer +#' RRFunc( +#' data = data, +#' substance = "tob", +#' tob_diseases = tob_disease_names, +#' show_progress = TRUE +#' ) +#' +#' +#' ############################# +#' ## TOBACCO AND ALCOHOL +#' +#' } +RRFunc <- function( + data, + substance = c("tob", "alc", "tobalc"), + k_year = NULL, + alc_diseases = c("Pharynx", "Oral_cavity"), + alc_mort_and_morb = c("Ischaemic_heart_disease", "LiverCirrhosis"), + alc_risk_lags = TRUE, + alc_indiv_risk_trajectories_store = NULL, + alc_protective = TRUE, + alc_wholly_chronic_thresholds = c(6, 8), + alc_wholly_acute_thresholds = c(6, 8), + grams_ethanol_per_unit = 8, + tob_diseases = c("Pharynx", "Oral_cavity"), + tob_include_risk_in_former_smokers = TRUE, + tobalc_include_int = FALSE, + tobalc_int_data = NULL, + show_progress = FALSE +) { + + + data <- copy(data) + + # Organise disease lists + + if(substance == "alc") { + # For the diseases that have separate risk functions for mortality and morbidity + # expand the list of diseases so that the mortality and morbidity versions + # are included as separate variables + + # Set the default as mortality + # and mark the additions to the disease list with the postscript "_morb" + alc_diseases <- c(alc_diseases, paste0(alc_mort_and_morb, "_morb")) + diseases <- alc_diseases + } + if(substance == "tob") { + diseases <- tob_diseases + } + if(substance == "tobalc") { + diseases <- union(alc_diseases, tob_diseases) + mort_and_morb_diseases <- union(alc_mort_and_morb, diseases) + diseases <- c(diseases, paste0(mort_and_morb_diseases, "_morb")) + } + + dn <- length(diseases) + + message(paste0("\t\tCalculating risk for ", dn, " conditions")) + + for (i in 1:dn) { + + d <- as.character(diseases[i]) + + if(isTRUE(show_progress)) message(paste0("\t\t\t", d, " ", round(100 * i / dn, 0), "%")) + + ############################################################# + # Relative risks - alcohol + + if(d %in% alc_diseases & substance %in% c("alc", "tobalc")) { + + # Calculate the parameters of the binge model - based on average weekly consumption + data <- tobalcepi::AlcBinge(data) + + # Convert units to grams of alcohol / truncate + data[ , GPerDay := weekmean * (grams_ethanol_per_unit / 7)] + data[GPerDay >= 150, GPerDay := 150] + data[ , peakday_grams := peakday * grams_ethanol_per_unit] + + # Setup names of temporary variables + d_alc <- paste0(d, "_alc") + d_alc_adj <- paste0(d, "_alc_adj") + + alc_mort_or_morb <- ifelse(stringr::str_detect(d, "_morb"), "morb", "mort") + + # Apply function that computes each individual's relative risk for a condition + data[ , (d_alc) := tobalcepi::RRalc( + data = data, + disease = d, + mort_or_morb = alc_mort_or_morb, + protective = alc_protective, + alc_wholly_chronic_thresholds = alc_wholly_acute_thresholds * grams_ethanol_per_unit, + alc_wholly_acute_thresholds = alc_wholly_acute_thresholds * grams_ethanol_per_unit + )] + + # Remove the variables that give alcohol consumption in grams + data[ , `:=`(GPerDay = NULL, peakday_grams = NULL)] + + if(isTRUE(alc_risk_lags) & !is.null(alc_indiv_risk_trajectories_store)) { + + # For the individuals present in the population sample for the current year, + # add the relative risks for the current year + # to the trajectories of past relative risks that have been stored for each individual + indiv_risk_trajectories_alc <- data.table::rbindlist(list( + data[ , c("ran_id", "year", d_alc), with = F], # current alcohol risks + alc_indiv_risk_trajectories_store[ran_id %in% data[ , ran_id], c("ran_id", "year", d_alc), with = F] # past relative risk trajectories + ), use.names = T) + + # Calculate the time differences to the current year + indiv_risk_trajectories_alc[ , years_since_change := year - k_year + 2] + indiv_risk_trajectories_alc[years_since_change > 20, years_since_change := 20] + + # Merge into the data the proportional reduction in relative risk + # according to the time since alcohol consumption changed + # Matching on the time difference to the current year + indiv_risk_trajectories_alc <- merge( + indiv_risk_trajectories_alc, # the individual trajectories of relative risk + tobalcepi::AlcLags(d), # the proportional reductions in relative risk + by = c("years_since_change"), all.x = T, all.y = F, sort = F) + + # Adjust the relative risk for the current year + # to take into account the individual's past trajectory of relative risk + # The adjusted relative risk for the current year is a weighted average of + # the relative risks for all past years for which the individual was tracked + # where the weights are the expected proportional reduction in risk + # which means that the relative risk for the current year always has the lowest weight + # reflecting the lagged link between current consumption and relative risk + indiv_risk_trajectories_alc_adjusted <- indiv_risk_trajectories_alc[ , + .(rr_adj = sum(get(d_alc) * (1 + prop_risk_reduction), na.rm = T) / sum(1 + prop_risk_reduction, na.rm = T)), + by = "ran_id"] + + # Remove the unadjusted relative risks from the data + data[ , (d_alc) := NULL] + + # Assign the adjusted relative risk the appropriate disease-specific name + data.table::setnames(indiv_risk_trajectories_alc_adjusted, "rr_adj", d_alc) + + # Marge the adjused relative risks into the data + data <- merge( + data, + indiv_risk_trajectories_alc_adjusted[ , c("ran_id", d_alc), with = F], + by = "ran_id", sort = F) + + } + + # If the relative risk for alcohol does not need to feed forward + # into a further calculation of joint relative risk for the disease being considered, + # then the temporary name can be changed to be just the name of disease + if(substance == "alc" | (substance == "tobalc" & !(d %in% intersect(alc_diseases, tob_diseases)))) { + data[ , (d) := get(d_alc)] + } + + } + + ############################################################# + # Relative risks - tobacco + + if(d %in% tob_diseases & substance %in% c("tob", "tobalc")) { + + # Setup names of temporary variables + d_tob <- paste0(d, "_tob") + d_tob_temp <- paste0(d, "_tob_temp") + + # Apply function that computes each individual's relative risk for a condition + # Note - this applies the risk associated with current smoking to current and former smokers + # to prepare for the later step in the calculation where the risk in former smokers + # is adjusted to account for the decline in risk by time since quitting + data[, (d_tob_temp) := tobalcepi::RRtob( + data = data, + disease = d # the name of the disease + )] + + # After someone has been quit for 40 years, assume their risk is the same as a never smoker + data[time_since_quit > 40, time_since_quit := 40] + + # Merge the proportional reduction in risk among former smokers into the data + # Matching on the time since quit + data <- merge( + data, + tobalcepi::TobLags(d), + by = c("time_since_quit"), all.x = T, all.y = F, sort = F) + + data[is.na(prop_risk_reduction), prop_risk_reduction := 0L] + + # Calculate the relative risk for former smokers + # by scaling the relative risk for current smokers for the change in risk expected + # for each former smoker's number of years since quitting + data[ , (d_tob) := (1 + (get(d_tob_temp) - 1) * (1 - prop_risk_reduction))] + + data[ , prop_risk_reduction := NULL] + data[ , (d_tob_temp) := NULL] + + # If we don't want to consider the residual risks in former smokers, + # then set the relative risks in former smokers to 1 i.e. the same as never smokers + if(!isTRUE(tob_include_risk_in_former_smokers)) { + data[smk.state == "former", (d_tob) := 1] + } + + data[is.na(get(d_tob)), (d_tob) := 1] + + # If the relative risk for alcohol does not need to feed forward + # into a further calculation of joint relative risk for the disease being considered, + # then the temporary name can be changed to be just the name of disease + if(substance == "tob" | (substance == "tobalc" & !(d %in% intersect(alc_diseases, tob_diseases)))) { + data.table::setnames(data, d_tob, d) + } + + } + + ############################################################# + # Relative risks - tobacco and alcohol + + if(d %in% intersect(alc_diseases, tob_diseases) & substance == "tobalc") { + + if(isTRUE(tobalc_include_int)) { + + # Synergy index + d_si <- paste0(d, "_si") + + data[ , (d_si) := tobalcepi::TobAlcInt( + condition_TobAlcInt = d, + cons_alc_TobAlcInt = "weekmean", + cons_tob_TobAlcInt = "smk.state", + rr.data_TobAlcInt = tobalc_int_data, + data_TobAlcInt = data + )] + + data[ , (d) := (1 + ((get(d_alc) - 1) + (get(d_tob) - 1)) * get(d_si))] + + data[ , (d_si) := NULL] + + } else { + + data[ , (d) := 1 + ((get(d_alc) - 1) + (get(d_tob) - 1))] + + } + + #data[ , (d_alc) := NULL] + data[ , (d_tob) := NULL] + + } + + if(isTRUE(show_progress)) message("\t\t\t\tdone") + + } + + + + ############################################################# + # Store relative risks for alcohol for the current year + + if(stringr::str_detect(substance, "alc")) { + + if(isTRUE(alc_risk_lags)) { + + if(is.null(alc_indiv_risk_trajectories_store)) { + + # If the first year, then create the storage data table + alc_indiv_risk_trajectories_store <- data.table::copy(data[ , c("ran_id", "year", paste0(alc_diseases, "_alc")), with = F]) + + } else { + + # Otherwise append the relative risks for the current year to the stored data table + alc_indiv_risk_trajectories_store <- data.table::rbindlist(list( + alc_indiv_risk_trajectories_store, + data.table::copy(data[ , c("ran_id", "year", paste0(alc_diseases, "_alc")), with = F]) + ), use.names = T) + + } + } + + # After storing, remove unadjusted alcohol relative risks for the current year + data <- data[ , colnames(data)[sapply(colnames(data), function(x) !stringr::str_detect(x, "_alc"))], with = F] + + } + + + # Outputs + + if(is.null(alc_indiv_risk_trajectories_store)) { + return(data.table::copy(data)) + } else { + + return(list( + data_plus_rr = data.table::copy(data), + new_alc_indiv_risk_trajectories_store = alc_indiv_risk_trajectories_store + )) + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/R/RRTobDR.R b/R/RRTobDR.R index abb6bbf..eb257fe 100644 --- a/R/RRTobDR.R +++ b/R/RRTobDR.R @@ -14,6 +14,7 @@ #' average number of daily cigarettes. #' #' @return Returns a numeric vector of each individual's relative risks for the tobacco related disease specified by "disease". +#' @importFrom data.table := setDT setnames #' @export #' #' @examples diff --git a/R/RRtob.R b/R/RRtob.R index 9cda524..ba8a297 100644 --- a/R/RRtob.R +++ b/R/RRtob.R @@ -1,207 +1,208 @@ - -#' Tobacco relative risks -#' -#' Relative risks for current vs. never cigarette smokers. -#' -#' We focus on the risks of current smoking and limit ourselves to diseases that affect the consumer themselves e.g. -#' excluding secondary effects of smoking on children. -#' We assume the equivalence of relative risks and odds ratios. -#' Our starting point was the Royal College of Physician's (RCP) report "Hiding in plain sight: -#' Treating tobacco dependency in the NHS", -#' which reviewed smoking-disease associations to produce an updated list of diseases that are caused -#' by smoking and updated risk sources. -#' We mainly keep to the RCP report's disease list and risk functions, with any deviations from the RCP list -#' and risk sources being for one of two reasons: -#' \itemize{ -#' \item{There are often slightly conflicting ICD-10 code definitions used for some diseases and -#' we have sought to harmonise these consistently across both tobacco and alcohol, -#' based on the Sheffield Alcohol Policy Model (SAPM) v4.0 disease list;} -#' \item{Since publication of the RCP report, Cancer Research UK (CRUK) produced their own disease -#' list and risk sources for cancers attributable to modifiable risk factors, -#' including tobacco and alcohol. -#' Discussions with CRUK shaped the disease definitions in our updated Sheffield disease list for alcohol. -#' Where there are differences in the risk sources used in the RCP report and CRUK's work, -#' we take the estimate that matches most closely to our disease definitions, or the more recent estimate.} -#' } -#' -#' @param data Data table of individual characteristics. -#' @param disease Character - the name of the disease for which the relative risks will be computed. -#' @param smoker_status_var Character - the name of the variable containing whether an individual is -#' a current, former or never smoker. -#' @param sex_var Character - the name of the variable containing individual sex. -#' @param age_var Character - the name of the variable containing individual age in single years. -#' @param rr_data Data table containing the relative risks of current vs. never smokers. -#' The data table "tobacco_relative_risks" is embedded within the stapmr package. -#' -#' @return Returns a numeric vector of each individual's relative risks for the tobacco-related disease -#' specified by "disease". -#' @export -#' -#' @examples -#' -#' # Example data -#' -#' n <- 1e2 -#' -#' data <- data.table( -#' smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), -#' sex = "Female", -#' age = 30 -#' ) -#' -#' # Apply the function -#' test <- RRtob( -#' data, -#' disease = "Pharynx" -#' ) -#' -RRtob <- function( - data, - disease = "Pharynx", - smoker_status_var = "smk.state", - sex_var = "sex", - age_var = "age", - rr_data = tobalcepi::tobacco_relative_risks -) { - - # Check that zero risk is specified as 1 - rr_data[relative_risk == 0, relative_risk := 1] - - # Select the relative risks for the focal disease - rr <- rr_data[condition == disease] - - # Select the consumption, age and sex columns - data_temp <- copy(data[ , .(x = get(smoker_status_var), sex = get(sex_var), age = get(age_var))]) - - data_temp[ , ageband := c( - "<35", - "35-44", - "45-54", - "55-64", - "65-74", - "75+")[findInterval(age, c(-1, 35, 45, 55, 65, 75))]] - - # As default return 1. - data_temp[ , rr_indiv := 1] - - ####################################### - # Diseases where risk differs by sex and age (35-64, 65+) - str3 <- c("Ischaemic_heart_disease") - - if(disease %in% str3) { - - # Assign risks for current smokers - - data_temp[x == "current" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Male", - rr_indiv := rr[sex == "Male" & age == "35-64", relative_risk]] - - data_temp[x == "current" & ageband %in% c("65-74", "75+") & sex == "Male", - rr_indiv := rr[sex == "Male" & age == "65+", relative_risk]] - - data_temp[x == "current" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Female", - rr_indiv := rr[sex == "Female" & age == "35-64", relative_risk]] - - data_temp[x == "current" & ageband %in% c("65-74", "75+") & sex == "Female", - rr_indiv := rr[sex == "Female" & age == "65+", relative_risk]] - - # Also assign the risks for current smoking to former smokers - # as the risk for former smokers will subsequently be reduced according to the number of years - # since these former smokers quit - - data_temp[x == "former" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Male", - rr_indiv := rr[sex == "Male" & age == "35-64", relative_risk]] - - data_temp[x == "former" & ageband %in% c("65-74", "75+") & sex == "Male", - rr_indiv := rr[sex == "Male" & age == "65+", relative_risk]] - - data_temp[x == "former" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Female", - rr_indiv := rr[sex == "Female" & age == "35-64", relative_risk]] - - data_temp[x == "former" & ageband %in% c("65-74", "75+") & sex == "Female", - rr_indiv := rr[sex == "Female" & age == "65+", relative_risk]] - - } - - ####################################### - # Diseases where risk differs by sex only - str4 <- c( - - "Haemorrhagic_Stroke", - "Ischaemic_Stroke", - - "Oral_cavity", - "Pharynx", - "Lung", - "Nasopharynx_sinonasal", - "Larynx", - "Oesophageal_AC", - "Oesophageal_SCC", - "Stomach", - "Pancreas", - "Liver", - "Colorectal", - "Kidney", - "Lower_urinary_tract", - "Bladder", - "Cervical", - "Acute_myeloid_leukaemia", - - "Peripheral_arterial_disease", - "Abdominal_aortic_aneurysm", - "Venous_thromboembolism", - "Chronic_obstructive_pulmonary_disease", - "Asthma", - "Tuberculosis", - "Obstructive_sleep_apnoea", - "Pneumonia", - "Influenza_clinically_diagnosed", - "Influenza_microbiologically_confirmed", - "Diabetes", - "Alzheimers_disease", - "Vascular_dementia", - "All_cause_dementia", - "Depression", - "Schizophrenia", - "Multiple_sclerosis", - "Systematic_lupus_erythematosis", - "Low_back_pain", - "Psoriasis", - "Age_related_macular_degeneration", - "Crohns_disease", - "Hip_fracture", - "Idiopathic_pulmonary_fibrosis", - "Rheumatoid_arthritis", - "Chronic_Kidney_disease", - "End_stage_renal_disease", - "Senile_cataract", - "Bulimia", - "Hearing_loss", - "Psychosis", - - "Ulcerative_colitis", - "Parkinson" - ) - - if(disease %in% str4) { - - # Assign risks for current smokers - - data_temp[x == "current" & sex == "Female", rr_indiv := rr[sex == "Female", relative_risk]] - data_temp[x == "current" & sex == "Male", rr_indiv := rr[sex == "Male", relative_risk]] - - # Also assign the risks for current smoking to former smokers - # as the risk for former smokers will subsequently be reduced according to the number of years - # since these former smokers quit - - data_temp[x == "former" & sex == "Female", rr_indiv := rr[sex == "Female", relative_risk]] - data_temp[x == "former" & sex == "Male", rr_indiv := rr[sex == "Male", relative_risk]] - - } - - -# Output a vector containing the relative risks for each individual -return(data_temp[ , rr_indiv]) -} - - - + +#' Tobacco relative risks +#' +#' Relative risks for current vs. never cigarette smokers. +#' +#' We focus on the risks of current smoking and limit ourselves to diseases that affect the consumer themselves e.g. +#' excluding secondary effects of smoking on children. +#' We assume the equivalence of relative risks and odds ratios. +#' Our starting point was the Royal College of Physician's (RCP) report "Hiding in plain sight: +#' Treating tobacco dependency in the NHS", +#' which reviewed smoking-disease associations to produce an updated list of diseases that are caused +#' by smoking and updated risk sources. +#' We mainly keep to the RCP report's disease list and risk functions, with any deviations from the RCP list +#' and risk sources being for one of two reasons: +#' \itemize{ +#' \item{There are often slightly conflicting ICD-10 code definitions used for some diseases and +#' we have sought to harmonise these consistently across both tobacco and alcohol, +#' based on the Sheffield Alcohol Policy Model (SAPM) v4.0 disease list;} +#' \item{Since publication of the RCP report, Cancer Research UK (CRUK) produced their own disease +#' list and risk sources for cancers attributable to modifiable risk factors, +#' including tobacco and alcohol. +#' Discussions with CRUK shaped the disease definitions in our updated Sheffield disease list for alcohol. +#' Where there are differences in the risk sources used in the RCP report and CRUK's work, +#' we take the estimate that matches most closely to our disease definitions, or the more recent estimate.} +#' } +#' +#' @param data Data table of individual characteristics. +#' @param disease Character - the name of the disease for which the relative risks will be computed. +#' @param smoker_status_var Character - the name of the variable containing whether an individual is +#' a current, former or never smoker. +#' @param sex_var Character - the name of the variable containing individual sex. +#' @param age_var Character - the name of the variable containing individual age in single years. +#' @param rr_data Data table containing the relative risks of current vs. never smokers. +#' The data table "tobacco_relative_risks" is embedded within the stapmr package. +#' +#' @return Returns a numeric vector of each individual's relative risks for the tobacco-related disease +#' specified by "disease". +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#'\dontrun{ +#' # Example data +#' +#' n <- 1e2 +#' +#' data <- data.table( +#' smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), +#' sex = "Female", +#' age = 30 +#' ) +#' +#' # Apply the function +#' test <- RRtob( +#' data, +#' disease = "Pharynx" +#' ) +#'} +RRtob <- function( + data, + disease = "Pharynx", + smoker_status_var = "smk.state", + sex_var = "sex", + age_var = "age", + rr_data = tobalcepi::tobacco_relative_risks +) { + + # Check that zero risk is specified as 1 + rr_data[relative_risk == 0, relative_risk := 1] + + # Select the relative risks for the focal disease + rr <- rr_data[condition == disease] + + # Select the consumption, age and sex columns + data_temp <- data.table::copy(data[ , .(x = get(smoker_status_var), sex = get(sex_var), age = get(age_var))]) + + data_temp[ , ageband := c( + "<35", + "35-44", + "45-54", + "55-64", + "65-74", + "75+")[findInterval(age, c(-1, 35, 45, 55, 65, 75))]] + + # As default return 1. + data_temp[ , rr_indiv := 1] + + ####################################### + # Diseases where risk differs by sex and age (35-64, 65+) + str3 <- c("Ischaemic_heart_disease") + + if(disease %in% str3) { + + # Assign risks for current smokers + + data_temp[x == "current" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Male", + rr_indiv := rr[sex == "Male" & age == "35-64", relative_risk]] + + data_temp[x == "current" & ageband %in% c("65-74", "75+") & sex == "Male", + rr_indiv := rr[sex == "Male" & age == "65+", relative_risk]] + + data_temp[x == "current" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Female", + rr_indiv := rr[sex == "Female" & age == "35-64", relative_risk]] + + data_temp[x == "current" & ageband %in% c("65-74", "75+") & sex == "Female", + rr_indiv := rr[sex == "Female" & age == "65+", relative_risk]] + + # Also assign the risks for current smoking to former smokers + # as the risk for former smokers will subsequently be reduced according to the number of years + # since these former smokers quit + + data_temp[x == "former" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Male", + rr_indiv := rr[sex == "Male" & age == "35-64", relative_risk]] + + data_temp[x == "former" & ageband %in% c("65-74", "75+") & sex == "Male", + rr_indiv := rr[sex == "Male" & age == "65+", relative_risk]] + + data_temp[x == "former" & ageband %in% c("<35", "35-44", "45-54", "55-64") & sex == "Female", + rr_indiv := rr[sex == "Female" & age == "35-64", relative_risk]] + + data_temp[x == "former" & ageband %in% c("65-74", "75+") & sex == "Female", + rr_indiv := rr[sex == "Female" & age == "65+", relative_risk]] + + } + + ####################################### + # Diseases where risk differs by sex only + str4 <- c( + + "Haemorrhagic_Stroke", + "Ischaemic_Stroke", + + "Oral_cavity", + "Pharynx", + "Lung", + "Nasopharynx_sinonasal", + "Larynx", + "Oesophageal_AC", + "Oesophageal_SCC", + "Stomach", + "Pancreas", + "Liver", + "Colorectal", + "Kidney", + "Lower_urinary_tract", + "Bladder", + "Cervical", + "Acute_myeloid_leukaemia", + + "Peripheral_arterial_disease", + "Abdominal_aortic_aneurysm", + "Venous_thromboembolism", + "Chronic_obstructive_pulmonary_disease", + "Asthma", + "Tuberculosis", + "Obstructive_sleep_apnoea", + "Pneumonia", + "Influenza_clinically_diagnosed", + "Influenza_microbiologically_confirmed", + "Diabetes", + "Alzheimers_disease", + "Vascular_dementia", + "All_cause_dementia", + "Depression", + "Schizophrenia", + "Multiple_sclerosis", + "Systematic_lupus_erythematosis", + "Low_back_pain", + "Psoriasis", + "Age_related_macular_degeneration", + "Crohns_disease", + "Hip_fracture", + "Idiopathic_pulmonary_fibrosis", + "Rheumatoid_arthritis", + "Chronic_Kidney_disease", + "End_stage_renal_disease", + "Senile_cataract", + "Bulimia", + "Hearing_loss", + "Psychosis", + + "Ulcerative_colitis", + "Parkinson" + ) + + if(disease %in% str4) { + + # Assign risks for current smokers + + data_temp[x == "current" & sex == "Female", rr_indiv := rr[sex == "Female", relative_risk]] + data_temp[x == "current" & sex == "Male", rr_indiv := rr[sex == "Male", relative_risk]] + + # Also assign the risks for current smoking to former smokers + # as the risk for former smokers will subsequently be reduced according to the number of years + # since these former smokers quit + + data_temp[x == "former" & sex == "Female", rr_indiv := rr[sex == "Female", relative_risk]] + data_temp[x == "former" & sex == "Male", rr_indiv := rr[sex == "Male", relative_risk]] + + } + + +# Output a vector containing the relative risks for each individual +return(data_temp[ , rr_indiv]) +} + + + diff --git a/R/TobAlcInt.R b/R/TobAlcInt.R index 380db38..3d75721 100644 --- a/R/TobAlcInt.R +++ b/R/TobAlcInt.R @@ -1,68 +1,77 @@ - - -#' Risk interaction between tobacco and alcohol -#' -#' Assigns the disease-specific interaction term (synergy index) appropriate to each -#' individual's tobacco and alcohol consumption. -#' -#' -#' -#' -#' @param data Data table -#' @param disease Character -#' @param alcohol_var Character -#' @param tobacco_var Character -#' @param rr_data Data table -#' @param account_for_synergy Logical -#' -#' @return Returns a numeric vector containing of each individual's relative risks for the tobacco-related disease -#' specified by "disease". -#' @export -#' -#' @examples -TobAlcInt <- function( - data, - disease = "Pharynx", - alcohol_var = "weekmean", - tobacco_var = "smk.state", - rr.data, - account_for_synergy = TRUE -) { - - rr <- rr.data[Disease == disease] - - dtmp <- copy(data[ , .(x.tob = get(tobacco_var), x.alc = get(alcohol_var))]) - - # Conditions with a tobacco alcohol interaction - str1 <- c( - "Oral_cavity", - "Pharynx", - "Larynx", - "Oesophageal_SCC" - ) - - # Calculate the synergy index. - if(disease %in% str1) { - - alc1_tob0 <- rr[ , alc1_tob0] - alc0_tob1 <- rr[ , alc0_tob1] - alc1_tob1 <- rr[ , alc1_tob1] - - si <- (alc1_tob1 - 1) / ((alc1_tob0 - 1) + (alc0_tob1 - 1)) - - } else { - - si <- 1 - - } - - # Calculate when to apply the synergy index to an individual. - dtmp[ , si.indiv := ifelse(x.tob == "current" & x.alc > 0, si, 1)] - - -# Final output -return(dtmp[ , si.indiv]) -} - - - + + +#' Risk interaction between tobacco and alcohol +#' +#' Assigns the disease-specific interaction term (synergy index) appropriate to each +#' individual's tobacco and alcohol consumption. +#' +#' +#' +#' +#' @param data Data table +#' @param disease Character +#' @param alcohol_var Character +#' @param tobacco_var Character +#' @param rr.data Data table +#' @param account_for_synergy Logical +#' +#' @return Returns a numeric vector containing of each individual's relative risks for the tobacco-related disease +#' specified by "disease". +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#' \dontrun{ +#' +#' TobAlcInt() +#' +#' } +#' +#' +TobAlcInt <- function( + data, + disease = "Pharynx", + alcohol_var = "weekmean", + tobacco_var = "smk.state", + rr.data, + account_for_synergy = TRUE +) { + + rr <- rr.data[Disease == disease] + + dtmp <- data.table::copy(data[ , .(x.tob = get(tobacco_var), x.alc = get(alcohol_var))]) + + # Conditions with a tobacco alcohol interaction + str1 <- c( + "Oral_cavity", + "Pharynx", + "Larynx", + "Oesophageal_SCC" + ) + + # Calculate the synergy index. + if(disease %in% str1) { + + alc1_tob0 <- rr[ , alc1_tob0] + alc0_tob1 <- rr[ , alc0_tob1] + alc1_tob1 <- rr[ , alc1_tob1] + + si <- (alc1_tob1 - 1) / ((alc1_tob0 - 1) + (alc0_tob1 - 1)) + + } else { + + si <- 1 + + } + + # Calculate when to apply the synergy index to an individual. + dtmp[ , si.indiv := ifelse(x.tob == "current" & x.alc > 0, si, 1)] + + +# Final output +return(dtmp[ , si.indiv]) +} + + + diff --git a/R/TobLags.R b/R/TobLags.R index 9ebfb0e..8aed620 100644 --- a/R/TobLags.R +++ b/R/TobLags.R @@ -1,129 +1,131 @@ - -#' Tobacco lag times -#' -#' Prepare the disease specific functions that describe how a change in tobacco consumption -#' gradually has an effect on the relative risk of disease incidence over time (up to 40 years) -#' since e.g. someone quit smoking -#' -#' All lag times are taken from a re-analysis of the Cancer prevention II study by Oza et al 2011 and Kontis et al 2014 -#' The values were sent to us by Kontis. Lags are smoothed functions over time describing the proportion of -#' the excess risk due to smoking that still remains. -#' -#' Kontis et al. re-analysed the change in risk after smoking in the ACS-CPS II study from Oza et al., -#' producing three functions to describe the decline in risk after quitting for each of cancers, CVD and COPD. -#' The estimates were informed by data on former smokers with known quit dates who were disease-free at baseline. -#' The results show the proportion of excess relative risk remaining at each time-point since cessation. -#' A cross-check showed that the figures for cancers were broadly consistent with the findings of the -#' International Agency for Research on Cancer's (IARC) -#' 2007 review of the decline in risk after quitting smoking. -#' -#' The remaining question is how risk declines after quitting smoking for diseases that are not cancers, -#' CVD or COPD. Kontis et al. state that -#' "Randomised trials also indicate that the benefits of behaviour change and pharmacological treatment -#' on diabetes risk occur within a few years, more similar to the CVDs than cancers. -#' Therefore, we used the CVD curve for diabetes." In-line with Kontis, we apply the rate of decline -#' in risk of CVD after quitting smoking to type 2 diabetes. -#' For other diseases, we assume that the relative risk reverts to 1 immediately after quitting -#' i.e. an immediate rather than a gradual decline in risk. -#' -#' @param disease_name Character - the name of the disease under consideration. -#' @param n_years Integer - the number of years from 1 to n over which the effect of a change in -#' consumption emerges. Defaults to 20 years to fit with the current lag data. -#' @param lag_data Data table containing the numerical description of the lag function. -#' The data table "tobacco lag times" is embedded within the stapmr package. -#' -#' @return Returns a data table with two columns - one for the years since consumption changed, and the other -#' that gives the proportion by which the effect of a change in consumption -#' on an individual's relative risk of disease has so far emerged. -#' @export -#' -#' @examples -#' -#' TobLags("Pharynx") -#' -TobLags <- function( - disease_name = c("Pharynx", "Oral_cavity"), - n_years = 40, - lag_data = tobalcepi::tobacco_lag_times -) { - - ################################# - # List the specific diseases that fall under each functional form of lag time - - cancer_lags <- c("Oral_cavity", "Pharynx", "Lung", "Nasopharynx_sinonasal", "Larynx", "Oesophageal_AC", - "Oesophageal_SCC", "Stomach", "Pancreas", "Liver", "Colorectal", "Kidney", "Lower_urinary_tract", - "Bladder", "Cervical", "Acute_myeloid_leukaemia") - - cvd_lags <- c("Ischaemic_heart_disease", "Haemorrhagic_Stroke", "Ischaemic_Stroke", "Peripheral_arterial_disease", - "Abdominal_aortic_aneurysm", "Venous_thromboembolism", "Diabetes") - - copd_lags <- c("Chronic_obstructive_pulmonary_disease") - - # For other conditions assume that the excess risk is zero 1 year after cessation - - ################################# - # Specify the functional forms of the lags - # The numbers are taken from SAPM - Holmes et al. 2012 - - ################## - # Set the default - - # An instant reduction of risk e.g. for acute conditions - #lag_func <- c(1, rep(0, n_years)) - - # Assume that other diseases follow the cancer lag - lag_func <- lag_data[cause_group == "Cancers", excess_risk_percent] - - ################## - - if(disease_name %in% cancer_lags) { - lag_func <- lag_data[cause_group == "Cancers", excess_risk_percent] - } - - if(disease_name %in% cvd_lags) { - lag_func <- lag_data[cause_group == "CVD", excess_risk_percent] - } - - if(disease_name %in% copd_lags) { - lag_func <- lag_data[cause_group == "COPD", excess_risk_percent] - } - - ################################# - # Format the output - - # The numbers above are currently in the form of the proportion of excess risk remaining - # Re-format so they show the cumulative proportion by which risk reduces over time - # i.e. after 40 years, all excess risk has gone, so the cumulative proportion of risk reduction = 1 - - disease_lag_data <- data.table( - time_since_quit = 0:n_years, - prop_risk_reduction = 1 - lag_func - ) - -return(disease_lag_data) -} - - - - - - - - - - - - - - - - - - - - - - - - - + +#' Tobacco lag times +#' +#' Prepare the disease specific functions that describe how a change in tobacco consumption +#' gradually has an effect on the relative risk of disease incidence over time (up to 40 years) +#' since e.g. someone quit smoking +#' +#' All lag times are taken from a re-analysis of the Cancer prevention II study by Oza et al 2011 and Kontis et al 2014 +#' The values were sent to us by Kontis. Lags are smoothed functions over time describing the proportion of +#' the excess risk due to smoking that still remains. +#' +#' Kontis et al. re-analysed the change in risk after smoking in the ACS-CPS II study from Oza et al., +#' producing three functions to describe the decline in risk after quitting for each of cancers, CVD and COPD. +#' The estimates were informed by data on former smokers with known quit dates who were disease-free at baseline. +#' The results show the proportion of excess relative risk remaining at each time-point since cessation. +#' A cross-check showed that the figures for cancers were broadly consistent with the findings of the +#' International Agency for Research on Cancer's (IARC) +#' 2007 review of the decline in risk after quitting smoking. +#' +#' The remaining question is how risk declines after quitting smoking for diseases that are not cancers, +#' CVD or COPD. Kontis et al. state that +#' "Randomised trials also indicate that the benefits of behaviour change and pharmacological treatment +#' on diabetes risk occur within a few years, more similar to the CVDs than cancers. +#' Therefore, we used the CVD curve for diabetes." In-line with Kontis, we apply the rate of decline +#' in risk of CVD after quitting smoking to type 2 diabetes. +#' For other diseases, we assume that the relative risk reverts to 1 immediately after quitting +#' i.e. an immediate rather than a gradual decline in risk. +#' +#' @param disease_name Character - the name of the disease under consideration. +#' @param n_years Integer - the number of years from 1 to n over which the effect of a change in +#' consumption emerges. Defaults to 20 years to fit with the current lag data. +#' @param lag_data Data table containing the numerical description of the lag function. +#' The data table "tobacco lag times" is embedded within the stapmr package. +#' +#' @return Returns a data table with two columns - one for the years since consumption changed, and the other +#' that gives the proportion by which the effect of a change in consumption +#' on an individual's relative risk of disease has so far emerged. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' +#' TobLags("Pharynx") +#' +TobLags <- function( + disease_name = c("Pharynx", "Oral_cavity"), + n_years = 40, + lag_data = tobalcepi::tobacco_lag_times +) { + + ################################# + # List the specific diseases that fall under each functional form of lag time + + cancer_lags <- c("Oral_cavity", "Pharynx", "Lung", "Nasopharynx_sinonasal", "Larynx", "Oesophageal_AC", + "Oesophageal_SCC", "Stomach", "Pancreas", "Liver", "Colorectal", "Kidney", "Lower_urinary_tract", + "Bladder", "Cervical", "Acute_myeloid_leukaemia") + + cvd_lags <- c("Ischaemic_heart_disease", "Haemorrhagic_Stroke", "Ischaemic_Stroke", "Peripheral_arterial_disease", + "Abdominal_aortic_aneurysm", "Venous_thromboembolism", "Diabetes") + + copd_lags <- c("Chronic_obstructive_pulmonary_disease") + + # For other conditions assume that the excess risk is zero 1 year after cessation + + ################################# + # Specify the functional forms of the lags + # The numbers are taken from SAPM - Holmes et al. 2012 + + ################## + # Set the default + + # An instant reduction of risk e.g. for acute conditions + #lag_func <- c(1, rep(0, n_years)) + + # Assume that other diseases follow the cancer lag + lag_func <- lag_data[cause_group == "Cancers", excess_risk_percent] + + ################## + + if(disease_name %in% cancer_lags) { + lag_func <- lag_data[cause_group == "Cancers", excess_risk_percent] + } + + if(disease_name %in% cvd_lags) { + lag_func <- lag_data[cause_group == "CVD", excess_risk_percent] + } + + if(disease_name %in% copd_lags) { + lag_func <- lag_data[cause_group == "COPD", excess_risk_percent] + } + + ################################# + # Format the output + + # The numbers above are currently in the form of the proportion of excess risk remaining + # Re-format so they show the cumulative proportion by which risk reduces over time + # i.e. after 40 years, all excess risk has gone, so the cumulative proportion of risk reduction = 1 + + disease_lag_data <- data.table::data.table( + time_since_quit = 0:n_years, + prop_risk_reduction = 1 - lag_func + ) + + +return(disease_lag_data) +} + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/R/alc_disease_names.R b/R/alc_disease_names.R new file mode 100644 index 0000000..1992448 --- /dev/null +++ b/R/alc_disease_names.R @@ -0,0 +1,16 @@ + +#' Names of alcohol-related diseases +#' +#' +#' +#' @docType data +#' +#' @format A data table +#' +#' @source +#' +#' +#' +#' +#' +"alc_disease_names" diff --git a/R/disease_names.R b/R/disease_names.R deleted file mode 100644 index 535a45c..0000000 --- a/R/disease_names.R +++ /dev/null @@ -1,15 +0,0 @@ - -library(data.table) -library(readxl) - -TobList <- read_excel("/Volumes/shared/ScHARR/PR_Disease_Risk_TA/Disease_Lists/16102018 tobacco and alcohol Disease List and Risk Functions.xlsx", sheet = "Tobacco") -tob_disease_names <- as.character(c(unique(TobList$condition))) - -usethis::use_data(tob_disease_names, overwrite = T) - - - -AlcList <- read_excel("/Volumes/shared/ScHARR/PR_Disease_Risk_TA/Disease_Lists/16102018 tobacco and alcohol Disease List and Risk Functions.xlsx", sheet = "Alcohol") -alc_disease_names <- as.character(c(unique(AlcList$condition))) - -usethis::use_data(alc_disease_names, overwrite = T) diff --git a/R/hse_data_smoking.R b/R/hse_data_smoking.R deleted file mode 100644 index 835de39..0000000 --- a/R/hse_data_smoking.R +++ /dev/null @@ -1,16 +0,0 @@ - -#' Health Survey for England data used for modelling smoking -#' -#' For years 2001-2016. -#' -#' @docType data -#' -#' @format A data table -#' -#' @source see the processing code in the data-raw folder, which uses the hseclean R package -#' -#' -#' -#' -#' -"hse_data_smoking" diff --git a/R/subgroupRisk.R b/R/subgroupRisk.R index 01bc908..9970cdc 100644 --- a/R/subgroupRisk.R +++ b/R/subgroupRisk.R @@ -1,196 +1,197 @@ - -#' Summarise relative risk -#' -#' Calculate the sum of the relative risk for all individuals in a subgroup, -#' or calculate the subgroup specific attributable fraction based on the current relative risks. -#' -#' Attributable fractions are calculated using the method as in Bellis & Jones 2014, which is also equivalent to the -#' method described in the Brennan et al. 2015 SAPM mathematical description paper. -#' -#' @param data A data table of individual characteristics. -#' @param label Character - a label to append to the outcome variable to help identify it in later calculations. -#' @param disease_names Character vector - the names of the diseases for which summaries of relative risk are required. -#' @param af Logical - if TRUE, then attributable fractions are calculated. If FALSE, then the total relative risk -#' is calculated. Defaults to FALSE. -#' @param use_weights Logical - should the calculation account for survey weights. Defaults to FALSE. -#' Weight variable must be called "wt_int". -#' @param year_range Either an integer vector of the years to be selected or "all". Defaults to "all". -#' @param pool Logical - should the years selected be pooled. Defaults to FALSE. -#' @param subgroups Character vector - the variable names of the subgroups used to stratify the estimates. -#' -#' @return Returns a data table containing the subgroup specific summaries for each disease. -#' @export -#' -#' @examples -#' -#' # Simulate individual data -#' -#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 -#' n <- 1e4 -#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) -#' -#' data <- data.table( -#' year = 2016, -#' weekmean = grams_ethanol_day * 7 / 8, -#' peakday = 2 * grams_ethanol_day / 8, -#' age = rpois(n, 30), -#' sex = sample(x = c("Male", "Female"), size = n, replace = T), -#' income5cat = "1_lowest income", -#' imd_quintile = "5_most_deprived", -#' kids = "0", -#' social_grade = "C2DE", -#' eduend4cat = "16-18", # age finished education -#' ethnic2cat = "white", # white / non-white -#' employ2cat = "yes", # employed / not -#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg -#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m -#' ) -#' -#' # Disease names -#' alc_disease_names <- c( -#' "Pharynx", -#' "Ischaemic_heart_disease", -#' "LiverCirrhosis", -#' "Transport_injuries", -#' "Alcohol_poisoning", -#' "Alcoholic_gastritis" -#' ) -#' -#' # Run basic function without alcohol lags -#' test_data <- RRFunc( -#' data = copy(data), -#' substance = "alc", -#' alc_diseases = alc_disease_names, -#' alc_wholly_chronic_thresholds = c(2, 2), -#' alc_wholly_acute_thresholds = c(3, 3), -#' show_progress = TRUE -#' ) -#' -#' # Calculate alcohol attributable fractions -#' test_aafs <- subgroupRisk( -#' data = test_data$data_plus_rr, -#' disease_names = alc_disease_names, -#' af = TRUE, -#' subgroups = "sex" -#' ) -#' -#' test_aafs -#' -subgroupRisk <- function( - data, - label = NULL, - disease_names = c("Pharynx", "Oral_cavity"), - af = FALSE, - use_weights = FALSE, - year_range = "all", - pool = FALSE, - subgroups = c("sex", "age_cat") -) { - - out <- copy(data) - - if("age_cat" %in% subgroups & !("age_cat" %in% colnames(out))) { - out[ , age_cat := c("12-15", "16-17", "18-24", "25-34", "35-49", "50-64", "65-74", "75-89")[findInterval(age, c(-10, 16, 18, 25, 35, 50, 65, 75))]] - } - - # To select a specified range of years of data - if(year_range[1] != "all") { - out <- out[year %in% year_range] - } - - # If several years of data are selected, should they be pooled - if(pool == T) { - out[ , year := 1] - } - - # Create a weighting variable - # depending on whether survey weights are to be used or not - if(use_weights == F) { - out[, weight := 1 / .N, by = c(subgroups, "year")] - } else { - out[, weight := wt_int / sum(wt_int, na.rm = T), by = c(subgroups, "year")] - } - - # Standardise the relative risks by subtracting 1 and multiplying by the weight - for (d in disease_names) { - out[, (paste0(d, "_z")) := weight * (get(d) - 1)] - } - - ############################################################ - # To prepare for subsequent computation of a PIF - # compute the average relative risk within a subgroup - - # compute the average rather than the total, so that when we later calculate the ratio - # of this aggregated relative risk between treatment and control arms, - # the ratio is not influenced by differences in the number of individuals - # i.e. we want to calculate the ratio of the expected value of individual risk in each arm - - if(!isTRUE(af)) { - - # calculate average relative risk - out_risk <- out[, - lapply(.SD, function(x) { - sum(x, na.rm = T) - }), - by = c(subgroups, "year"), - .SDcols = paste0(disease_names, "_z")] - - setnames(out_risk, paste0(disease_names, "_z"), disease_names) - - out_risk <- melt( - out_risk, - id.vars = c(subgroups, "year"), - variable.name = "condition", - value.name = paste0("av_risk_", label) - ) - - } - - ############################################################ - # For attributable fractions - - if(isTRUE(af)) { - - # calculate attributable fractions, considering residual risk in former smokers - out_risk <- out[, - lapply(.SD, function(x) { - sum(x, na.rm = T) / (sum(x, na.rm = T) + 1) - }), - by = c(subgroups, "year"), - .SDcols = paste0(disease_names, "_z")] - - setnames(out_risk, paste0(disease_names, "_z"), disease_names) - - out_risk <- melt( - out_risk, - id.vars = c(subgroups, "year"), - variable.name = "condition", - value.name = "af" - ) - - # Set the AAF = 1 for wholly attributable conditions - out_risk[condition %in% c( - "Excessive_Blood_Level_of_Alcohol", - "Toxic_effect_of_alcohol", - "Alcohol_poisoning", - "Evidence_of_alcohol_involvement_determined_by_blood_alcohol_level", - "Acute_intoxication", - "Alcoholic_cardiomyopathy", - "Alcoholic_gastritis", - "Alcoholic_liver_disease", - "Acute_pancreatitis_alcohol_induced", - "Chronic_pancreatitis_alcohol_induced", - "Alcohol_induced_pseudoCushings_syndrome", - "Alcoholic_myopathy", - "Alcoholic_polyneuropathy", - "Maternal_care_for_suspected_damage_to_foetus_from_alcohol", - "Degeneration", - "Mental_and_behavioural_disorders_due_to_use_of_alcohol" - ), af := 1] - - } - -return(out_risk) -} - - + +#' Summarise relative risk +#' +#' Calculate the sum of the relative risk for all individuals in a subgroup, +#' or calculate the subgroup specific attributable fraction based on the current relative risks. +#' +#' Attributable fractions are calculated using the method as in Bellis & Jones 2014, which is also equivalent to the +#' method described in the Brennan et al. 2015 SAPM mathematical description paper. +#' +#' @param data A data table of individual characteristics. +#' @param label Character - a label to append to the outcome variable to help identify it in later calculations. +#' @param disease_names Character vector - the names of the diseases for which summaries of relative risk are required. +#' @param af Logical - if TRUE, then attributable fractions are calculated. If FALSE, then the total relative risk +#' is calculated. Defaults to FALSE. +#' @param use_weights Logical - should the calculation account for survey weights. Defaults to FALSE. +#' Weight variable must be called "wt_int". +#' @param year_range Either an integer vector of the years to be selected or "all". Defaults to "all". +#' @param pool Logical - should the years selected be pooled. Defaults to FALSE. +#' @param subgroups Character vector - the variable names of the subgroups used to stratify the estimates. +#' +#' @return Returns a data table containing the subgroup specific summaries for each disease. +#' @importFrom data.table := setDT setnames +#' @export +#' +#' @examples +#' \dontrun{ +#' # Simulate individual data +#' +#' # Using the parameters for the Gamma distribution from Kehoe et al. 2012 +#' n <- 1e4 +#' grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) +#' +#' data <- data.table( +#' year = 2016, +#' weekmean = grams_ethanol_day * 7 / 8, +#' peakday = 2 * grams_ethanol_day / 8, +#' age = rpois(n, 30), +#' sex = sample(x = c("Male", "Female"), size = n, replace = T), +#' income5cat = "1_lowest income", +#' imd_quintile = "5_most_deprived", +#' kids = "0", +#' social_grade = "C2DE", +#' eduend4cat = "16-18", # age finished education +#' ethnic2cat = "white", # white / non-white +#' employ2cat = "yes", # employed / not +#' wtval = rnorm(n, mean = 60, sd = 5), # weight in kg +#' htval = rnorm(n, mean = 1.7, sd = .1) # height in m +#' ) +#' +#' # Disease names +#' alc_disease_names <- c( +#' "Pharynx", +#' "Ischaemic_heart_disease", +#' "LiverCirrhosis", +#' "Transport_injuries", +#' "Alcohol_poisoning", +#' "Alcoholic_gastritis" +#' ) +#' +#' # Run basic function without alcohol lags +#' test_data <- RRFunc( +#' data = copy(data), +#' substance = "alc", +#' alc_diseases = alc_disease_names, +#' alc_wholly_chronic_thresholds = c(2, 2), +#' alc_wholly_acute_thresholds = c(3, 3), +#' show_progress = TRUE +#' ) +#' +#' # Calculate alcohol attributable fractions +#' test_aafs <- subgroupRisk( +#' data = test_data$data_plus_rr, +#' disease_names = alc_disease_names, +#' af = TRUE, +#' subgroups = "sex" +#' ) +#' +#' test_aafs +#' } +subgroupRisk <- function( + data, + label = NULL, + disease_names = c("Pharynx", "Oral_cavity"), + af = FALSE, + use_weights = FALSE, + year_range = "all", + pool = FALSE, + subgroups = c("sex", "age_cat") +) { + + out <- data.table::copy(data) + + if("age_cat" %in% subgroups & !("age_cat" %in% colnames(out))) { + out[ , age_cat := c("12-15", "16-17", "18-24", "25-34", "35-49", "50-64", "65-74", "75-89")[findInterval(age, c(-10, 16, 18, 25, 35, 50, 65, 75))]] + } + + # To select a specified range of years of data + if(year_range[1] != "all") { + out <- out[year %in% year_range] + } + + # If several years of data are selected, should they be pooled + if(pool == T) { + out[ , year := 1] + } + + # Create a weighting variable + # depending on whether survey weights are to be used or not + if(use_weights == F) { + out[, weight := 1 / .N, by = c(subgroups, "year")] + } else { + out[, weight := wt_int / sum(wt_int, na.rm = T), by = c(subgroups, "year")] + } + + # Standardise the relative risks by subtracting 1 and multiplying by the weight + for (d in disease_names) { + out[, (paste0(d, "_z")) := weight * (get(d) - 1)] + } + + ############################################################ + # To prepare for subsequent computation of a PIF + # compute the average relative risk within a subgroup + + # compute the average rather than the total, so that when we later calculate the ratio + # of this aggregated relative risk between treatment and control arms, + # the ratio is not influenced by differences in the number of individuals + # i.e. we want to calculate the ratio of the expected value of individual risk in each arm + + if(!isTRUE(af)) { + + # calculate average relative risk + out_risk <- out[, + lapply(.SD, function(x) { + sum(x, na.rm = T) + }), + by = c(subgroups, "year"), + .SDcols = paste0(disease_names, "_z")] + + data.table::setnames(out_risk, paste0(disease_names, "_z"), disease_names) + + out_risk <- data.table::melt( + out_risk, + id.vars = c(subgroups, "year"), + variable.name = "condition", + value.name = paste0("av_risk_", label) + ) + + } + + ############################################################ + # For attributable fractions + + if(isTRUE(af)) { + + # calculate attributable fractions, considering residual risk in former smokers + out_risk <- out[, + lapply(.SD, function(x) { + sum(x, na.rm = T) / (sum(x, na.rm = T) + 1) + }), + by = c(subgroups, "year"), + .SDcols = paste0(disease_names, "_z")] + + data.table::setnames(out_risk, paste0(disease_names, "_z"), disease_names) + + out_risk <- data.table::melt( + out_risk, + id.vars = c(subgroups, "year"), + variable.name = "condition", + value.name = "af" + ) + + # Set the AAF = 1 for wholly attributable conditions + out_risk[condition %in% c( + "Excessive_Blood_Level_of_Alcohol", + "Toxic_effect_of_alcohol", + "Alcohol_poisoning", + "Evidence_of_alcohol_involvement_determined_by_blood_alcohol_level", + "Acute_intoxication", + "Alcoholic_cardiomyopathy", + "Alcoholic_gastritis", + "Alcoholic_liver_disease", + "Acute_pancreatitis_alcohol_induced", + "Chronic_pancreatitis_alcohol_induced", + "Alcohol_induced_pseudoCushings_syndrome", + "Alcoholic_myopathy", + "Alcoholic_polyneuropathy", + "Maternal_care_for_suspected_damage_to_foetus_from_alcohol", + "Degeneration", + "Mental_and_behavioural_disorders_due_to_use_of_alcohol" + ), af := 1] + + } + +return(out_risk) +} + + diff --git a/R/tob_alc_risk_int.R b/R/tob_alc_risk_int.R new file mode 100644 index 0000000..654c455 --- /dev/null +++ b/R/tob_alc_risk_int.R @@ -0,0 +1,16 @@ + +#' Synergstic effects of tobacco and alcohol risks +#' +#' +#' +#' @docType data +#' +#' @format A data table +#' +#' @source +#' +#' +#' +#' +#' +"tob_alc_risk_int" diff --git a/R/tob_disease_names.R b/R/tob_disease_names.R new file mode 100644 index 0000000..3b92f3d --- /dev/null +++ b/R/tob_disease_names.R @@ -0,0 +1,16 @@ + +#' Names of tobacco-related diseases +#' +#' +#' +#' @docType data +#' +#' @format A data table +#' +#' @source +#' +#' +#' +#' +#' +"tob_disease_names" diff --git a/R/tobacco_lag_times.R b/R/tobacco_lag_times.R new file mode 100644 index 0000000..49478ca --- /dev/null +++ b/R/tobacco_lag_times.R @@ -0,0 +1,16 @@ + +#' Tobacco lag times +#' +#' +#' +#' @docType data +#' +#' @format A data table +#' +#' @source +#' +#' +#' +#' +#' +"tobacco_lag_times" diff --git a/R/tobacco_relative_risks.R b/R/tobacco_relative_risks.R new file mode 100644 index 0000000..e681c8d --- /dev/null +++ b/R/tobacco_relative_risks.R @@ -0,0 +1,16 @@ + +#' Tobacco relative risks +#' +#' +#' +#' @docType data +#' +#' @format A data table +#' +#' @source +#' +#' +#' +#' +#' +"tobacco_relative_risks" diff --git a/R/utils-data-table.R b/R/utils-data-table.R new file mode 100644 index 0000000..d2f2964 --- /dev/null +++ b/R/utils-data-table.R @@ -0,0 +1,12 @@ +# data.table is generally careful to minimize the scope for namespace +# conflicts (i.e., functions with the same name as in other packages); +# a more conservative approach using @importFrom should be careful to +# import any needed data.table special symbols as well, e.g., if you +# run DT[ , .N, by='grp'] in your package, you'll need to add +# @importFrom data.table .N to prevent the NOTE from R CMD check. +# See ?data.table::`special-symbols` for the list of such symbols +# data.table defines; see the 'Importing data.table' vignette for more +# advice (vignette('datatable-importing', 'data.table')). +# +#' @import data.table +NULL diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..35bf3d1 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,110 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` +# tobalcepi + +[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) + + +The package is usable but there are still bugs and further developments that are being worked through i.e. some code and documentation is still incomplete or in need of being refined. The code and documentation are still undergoing internal review by the analyst team. + +## Motivation +`tobalcepi` was created as part of a programme of work on the health economics of tobacco and alcohol at the School of Health and Related Research (ScHARR), The University of Sheffield. This programme is based around the construction of the Sheffield Tobacco and Alcohol Policy Model (STAPM), which aims to use comparable methodologies to evaluate the impacts of tobacco and alcohol policies, and investigate the consequences of clustering and interactions between tobacco and alcohol consumption behaviours. + +The motivation for `tobalcepi` was to organise the information on the relative risks of diseases related to tobacco and alcohol consumption and to provide functions to easily work with these data in modelling. The suite of functions within `tobalcepi` processes the published data on disease risks that stem from chronic and acute alcohol consumption, from smoking, and on the decline in risk after ceasing or reducing consumption. The package also includes functions to estimate population attributable fractions, and to explore the interaction between the disease risks that stem from tobacco and alcohol consumption. + + > The risk functions in this package are all collated from published sources, which we have referenced. + +## Usage + +`tobalcepi` is a package for predicting individual risk of disease due to tobacco and alcohol consumption based on published sources, and summarising that risk. + +The **inputs** are the published estimates of relative risk for each disease (sometimes stratified by population subgroup). + +The **processes** applied by the functions in `tobalcepi` give options to estimate: + +1. The risk of injury or disease from acute alcohol consumption. +1. The risk of chronic disease based on the current amount of alcohol consumed. +1. The risk of chronic disease based on whether someone currently smokes, and how much they currently smoke. +1. The combined risk of disease in someone who smokes and drinks. +1. The change in risk of disease after someone ceases or reduces their consumption. +1. The population attributable fractions of disease to tobacco and/or alcohol (given suitable data on tobacco and alcohol consumption). + +The **outputs** of these processes are datasets in which an individual's tobacco and/or alcohol consumption has been matched to their relative risks of certain diseases, and aggregated datasets that summarise the risks of disease within certain population subgroups. + +## Installation + +We would like to ask that since the code and documentation is still under development and is complex, that you consult with the authors before you use it. + +Please cite the latest version of the package using: +"Duncan Gillespie, Laura Webster, Maddy Henney, Colin Angus and Alan Brennan (2020). tobalcepi: Risk Functions and Attributable Fractions for Tobacco and +Alcohol. R package version x.x.x. https://STAPM.github.io/tobalcepi/. DOI: " + +--- + +Since you will be downloading and installing a source package, you might need to set your system up for building R packages: + +It is a good idea to update R and all of your packages. + +**Mac OS**: A convenient way to get the tools needed for compilation is to install Xcode Command Line Tools. Note that this is much smaller than full Xcode. In a shell, enter xcode-select --install. For installing almost anything else, consider using [Homebrew](https://brew.sh/). + +**Windows**: Install Rtools. This is not an R package! It is “a collection of resources for building packages for R under Microsoft Windows, or for building R itself”. Go to https://cran.r-project.org/bin/windows/Rtools/ and install as instructed. + +--- + +You can **install the development version of `hseclean`** from github with: + +```{r gh_installation, message=FALSE, eval = FALSE} +#install.packages("devtools") +devtools::install_github("STAPM/tobalcepi") +``` + +--- + +If there is an error with `install_github()`, one possible work-around is + +1. Download the package "tarball" by copying this into your internet browser (making sure the numbers at the end indicate the latest version) `https://github.com/STAPM/tobalcepi/tarball/1.0.0`. When the window pops up, choose where to save the .tar.gz file. + + +2. Go to the Terminal window in R Studio (or a console window in Windows by searching for "cmd") and install the package from the downloaded file by typing `R CMD INSTALL file_path.tar.gz`. + +--- + +Then load the package, and some other packages that are useful. Note that the code within `tobalcepi` uses the `data.table::data.table()` syntax. + +```{r pkgs, eval = F} +# Load the package +library(tobalcepi) + +# Other useful packages +library(dplyr) # for data manipulation and summary +library(magrittr) # for pipes +library(ggplot2) # for plotting +``` + +## Getting started + + + + + +## Basic functionality + + + + + + + + diff --git a/README.md b/README.md index a0445d8..1776276 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,139 @@ -# tobalcepi -Functions to assign relative risks of disease to individuals based on their tobacco and/or alcohol consumption, and to estimate the attributable fractions of disease. + + + +# tobalcepi + +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) + +The package is usable but there are still bugs and further developments +that are being worked through i.e. some code and documentation is still +incomplete or in need of being refined. The code and documentation are +still undergoing internal review by the analyst team. + +## Motivation + +`tobalcepi` was created as part of a programme of work on the health +economics of tobacco and alcohol at the School of Health and Related +Research (ScHARR), The University of Sheffield. This programme is based +around the construction of the Sheffield Tobacco and Alcohol Policy +Model (STAPM), which aims to use comparable methodologies to evaluate +the impacts of tobacco and alcohol policies, and investigate the +consequences of clustering and interactions between tobacco and alcohol +consumption behaviours. + +The motivation for `tobalcepi` was to organise the information on the +relative risks of diseases related to tobacco and alcohol consumption +and to provide functions to easily work with these data in modelling. +The suite of functions within `tobalcepi` processes the published data +on disease risks that stem from chronic and acute alcohol consumption, +from smoking, and on the decline in risk after ceasing or reducing +consumption. The package also includes functions to estimate population +attributable fractions, and to explore the interaction between the +disease risks that stem from tobacco and alcohol consumption. + +> The risk functions in this package are all collated from published +> sources, which we have referenced. + +## Usage + +`tobalcepi` is a package for predicting individual risk of disease due +to tobacco and alcohol consumption based on published sources, and +summarising that risk. + +The **inputs** are the published estimates of relative risk for each +disease (sometimes stratified by population subgroup). + +The **processes** applied by the functions in `tobalcepi` give options +to estimate: + +1. The risk of injury or disease from acute alcohol consumption. +2. The risk of chronic disease based on the current amount of alcohol + consumed. +3. The risk of chronic disease based on whether someone currently + smokes, and how much they currently smoke. +4. The combined risk of disease in someone who smokes and drinks. +5. The change in risk of disease after someone ceases or reduces their + consumption. +6. The population attributable fractions of disease to tobacco and/or + alcohol (given suitable data on tobacco and alcohol consumption). + +The **outputs** of these processes are datasets in which an individual’s +tobacco and/or alcohol consumption has been matched to their relative +risks of certain diseases, and aggregated datasets that summarise the +risks of disease within certain population subgroups. + +## Installation + +We would like to ask that since the code and documentation is still +under development and is complex, that you consult with the authors +before you use it. + +Please cite the latest version of the package using: +“Duncan Gillespie, Laura Webster, Maddy Henney, Colin Angus and Alan +Brennan (2020). tobalcepi: Risk Functions and Attributable Fractions for +Tobacco and Alcohol. R package version x.x.x. +. DOI:” + +----- + +Since you will be downloading and installing a source package, you might +need to set your system up for building R packages: + +It is a good idea to update R and all of your packages. + +**Mac OS**: A convenient way to get the tools needed for compilation is +to install Xcode Command Line Tools. Note that this is much smaller than +full Xcode. In a shell, enter xcode-select –install. For installing +almost anything else, consider using [Homebrew](https://brew.sh/). + +**Windows**: Install Rtools. This is not an R package\! It is “a +collection of resources for building packages for R under Microsoft +Windows, or for building R itself”. Go to + and install as +instructed. + +----- + +You can **install the development version of `hseclean`** from github +with: + +``` r +#install.packages("devtools") +devtools::install_github("STAPM/tobalcepi") +``` + +----- + +If there is an error with `install_github()`, one possible work-around +is + +1. Download the package “tarball” by copying this into your internet + browser (making sure the numbers at the end indicate the latest + version) `https://github.com/STAPM/tobalcepi/tarball/1.0.0`. When + the window pops up, choose where to save the .tar.gz file. + +2. Go to the Terminal window in R Studio (or a console window in + Windows by searching for “cmd”) and install the package from the + downloaded file by typing `R CMD INSTALL file_path.tar.gz`. + +----- + +Then load the package, and some other packages that are useful. Note +that the code within `tobalcepi` uses the `data.table::data.table()` +syntax. + +``` r +# Load the package +library(tobalcepi) + +# Other useful packages +library(dplyr) # for data manipulation and summary +library(magrittr) # for pipes +library(ggplot2) # for plotting +``` + +## Getting started + +## Basic functionality diff --git a/_pkgdown.yml b/_pkgdown.yml new file mode 100644 index 0000000..ae7db15 --- /dev/null +++ b/_pkgdown.yml @@ -0,0 +1,19 @@ +destination: docs +home: + title: Risk Functions and Attributable Fractions for Tobacco and Alcohol + links: + - text: Browse source code + href: https://github.com/STAPM/tobalcepi +url: https://github.com/STAPM/tobalcepi +template: + params: + bootswatch: flatly +authors: + Duncan Gillespie: + href: https://www.sheffield.ac.uk/scharr/sections/heds/staff/gillespie_d + Maddy Henney: + href: https://www.sheffield.ac.uk/scharr/sections/heds/staff/henney_m + Colin Angus: + href: https://www.sheffield.ac.uk/scharr/sections/heds/staff/angus_c + Alan Brennan: + href: https://www.sheffield.ac.uk/scharr/sections/heds/staff/brennan_a \ No newline at end of file diff --git a/data-raw/.DS_Store b/data-raw/.DS_Store new file mode 100644 index 0000000..d4ae5a9 Binary files /dev/null and b/data-raw/.DS_Store differ diff --git a/data-raw/Health Survey for England/clean_hse_alcohol.R b/data-raw/Health Survey for England/clean_hse_alcohol.R deleted file mode 100644 index 6b27d48..0000000 --- a/data-raw/Health Survey for England/clean_hse_alcohol.R +++ /dev/null @@ -1,90 +0,0 @@ - - -#install.packages("X:/ScHARR/PR_STAPM/Code/R_packages/hseclean_0.1.0.zip", repos = NULL) - -library(hseclean) - -cleandata <- function(data) { - - data <- clean_age(data) - data <- clean_family(data) - data <- clean_demographic(data) - data <- clean_education(data) - data <- clean_economic_status(data) - data <- clean_income(data) - data <- clean_health_and_bio(data) - - data <- smk_status(data) - data <- smk_former(data) - data <- smk_life_history(data) - data <- smk_amount(data) - - data <- select_data( - data, - ages = 12:89, - years = 2001:2016, - keep_vars = c("age", "sex", "imd_quintile", "wt_int", "psu", "cluster", "year", "age_cat", "cig_smoker_status", - "smk_start_age", "censor_age", "cigs_per_day", "smoker_cat", - "years_since_quit", "degree", "relationship_status", "employ2cat", "hse_mental", "hse_heart", "hse_respir", "hse_endocrine", "kids", "income5cat"), - complete_vars = c("age", "sex", "imd_quintile", "cig_smoker_status", "psu", "wt_int", "cluster", "year", "censor_age") - ) - - return(data) -} - -hse_data <- combine_years(list( - cleandata(read_2001()), - cleandata(read_2002()), - cleandata(read_2003()), - cleandata(read_2004()), - cleandata(read_2005()), - cleandata(read_2006()), - cleandata(read_2007()), - cleandata(read_2008()), - cleandata(read_2009()), - cleandata(read_2010()), - cleandata(read_2011()), - cleandata(read_2012()), - cleandata(read_2013()), - cleandata(read_2014()), - cleandata(read_2015()), - cleandata(read_2016()) -)) - -hse_data <- clean_surveyweights(hse_data) - -setnames(hse_data, - c("smk_start_age", "cig_smoker_status", "years_since_quit"), - c("start_age", "smk.state", "time_since_quit")) - -hse_data[is.na(degree), degree := "no_degree"] -hse_data[is.na(relationship_status ), relationship_status := "single"] -hse_data[is.na(employ2cat), employ2cat := "unemployed"] -hse_data[is.na(hse_mental), hse_mental := "no_mental"] -hse_data[is.na(hse_heart), hse_heart := "no_heart"] -hse_data[is.na(hse_respir), hse_respir := "no_respir"] -hse_data[is.na(hse_endocrine), hse_endocrine := "no_endocrine"] -hse_data[is.na(kids), kids := "0"] -hse_data[is.na(income5cat), income5cat := "1_lowest_income"] - -hse_data[ , time_since_quit := as.double(ceiling(time_since_quit))] -hse_data <- hse_data[!(smk.state == "former" & time_since_quit < 1)] - - -# Main data -hse_data_smoking <- copy(hse_data) - -testthat::expect_equal(nrow(hse_data_smoking[smk.state == "current" & cigs_per_day == 0]), 0, - info = "some current smokers smoke 0 cigs per day") - -# Save the data to the package data folder -usethis::use_data(hse_data_smoking, overwrite = TRUE) - -rm(hse_data_smoking, hse_data, cleandata) -gc() - - - - - - diff --git a/data-raw/Health Survey for England/clean_hse_smoking.R b/data-raw/Health Survey for England/clean_hse_smoking.R deleted file mode 100644 index 6a54f52..0000000 --- a/data-raw/Health Survey for England/clean_hse_smoking.R +++ /dev/null @@ -1,90 +0,0 @@ - - -#install.packages("X:/ScHARR/PR_STAPM/Code/R_packages/hseclean_0.1.0.zip", repos = NULL) - -library(hseclean) - -cleandata <- function(data) { - - data <- clean_age(data) - data <- clean_family(data) - data <- clean_demographic(data) - data <- clean_education(data) - data <- clean_economic_status(data) - data <- clean_income(data) - data <- clean_health_and_bio(data) - - data <- smk_status(data) - data <- smk_former(data) - data <- smk_life_history(data) - data <- smk_amount(data) - - data <- select_data( - data, - ages = 12:89, - years = 2001:2016, - keep_vars = c("age", "sex", "imd_quintile", "wt_int", "psu", "cluster", "year", "age_cat", "cig_smoker_status", - "smk_start_age", "censor_age", "cigs_per_day", "smoker_cat", - "years_since_quit", "degree", "relationship_status", "employ2cat", "hse_mental", "hse_heart", "hse_respir", "hse_endocrine", "kids", "income5cat"), - complete_vars = c("age", "sex", "imd_quintile", "cig_smoker_status", "psu", "wt_int", "cluster", "year", "censor_age") - ) - -return(data) -} - -hse_data <- combine_years(list( - cleandata(read_2001()), - cleandata(read_2002()), - cleandata(read_2003()), - cleandata(read_2004()), - cleandata(read_2005()), - cleandata(read_2006()), - cleandata(read_2007()), - cleandata(read_2008()), - cleandata(read_2009()), - cleandata(read_2010()), - cleandata(read_2011()), - cleandata(read_2012()), - cleandata(read_2013()), - cleandata(read_2014()), - cleandata(read_2015()), - cleandata(read_2016()) -)) - -hse_data <- clean_surveyweights(hse_data) - -setnames(hse_data, - c("smk_start_age", "cig_smoker_status", "years_since_quit"), - c("start_age", "smk.state", "time_since_quit")) - -hse_data[is.na(degree), degree := "no_degree"] -hse_data[is.na(relationship_status ), relationship_status := "single"] -hse_data[is.na(employ2cat), employ2cat := "unemployed"] -hse_data[is.na(hse_mental), hse_mental := "no_mental"] -hse_data[is.na(hse_heart), hse_heart := "no_heart"] -hse_data[is.na(hse_respir), hse_respir := "no_respir"] -hse_data[is.na(hse_endocrine), hse_endocrine := "no_endocrine"] -hse_data[is.na(kids), kids := "0"] -hse_data[is.na(income5cat), income5cat := "1_lowest_income"] - -hse_data[ , time_since_quit := as.double(ceiling(time_since_quit))] -hse_data <- hse_data[!(smk.state == "former" & time_since_quit < 1)] - - -# Main data -hse_data_smoking <- copy(hse_data) - -testthat::expect_equal(nrow(hse_data_smoking[smk.state == "current" & cigs_per_day == 0]), 0, - info = "some current smokers smoke 0 cigs per day") - -# Save the data to the package data folder -usethis::use_data(hse_data_smoking, overwrite = TRUE) - -rm(hse_data_smoking, hse_data, cleandata) -gc() - - - - - - diff --git a/data-raw/Relative risks/disease_groups.R b/data-raw/Relative risks/disease_groups.R deleted file mode 100644 index 0e6c6a2..0000000 --- a/data-raw/Relative risks/disease_groups.R +++ /dev/null @@ -1,6 +0,0 @@ - -library(data.table) - -disease_groups <- fread("data-raw/Relative risks/disease_groups.csv") - -usethis::use_data(disease_groups, overwrite = T) diff --git a/data-raw/disease_groups.R b/data-raw/disease_groups.R new file mode 100644 index 0000000..99df3ac --- /dev/null +++ b/data-raw/disease_groups.R @@ -0,0 +1,6 @@ + +library(data.table) + +disease_groups <- fread("vignettes/disease_groups.csv") + +usethis::use_data(disease_groups, overwrite = T) diff --git a/data-raw/disease_names.R b/data-raw/disease_names.R new file mode 100644 index 0000000..3239a9b --- /dev/null +++ b/data-raw/disease_names.R @@ -0,0 +1,15 @@ + +library(data.table) +library(readxl) + +TobList <- readxl::read_excel("vignettes/16102018tobaccoandalcoholDiseaseListandRiskFunctions.xlsx", sheet = "Tobacco") +tob_disease_names <- as.character(c(unique(TobList$condition))) + +usethis::use_data(tob_disease_names, overwrite = T) + + + +AlcList <- readxl::read_excel("vignettes/16102018tobaccoandalcoholDiseaseListandRiskFunctions.xlsx", sheet = "Alcohol") +alc_disease_names <- as.character(c(unique(AlcList$condition))) + +usethis::use_data(alc_disease_names, overwrite = T) diff --git a/data-raw/Relative risks/tobacco_alcohol_risk_interaction.R b/data-raw/tobacco_alcohol_risk_interaction.R similarity index 75% rename from data-raw/Relative risks/tobacco_alcohol_risk_interaction.R rename to data-raw/tobacco_alcohol_risk_interaction.R index de46341..91a251e 100644 --- a/data-raw/Relative risks/tobacco_alcohol_risk_interaction.R +++ b/data-raw/tobacco_alcohol_risk_interaction.R @@ -1,12 +1,12 @@ - -# This code reads and processes the estimates for the effect that consumption of -# both tobacco and alcohol has for the risk of certain diseases - -# Load the spreadsheet containing disease risks -tob_alc_risk_int <- data.table::fread("X:/ScHARR/PR_Disease_Risk_TA/Disease_Lists/tob_alc_interactions_180119.csv") - -# Select the versions marked as current -tob_alc_risk_int <- tob_alc_risk_int[Version == "Current"] - -# Save the result to the package data folder -usethis::use_data(tob_alc_risk_int, overwrite = T) + +# This code reads and processes the estimates for the effect that consumption of +# both tobacco and alcohol has for the risk of certain diseases + +# Load the spreadsheet containing disease risks +tob_alc_risk_int <- data.table::fread("vignettes/tob_alc_interactions_180119.csv") + +# Select the versions marked as current +tob_alc_risk_int <- tob_alc_risk_int[Version == "Current"] + +# Save the result to the package data folder +usethis::use_data(tob_alc_risk_int, overwrite = T) diff --git a/data-raw/Relative risks/tobacco_lag_times.R b/data-raw/tobacco_lag_times.R similarity index 78% rename from data-raw/Relative risks/tobacco_lag_times.R rename to data-raw/tobacco_lag_times.R index cedd9ba..82481a2 100644 --- a/data-raw/Relative risks/tobacco_lag_times.R +++ b/data-raw/tobacco_lag_times.R @@ -1,16 +1,16 @@ - -# This code reads and processes the lag times for tobacco - -# Load the spreadsheet containing the lag times -# These are taken from Kontis et al. 2015 and were sent to us by the author -tobacco_lag_times <- data.table::fread("X:/ScHARR/PR_Disease_Risk_TA/Lag_times/Kontis tobacco lags/excess_risk_decline_from_KontisLancet.csv") - -# Select the versions marked as current -# and select the required columns -tobacco_lag_times <- tobacco_lag_times[years_since_cessation %in% 0:40, c("cause_group", "years_since_cessation", "excess_risk_percent")] - -# Change the names -setnames(tobacco_lag_times, "years_since_cessation", "time_since_quit") - -# Save the result to the package data folder -usethis::use_data(tobacco_lag_times, overwrite = T) + +# This code reads and processes the lag times for tobacco + +# Load the spreadsheet containing the lag times +# These are taken from Kontis et al. 2015 and were sent to us by the author +tobacco_lag_times <- data.table::fread("vignettes/excess_risk_decline_from_KontisLancet.csv") + +# Select the versions marked as current +# and select the required columns +tobacco_lag_times <- tobacco_lag_times[years_since_cessation %in% 0:40, c("cause_group", "years_since_cessation", "excess_risk_percent")] + +# Change the names +setnames(tobacco_lag_times, "years_since_cessation", "time_since_quit") + +# Save the result to the package data folder +usethis::use_data(tobacco_lag_times, overwrite = T) diff --git a/data-raw/Relative risks/tobacco_relative_risks.R b/data-raw/tobacco_relative_risks.R similarity index 79% rename from data-raw/Relative risks/tobacco_relative_risks.R rename to data-raw/tobacco_relative_risks.R index 2143eff..37a7ffb 100644 --- a/data-raw/Relative risks/tobacco_relative_risks.R +++ b/data-raw/tobacco_relative_risks.R @@ -1,22 +1,24 @@ - -# This code reads and processes the relative risks for tobacco -# They are stored in a marker file -# This code reads that file and cleans it to prepare the data to be used in the model - -# Load the master spreadsheet containing disease risks -tobacco_relative_risks <- readxl::read_excel("X:/ScHARR/PR_Disease_Risk_TA/Disease_Lists/16102018 tobacco and alcohol Disease List and Risk Functions.xlsx", - sheet = "Tobacco") - -# Set it as a data table -data.table::setDT(tobacco_relative_risks) - -# Select the versions marked as current -# and select the required columns -tobacco_relative_risks <- tobacco_relative_risks[Version == "Current", c("condition", "age", "sex", "Current")] - -# Change the names -data.table::setnames(tobacco_relative_risks, "Current", "relative_risk") - -# Save the result to the package data folder -usethis::use_data(tobacco_relative_risks, overwrite = T) - + +# This code reads and processes the relative risks for tobacco +# They are stored in a marker file +# This code reads that file and cleans it to prepare the data to be used in the model + +library(readxl) + +# Load the master spreadsheet containing disease risks +tobacco_relative_risks <- readxl::read_excel("vignettes/16102018tobaccoandalcoholDiseaseListandRiskFunctions.xlsx", + sheet = "Tobacco") + +# Set it as a data table +data.table::setDT(tobacco_relative_risks) + +# Select the versions marked as current +# and select the required columns +tobacco_relative_risks <- tobacco_relative_risks[Version == "Current", c("condition", "age", "sex", "Current")] + +# Change the names +data.table::setnames(tobacco_relative_risks, "Current", "relative_risk") + +# Save the result to the package data folder +usethis::use_data(tobacco_relative_risks, overwrite = T) + diff --git a/data/alc_disease_names.rda b/data/alc_disease_names.rda index 95c621c..16ce9b2 100644 Binary files a/data/alc_disease_names.rda and b/data/alc_disease_names.rda differ diff --git a/data/hse_data_smoking.rda b/data/hse_data_smoking.rda deleted file mode 100644 index baa98e9..0000000 Binary files a/data/hse_data_smoking.rda and /dev/null differ diff --git a/data/tob_disease_names.rda b/data/tob_disease_names.rda index f97c3cc..adacfc1 100644 Binary files a/data/tob_disease_names.rda and b/data/tob_disease_names.rda differ diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..7b6e056 --- /dev/null +++ b/docs/404.html @@ -0,0 +1,152 @@ + + + + + + + + +Page not found (404) • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +Content not found. Please use links in the navbar. + +
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/LICENSE.html b/docs/LICENSE.html new file mode 100644 index 0000000..5b2ae61 --- /dev/null +++ b/docs/LICENSE.html @@ -0,0 +1,374 @@ + + + + + + + + +GNU General Public License • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+ +

Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

+

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

+
+

+Preamble

+

The GNU General Public License is a free, copyleft license for software and other kinds of works.

+

The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program–to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.

+

When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.

+

To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.

+

For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

+

Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.

+

For the developers’ and authors’ protection, the GPL clearly explains that there is no warranty for this free software. For both users’ and authors’ sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.

+

Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users’ freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.

+

Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.

+

The precise terms and conditions for copying, distribution and modification follow.

+
+
+

+TERMS AND CONDITIONS

+
+

+0. Definitions

+

“This License” refers to version 3 of the GNU General Public License.

+

“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.

+

“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.

+

To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.

+

A “covered work” means either the unmodified Program or a work based on the Program.

+

To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.

+

To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.

+

An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.

+
+
+

+1. Source Code

+

The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.

+

A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.

+

The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.

+

The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work’s System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.

+

The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.

+

The Corresponding Source for a work in source code form is that same work.

+
+
+

+2. Basic Permissions

+

All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.

+

You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.

+

Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.

+
+ +
+

+4. Conveying Verbatim Copies

+

You may convey verbatim copies of the Program’s source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.

+

You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.

+
+
+

+5. Conveying Modified Source Versions

+

You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:

+
    +
  • +a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
  • +
  • +b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
  • +
  • +c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
  • +
  • +d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
  • +
+

A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation’s users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.

+
+
+

+6. Conveying Non-Source Forms

+

You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:

+
    +
  • +a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
  • +
  • +b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
  • +
  • +c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
  • +
  • +d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
  • +
  • +e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
  • +
+

A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.

+

A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.

+

“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.

+

If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).

+

The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.

+

Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.

+
+
+

+7. Additional Terms

+

“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.

+

When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.

+

Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:

+
    +
  • +a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
  • +
  • +b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
  • +
  • +c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
  • +
  • +d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
  • +
  • +e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
  • +
  • +f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
  • +
+

All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.

+

If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.

+

Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.

+
+
+

+8. Termination

+

You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).

+

However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

+

Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.

+

Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.

+
+
+

+9. Acceptance Not Required for Having Copies

+

You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.

+
+
+

+10. Automatic Licensing of Downstream Recipients

+

Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.

+

An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party’s predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.

+

You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.

+
+
+

+11. Patents

+

A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor’s “contributor version”.

+

A contributor’s “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.

+

Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor’s essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.

+

In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.

+

If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient’s use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.

+

If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.

+

A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.

+

Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.

+
+
+

+12. No Surrender of Others’ Freedom

+

If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.

+
+
+

+13. Use with the GNU Affero General Public License

+

Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.

+
+
+

+14. Revised Versions of this License

+

The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

+

Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.

+

If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy’s public statement of acceptance of a version permanently authorizes you to choose that version for the Program.

+

Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.

+
+
+

+15. Disclaimer of Warranty

+

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

+
+
+

+16. Limitation of Liability

+

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+
+
+

+17. Interpretation of Sections 15 and 16

+

If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.

+

END OF TERMS AND CONDITIONS

+
+
+
+

+How to Apply These Terms to Your New Programs

+

If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

+

To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found.

+ +

Also add information on how to contact you by electronic and paper mail.

+

If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode:

+ +

The hypothetical commands show w and show c should show the appropriate parts of the General Public License. Of course, your program’s commands might be different; for a GUI interface, you would use an “about box”.

+

You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>.

+

The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.

+
+
+ +
+ + + +
+ + + + +
+ + + + + + + + diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 0000000..da178e8 --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,151 @@ + + + + + + + + +Articles • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+

All vignettes

+

+ +
+
Smoking and the risks of adult diseases
+
+
+
+
+
+ + + +
+ + + + + + + + diff --git a/docs/articles/smoking-disease-risks.html b/docs/articles/smoking-disease-risks.html new file mode 100644 index 0000000..6442468 --- /dev/null +++ b/docs/articles/smoking-disease-risks.html @@ -0,0 +1,720 @@ + + + + + + + +Smoking and the risks of adult diseases • tobalcepi + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+

+Acknowledgements

+

We thank Professor John Britton and Dr Katrina Brown. This work was conducted as part of our development of the Sheffield Tobacco and Alcohol Policy Model as part of the UK Centre for Tobacco and Alcohol Studies (http://ukctas.net/). Funding for UKCTAS from the British Heart Foundation, Cancer Research UK, the Economic and Social Research Council, the Medical Research Council and the National Institute of Health Research, under the auspices of the UK Clinical Research Collaboration, is gratefully acknowledged. The funders had no role in study design, data collection and analysis, decision to publish or preparation of this work.

+
+
+

+Summary

+

In the Sheffield Tobacco Policy Model (STPM), we consider 52 adult diseases related to smoking and the corresponding relative risks of developing these diseases in current vs. never smokers, and in former smokers according to the time since they quit (Webster et al. 2018). For current smokers, we assume that the relative risks of disease are the same for all smokers regardless of the amount currently smoked and the length of time as a smoker. We limit ourselves to diseases that affect the consumer themselves e.g. excluding secondary effects of smoking.

+
+
+

+Disease list

+

We arrived at our disease list and the corresponding International Classification of Diseases version 10 (ICD-10) definitions through an iterative process of reviewing the diseases considered by previous health economic models of smoking, and reviewing reports and papers that reviewed the disease risks of smoking. The main UK focused modelling of smoking is the NICE Tobacco Return on Investment Tool (Pokhrel et al. 2013), and the national monitoring of the health costs of smoking (Callum and White 2004; NHS Digital 2018). In 2014, the US Surgeon General conducted a review of the diseases related to smoking, taking careful consideration of the strength of evidence for causality (US Surgeon General 2014). In 2015, Carter et al (2015) in the New England Journal of Medicine found statistical associations in the American Cancer Society’s Cancer Prevention II study (ACS-CPS II) between smoking and a much wider range of diseases than were previously considered smoking related. In 2018, Chapter 2 of the Royal College of Physician’s (RCP) report “Hiding in plain sight: Treating tobacco dependency in the NHS” (Tobacco Advisory Group of the Royal College of Physicians 2018) reviewed the current evidence for smoking–disease associations, focusing on recent meta-analyses, to produce an updated list of diseases that are caused by smoking. Subsequently, Cancer Research UK (CRUK) produced their own disease list and published sources for estimates of the relative risk of current vs. never smoking for developing cancers (in a study that considered smoking as one of a range of modifiable risk factors related to cancer) (Brown et al. 2018).

+

We began to develop our list of diseases in 2015. The list was influence heavily by our involvement in Chapter 2 of the RCP report. We were then further influenced by discussions within our research group relating to updates to the list of diseases related to alcohol, their ICD-10 code definitions and the published sources of relative risk estimates. As part of these discussions for alcohol we made contact with the lead author of the CRUK paper, Dr Katrina Brown. Discussions focused particularly on the ICD-10 definitions of head and neck cancers, and oesophageal cancers. The result of these discussions was an updated list of alcohol related diseases for the Sheffield Alcohol Policy Model (SAPM) v4.0 (Angus et al. 2018). In producing our list of smoking related diseases we sought to harmonise our ICD-10 definitions with those used in our alcohol modelling (particularly important since we will conduct joint modelling of tobacco and alcohol). Our list is mainly consistent with the RCP report, with most deviations being for cancers, where we have been influenced by CRUK’s work and our alcohol modelling. We explain the choices we made in the report where we initially presented our disease list (Webster et al. 2018).

+

The notable omissions from our list are: Breast cancer - due to a small and statistially uncertain effect of smoking; Prostate cancer - due to a lack of published evidence for current smokers; Ovarian cancer - for which smoking only carries a risk for fully malignant mucinous ovarian cancers (13% of ovarian cancers are mucinous, and of these 57% are fully malignant) - that created large uncertainty in identifying the cases attributable to smoking using the ICD-10 definitions recorded in our mortality data and hospital episode statistics.

+
+

+Oesophageal cancer

+

For oesophageal cancer, our discussions with CRUK concluded that we should distinguish between adenocarcinoma (AC) and squamous cell carcinoma (SCC). However, it is not possible to distinguish these subtypes from the routinely recorded ICD-10 codes. We therefore settled on the following approach:

+

We apportion overall oesophageal cancer prevalence between AC and SCC using data on percentage prevalence by age and sex, which we were sent by Katrina Brown at CRUK. CRUK requested data direct from the UK cancer registries on the number of oesophageal SCCs. That data isn’t routinely available because it is morphology (cell type) data, whereas what is published as standard is topography (body part). Alternatively, we could distinguish SCC using the body sites ‘upper third of oesophagus’ and ‘middle third of oesophagus’ (ICD-10 codes C15.3 and C15.4) as a fairly good proxy for SCC (Coupland et al. 2012). Arnold et al (2015) also provide splits of Oesophageal cancer by subtype for Northern and Western Europe, which could be an alternative source of data (and might be the approach used in the Global Burden of Disease Study).

+

The percentages provided to us by CRUK are for 2014 for England. We therefore need to be aware that in modelling periods that are substantially earlier or later, the percentages might not hold true. Specifically, AC incidence in males has risen over time while AC incidence in females, and SCC incidence in both sexes, has remained fairly stable – so the relative proportions of AC and SCC in males have varied over time. We should also consider whether it is sensible to assume the distribution of AC and SCC in oesophageal cancer will be the same for deaths as it is for cases. Coupland et al (2012) show that 1 year and 5 year overall survival is significantly lower in SCC (1yr 30.3%, 5yr 8.3%) than in AC (5yr 36.4%, 5yr 9.4%) – though the absolute differences are quite small. So arguably there would be a slightly higher ratio of SCC:AC in deaths than in cases.

+ + ++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Our list of adult diseases related to smoking.
CategoryDiseaseICD 10Source
Malignant neoplasmsOral cavityC00-C06(Maasland et al. 2014)
PharynxC09, C10, C12-C14(Gandini et al. 2008)
LungC33, C34(Jayes et al. 2016)
Nasopharynx sinonasalC11, C30, C31(Gandini et al. 2008)
LarynxC32(Zuo et al. 2017)
Oesophageal (Adenocarcinoma)C15(Tramacere, La Vecchia, and Negri 2011)
Oesophageal (Squamous cell carcinoma)C15(Prabhu, Obi, and Rubenstein 2013)
StomachC16(Ordóñez-Mena et al. 2016)
PancreasC25(Ordóñez-Mena et al. 2016)
LiverC22(Lee et al. 2009)
ColorectalC18-C20(Ordóñez-Mena et al. 2016)
KidneyC64(Cumberbatch et al. 2016)
Lower urinary tractC65, C66(Gandini et al. 2008)
BladderC67(Osch et al. 2016)
CervicalC53(Gandini et al. 2008)
Acute myeloid leukaemiaC92(Colamesta et al. 2016)
Circulatory systemIschaemic heart diseaseI20-I25(Rostron 2012)
Haemorrhagic strokeI60-I62(Peters, Huxley, and Woodward 2013)
Ischaemic strokeI63-I67(Peters, Huxley, and Woodward 2013)
Peripheral arterial diseaseI73.9(Lu, Mackay, and Pell 2014)
Abdominal aortic aneurysmI71(Cornuz et al. 2004)
Venous thromboembolismI26,I80-I82(Cheng et al. 2013)
Respiratory systemChronic obstructive pulmonary diseaseJ40-J44,J47(Jayes et al. 2016)
AsthmaJ45-J46(Jayes et al. 2016)
TuberculosisA15-A19(Jayes et al. 2016)
Obstructive sleep apnoeaG47.3(Jayes et al. 2016)
PneumoniaJ12-J18(Tobacco Advisory Group of the Royal College of Physicians 2018)
Influenza (clinically diagnosed)J11(Tobacco Advisory Group of the Royal College of Physicians 2018)
Influenza (microbiologically confirmed)J09, J10(Tobacco Advisory Group of the Royal College of Physicians 2018)
Idiopathic pulmonary fibrosisJ84.1(Taskar and Coultas 2006)
OtherDiabetesE11(Pan et al. 2015)
Alzheimers diseaseG30(Zhong et al. 2015)
Multiple sclerosisG35(Zhang et al. 2016)
ParkinsonG20(Breckenridge et al. 2016)
Vascular dementiaF01(Zhong et al. 2015)
All cause dementiaF02,F03(Zhong et al. 2015)
DepressionF32,F33(Luger, Suls, and Vander Weg 2014)
SchizophreniaF20-F25(Tobacco Advisory Group of the Royal College of Physicians 2018)
PsychosisF28,F29(Gurillo et al. 2015)
BulimiaF50.2(Solmi et al. 2016)
Systematic lupus erythematosisM32(Jiang, Li, and Jia 2015)
Low back painM54(Shiri et al. 2010)
Rheumatoid arthritisM05,M06(Di Giuseppe et al. 2014)
PsoriasisL40(Armstrong et al. 2014)
Age related macular degenerationH35.3-H52.4(Chakravarthy et al. 2010)
Senile cataractH25(Ye et al. 2012)
Crohns diseaseK50(???)
Ulcerative colitisK51(Dias et al. 2015)
Hip fractureS72.0-S72.2(Shen et al. 2015)
Chronic kidney diseaseN18.1,N18.2,N18.3, N18.4,N18.8,N18.9(Xia et al. 2017)
End-stage renal diseaseN18.5,N18.0(Xia et al. 2017)
Hearing lossH90,H91(Nomura, Nakao, and Morimoto 2005)
+
+
+
+

+Relative risks of disease

+

From the sources given in Table 1, we extracted the relative risks of current vs. never smoking and their 95% confidence intervals. We illustrate these in Figure 1, ordered by the strength of relationship to smoking. We do not incorporate the uncertainty around these relative risks in our modelling, but this is an obvious area for improvement. We assume the equivalence of relative risks and odds ratios.

+
+

+Dose-response effects of smoking

+

The extent to which someone is at risk of a smoking related disease also depends on how much they smoke, and for how long they have smoked, i.e. the accumulated dose-response effects of smoking. However, we do not currently incorporate these dose-response effects. Instead we use the average differences in disease risk between people who currently smoke (to any level or history) and never smokers.

+

Not incorporating these dose-response effects of smoking into our model has two potential disadvantages for assessing the impact of tobacco control policy. First, the effects of reductions in smoking initiation cannot properly be assessed, because without tracking the accumulation of disease risk over the life course, the reduction in lifetime risk is not estimable. Second, the effects on disease risk of quitting smoking cannot be estimated accurately. This is because – when we operationalise the theory that disease risk declines gradually after quitting smoking (Doll et al. 2004) – we cannot accurately know the current risk faced by each newly quit individual i.e. we don’t know from what level the risk will decline. Furthermore, both these considerations have implications for our estimates of how changes to smoking initiation and quitting affect socioeconomic inequalities in disease risk – due to socioeconomic differences in the lifetime accumulation of disease risk not currently featuring in population models.

+

From our pilot searches for evidence on dose-response effects, we selected 12 illustrative studies, each for a different type of cancer (Tredaniel et al. 1997; Macacu et al. 2015; Zou et al. 2014; Xu et al. 2012; Liang, Chen, and Giovannucci 2009, 2009; Maasland et al. 2014; Fircanis et al. 2014; Osch et al. 2016; Pang et al. 2015; Gandini et al. 2008). They show the inconsistency in reporting of exposure (current smoking intensity, duration, pack-years), level of exposure (e.g. categorical vs. continuous) and in the format that the risk relationships are reported (in one study, the information we would want to extract is not reported, so we would need to contact the authors). For cancer of the oral cavity, we did not find a meta-analysis but did find a recent and cohort study (Maasland et al. 2014), suggesting that we might have to relax our criteria to look only at meta-analyses.

+
+Relative risks of disease in current vs. never smokers.

+Relative risks of disease in current vs. never smokers. +

+
+
+
+

+Decline in risk over time after quitting smoking

+

To estimate the risk of disease for former smokers we used the findings of Kontis et al. (2014), who re-analysed the change in risk after smoking in the ACS-CPS II study from Oza et al.(2011), producing three functions to describe the decline in risk after quitting for each of cancers, cardiovascular disease (CVD) and chronic obstructive pulmonary disease (COPD) (Figure 2). The estimates were informed by data on former smokers with known quit dates who were disease-free at baseline. The results show the proportion of excess relative risk remaining at each time-point since cessation.

+

In an effort to validate these estimates, we checked them against the range of estimates for laryngeal cancer, oropharyngeal cancer and oesophageal cancer found by the International Agency for Research on Cancer’s (IARC) 2007 review of the decline in risk after quitting smoking (International Agency for Research on Cancer and World Health Organization 2007). The results are shown in Figures 3-5. Most past studies do not treat the decline in risk after quitting as a continuous function of time, rather estimating the effect for variously defined categories of time. In some cases, risk is observed to be higher shortly after quitting for former smokers, which might indicate that the condition takes time to emerge after the damage is done by past smoking, or that these studies could have controlled better for individual heterogeneity. In general, the estimates of Kontis et al. (2014) fall within the cloud of estimates.

+

Thus, even though there is potential to improve on the ACS-CPS II evidence used by Kontis et al. (2014) (e.g. using the results of meta-analyses found through searching for the dose-response evidence), we adopt the approach of Kontis et al. (2014).

+

However, since Kontis et al. (2014) only provide estimates for cancers, CVD or COPD, we must decide how to specify the rates of decline in the risks due to smoking after quitting for other diseases. Kontis et al. (2014) consider this issue for type II diabetes, stating that “Randomised trials also indicate that the benefits of behaviour change and pharmacological treatment on diabetes risk occur within a few years, more similar to the CVDs than cancers (Knowler et al. 2002). Therefore, we used the CVD curve for diabetes.” In-line with Kontis et al. (2014), we apply the rate of decline in risk of CVD after quitting smoking to type 2 diabetes.

+

We have begun to develop our own further assumptions: We assume that the decline in risk for all respiratory conditions follows Kontis et al.’s (2014) estimates for COPD. For other diseases, we might assume that the decline in relative risk follows the cancer curve (the most conservative option), that the additional risk from smoking disappears immediately following quitting (the least conservative option), or that the risk immediately falls to the average risk in former smokers identified from meta-analyses (potentially a middle-ground option?). However, these assumptions are based on no or limited evidence and will need revisiting to see what use might be made of existing evidence and expert opinion to develop a credible approach.

+
+Rate at which the excess risk of disease due to smoking declines over time after quitting.

+Rate at which the excess risk of disease due to smoking declines over time after quitting. +

+
+
+Comparison of decline in cancer risk after quitting to results of IARC review for Laryngeal cancers.

+Comparison of decline in cancer risk after quitting to results of IARC review for Laryngeal cancers. +

+
+
+Comparison of decline in cancer risk after quitting to results of IARC review for Oropharyngeal.

+Comparison of decline in cancer risk after quitting to results of IARC review for Oropharyngeal. +

+
+
+Comparison of decline in cancer risk after quitting to results of IARC review for Oesophageal cancers.

+Comparison of decline in cancer risk after quitting to results of IARC review for Oesophageal cancers. +

+
+
+
+
+

+Use of relative risks in STPM

+

The functions to assign relative risks to each individual based on their current or former smoking status are in the tobalcepi R package, which is part of the set of R packages containing the code that underlies STPM.

+

The function RRFunc() does the job of assigning the relative risks of each disease to a sample of individuals according to their current tobacco consumption status. Since STPM is a part of our joint programme of modelling across tobacco and alcohol, RRFunc() has options that can tailor it to assign risks based on tobacco consumption only, alcohol consumption only, or both tobacco and alcohol consumption.

+

For tobacco, the relative risk for each individual is calculated based on whether they are a current, former or never smoker. Currently, all current smokers have the same relative risk regardless of the amount they currently smoke or have smoked in the past. Former smokers are initially given the relative risk associated with current smokers, which we then scale according to a disease-specific function that describes how risk declines after quitting smoking.

+

The first step carried out by RRFunc() is to assign both current and former smokers the relative risk for each disease associated with current smoking. It does this using the function RRTob(). For former smokers, we estimate the risk in former smokers using the equation

+

\[\begin{equation} +R_{former}=1+[R_{current}-1][1-p(t)], +\end{equation}\]

+

in which the relative risk (\(R\)) associated with current smoking is scaled according to our estimates of the proportional reduction in the risk (\(p\)) associated with their number of years (\(t\)) as a former smoker. After someone has been quit for 40 years, we assume their risk reverts back to be the same as a never smoker.

+

The current version of STPM models the individual-level dynamics of smoking and the associated risks of disease, but it links these to the population-level trends in the rates of morbidity and mortality from each disease. In other words, STPM models the direct link between smoking and disease prevalence rather than modelling the link between smoking and disease incidence (which would then have a knock-on effect to prevalence).

+

We define the effect of an intervention on the rates of disease morbidity and mortality in terms of a proportional change, stratified by year, age, sex and quintiles of the Index of Multiple Deprivation. The proportional change is the ratio of the average risks in each of these subgroups in the treatment compared to the control arms of the model (see the STPM vignette for further details). This proportional change is also known as the ‘potential impact fraction’ (PIF = ratio of weighted average revised risk given a policy to the weighted average baseline risk given current consumption levels). The PIF approach to updating the population-level rates of morbidity and mortality originated in the PREVENT model (Gunningschepers 1989) and was extend to underlie the Sheffield Alcohol Policy Model (Brennan et al. 2015).

+

Thus, after assigning each individual (\(i\)) a relative risk for each disease (\(h\)) based on their current smoking status, we then calculate the average risk (\(\bar{R}\)) across the \(N\) individuals in each subgroup (\(s\))

+

\[\begin{equation} +\bar{R}_s^h= \frac{1}{N_s}\sum_{i\in{s}}R^h_i. +\end{equation}\]

+

This average risk is calculated by the function subgroupRisk(). The functon UpdateHarm() in the stapmr R package calculates and applies the PIF.

+

The tobalcepi package contains data on smoking from the Health Survey for England, 2001-2016 in hse_data_smoking. To illustrate, we take a subset of 10,000 individuals from these data, assign them their smoking attributable relative risks for laryngeal cancer, and calculate the average risk for males and females.

+
+
+

+Code developments

+

To integrate dose-response risk functions into our modelling, we have started to develop a new function to replace RRtob(). The function RRTobDR estimates each individual in the data their dose-response relative risk based on the number of cigarettes they consume per day. This function has not yet been integrated into the function RRFunc().

+

In order to this this we need to work out if and how we assign risk to former smokers, as there is no cigs per day information for former smokers.

+
+
+

+References

+
+
+

Angus, Colin, M Henney, L Webster, and Duncan Gillespie. 2018. Alcohol-Attributable Diseases and Dose-Response Curves for the Sheffield Alcohol Policy Model Version 4.0. Book. https://doi.org/10.15131/shef.data.6819689.v1.

+
+
+

Armstrong, A. W., C. T. Harskamp, J. S. Dhillon, and E. J. Armstrong. 2014. “Psoriasis and Smoking: A Systematic Review and Meta-Analysis.” Journal Article. Br J Dermatol 170 (2): 304–14. https://doi.org/10.1111/bjd.12670.

+
+
+

Arnold, Melina, Isabelle Soerjomataram, Jacques Ferlay, and David Forman. 2015. “Global Incidence of Oesophageal Cancer by Histological Subtype in 2012.” Journal Article. Gut 64 (3): 381–87.

+
+
+

Breckenridge, Charles B., Colin Berry, Ellen T. Chang, Jr. Sielken Robert L., and Jack S. Mandel. 2016. “Association Between Parkinson’s Disease and Cigarette Smoking, Rural Living, Well-Water Consumption, Farming and Pesticide Use: Systematic Review and Meta-Analysis.” Journal Article. PLOS ONE 11 (4): e0151841. https://doi.org/10.1371/journal.pone.0151841.

+
+
+

Brennan, Alan, Petra Meier, Robin Purshouse, Rachid Rafia, Yang Meng, Daniel Hill-Macmanus, Colin Angus, and John Holmes. 2015. “The Sheffield Alcohol Policy Model – a Mathematical Description.” Journal Article. Health Economics 24 (10): 1368–88. https://doi.org/10.1002/hec.3105.

+
+
+

Brown, Katrina F., Harriet Rumgay, Casey Dunlop, Margaret Ryan, Frances Quartly, Alison Cox, Andrew Deas, et al. 2018. “The Fraction of Cancer Attributable to Modifiable Risk Factors in England, Wales, Scotland, Northern Ireland, and the United Kingdom in 2015.” Journal Article. British Journal of Cancer 118 (8): 1130–41. https://doi.org/10.1038/s41416-018-0029-6.

+
+
+

Callum, Christine, and Patti White. 2004. Tobacco in London: The Preventable Burden. Book. SmokeFree London.

+
+
+

Carter, Brian D., Christian C. Abnet, Diane Feskanich, Neal D. Freedman, Patricia Hartge, Cora E. Lewis, Judith K. Ockene, et al. 2015. “Smoking and Mortality - Beyond Established Causes.” Journal Article. New England Journal of Medicine 372 (7): 631–40. https://doi.org/10.1056/NEJMsa1407211.

+
+
+

Chakravarthy, Usha, Tien Y Wong, Astrid Fletcher, Elisabeth Piault, Christopher Evans, Gergana Zlateva, Ronald Buggage, Andreas Pleil, and Paul Mitchell. 2010. “Clinical Risk Factors for Age-Related Macular Degeneration: A Systematic Review and Meta-Analysis.” Journal Article. BMC Ophthalmology 10 (1): 31.

+
+
+

Cheng, Yun-Jiu, Zhi-Hao Liu, Feng-Juan Yao, Wu-Tao Zeng, Dong-Dan Zheng, Yu-Gang Dong, and Su-Hua Wu. 2013. “Current and Former Smoking and Risk for Venous Thromboembolism: A Systematic Review and Meta-Analysis.” Journal Article. PLoS Medicine 10 (9): e1001515.

+
+
+

Colamesta, Vittoria, Silvia D’Aguanno, Massimo Breccia, Sara Bruffa, Claudio Cartoni, and Giuseppe La Torre. 2016. “Do the Smoking Intensity and Duration, the Years Since Quitting, the Methodological Quality and the Year of Publication of the Studies Affect the Results of the Meta-Analysis on Cigarette Smoking and Acute Myeloid Leukemia (Aml) in Adults?” Journal Article. Critical Reviews in Oncology/Hematology 99: 376–88.

+
+
+

Cornuz, Jacques, Claudio Sidoti Pinto, Heindrik Tevaearai, and Matthias Egger. 2004. “Risk Factors for Asymptomatic Abdominal Aortic Aneurysm: Systematic Review and Meta-Analysis of Population-Based Screening Studies.” Journal Article. The European Journal of Public Health 14 (4): 343–49.

+
+
+

Coupland, V. H., W. Allum, J. M. Blazeby, M. A. Mendall, R. H. Hardwick, K. M. Linklater, H. Moller, and E. A. Davies. 2012. “Incidence and Survival of Oesophageal and Gastric Cancer in England Between 1998 and 2007, a Population-Based Study.” Journal Article. BMC Cancer 12: 11. https://doi.org/10.1186/1471-2407-12-11.

+
+
+

Cumberbatch, Marcus G, Matteo Rota, James WF Catto, and Carlo La Vecchia. 2016. “The Role of Tobacco Smoke in Bladder and Kidney Carcinogenesis: A Comparison of Exposures and Meta-Analysis of Incidence and Mortality Risks.” Journal Article. European Urology 70 (3): 458–66.

+
+
+

Dias, C. C., P. P. Rodrigues, A. da Costa-Pereira, and F. Magro. 2015. “Clinical Predictors of Colectomy in Patients with Ulcerative Colitis: Systematic Review and Meta-Analysis of Cohort Studies.” Journal Article. J Crohns Colitis 9 (2): 156–63. https://doi.org/10.1093/ecco-jcc/jju016.

+
+
+

Di Giuseppe, Daniela, Andrea Discacciati, Nicola Orsini, and Alicja Wolk. 2014. “Cigarette Smoking and Risk of Rheumatoid Arthritis: A Dose-Response Meta-Analysis.” Journal Article. Arthritis Research & Therapy 16 (2): R61.

+
+
+

Doll, Richard, Richard Peto, Jillian Boreham, and Isabelle Sutherland. 2004. “Mortality in Relation to Smoking: 50 Years’ Observations on Male British Doctors.” Journal Article. Bmj 328 (7455): 1519.

+
+
+

Fircanis, Sophia, Priscilla Merriam, Naushaba Khan, and Jorge J Castillo. 2014. “The Relation Between Cigarette Smoking and Risk of Acute Myeloid Leukemia: An Updated Meta‐analysis of Epidemiological Studies.” Journal Article. American Journal of Hematology 89 (8): E125–E132.

+
+
+

Gandini, Sara, Edoardo Botteri, Simona Iodice, Mathieu Boniol, Albert B Lowenfels, Patrick Maisonneuve, and Peter Boyle. 2008. “Tobacco Smoking and Cancer: A Meta‐analysis.” Journal Article. International Journal of Cancer 122 (1): 155–64. https://onlinelibrary.wiley.com/doi/pdf/10.1002/ijc.23033.

+
+
+

Gunningschepers, L. 1989. “The Health Benefits of Preventions - a Simulation Approach.” Journal Article. Health Policy 12 (1-2): 1–255. <Go to ISI>://WOS:A1989AD34000001.

+
+
+

Gurillo, Pedro, Sameer Jauhar, Robin M. Murray, and James H. MacCabe. 2015. “Does Tobacco Use Cause Psychosis? Systematic Review and Meta-Analysis.” Journal Article. The Lancet Psychiatry 2 (8): 718–25. https://doi.org/10.1016/S2215-0366(15)00152-2.

+
+
+

International Agency for Research on Cancer and World Health Organization. 2007. “Reversal of Risk After Quitting Smoking.” Report.

+
+
+

Jayes, Leah, Patricia L. Haslam, Christina G. Gratziou, Pippa Powell, John Britton, Constantine Vardavas, Carlos Jimenez-Ruiz, and Jo Leonardi-Bee. 2016. “SmokeHaz: Systematic Reviews and Meta-Analyses of the Effects of Smoking on Respiratory Health.” Journal Article. CHEST Journal 150 (1): 164–79.

+
+
+

Jiang, Fan, Suyun Li, and Chongqi Jia. 2015. “Smoking and the Risk of Systemic Lupus Erythematosus: An Updated Systematic Review and Cumulative Meta-Analysis.” Journal Article. Clinical Rheumatology 34 (11): 1885–92.

+
+
+

Knowler, William C, Elizabeth Barrett-Connor, Sarah E Fowler, Richard F Hamman, John M Lachin, Elizabeth A Walker, and David M Nathan. 2002. “Reduction in the Incidence of Type 2 Diabetes with Lifestyle Intervention or Metformin.” Journal Article. The New England Journal of Medicine 346 (6): 393–403.

+
+
+

Kontis, Vasilis, Colin D Mathers, Jürgen Rehm, Gretchen A Stevens, Kevin D Shield, Ruth Bonita, Leanne M Riley, Vladimir Poznyak, Robert Beaglehole, and Majid Ezzati. 2014. “Contribution of Six Risk Factors to Achieving the 25× 25 Non-Communicable Disease Mortality Reduction Target: A Modelling Study.” Journal Article. The Lancet 384 (9941): 427–37.

+
+
+

Lee, Yuan-Chin Amy, Catherine Cohet, Yu-Ching Yang, Leslie Stayner, Mia Hashibe, and Kurt Straif. 2009. “Meta-Analysis of Epidemiologic Studies on Cigarette Smoking and Liver Cancer.” Journal Article. International Journal of Epidemiology 38 (6): 1497–1511.

+
+
+

Liang, PS, TY Chen, and E Giovannucci. 2009. “Cigarette Smoking and Colorectal Cancer Incidence and Mortality: Systematic Review and Meta-Analysis.” Journal Article. International Journal of Cancer 124 (10): 2406–15. https://onlinelibrary.wiley.com/doi/pdf/10.1002/ijc.24191.

+
+
+

Lu, L, DF Mackay, and JP Pell. 2014. “Meta-Analysis of the Association Between Cigarette Smoking and Peripheral Arterial Disease.” Journal Article. Heart 100 (5): 414–23.

+
+
+

Luger, Tana M., Jerry Suls, and Mark W. Vander Weg. 2014. “How Robust Is the Association Between Smoking and Depression in Adults? A Meta-Analysis Using Linear Mixed-Effects Models.” Journal Article. Addictive Behaviors 39 (10): 1418–29. https://doi.org/http://doi.org/10.1016/j.addbeh.2014.05.011.

+
+
+

Maasland, Denise HE, Piet A van den Brandt, Bernd Kremer, R Alexandra Sandra Goldbohm, and Leo J Schouten. 2014. “Alcohol Consumption, Cigarette Smoking and the Risk of Subtypes of Head-Neck Cancer: Results from the Netherlands Cohort Study.” Journal Article. BMC Cancer 14 (1): 187.

+
+
+

Macacu, A., P. Autier, M. Boniol, and P. Boyle. 2015. “Active and Passive Smoking and Risk of Breast Cancer: A Meta-Analysis.” Journal Article. Breast Cancer Research and Treatment 154 (2): 213–24. https://doi.org/10.1007/s10549-015-3628-4.

+
+
+

NHS Digital. 2018. “Statistics on Smoking: England, 2018.” Report.

+
+
+

Nomura, Kyoko, Mutsuhiro Nakao, and Takeshi Morimoto. 2005. “Effect of Smoking on Hearing Loss: Quality Assessment and Meta-Analysis.” Journal Article. Preventive Medicine 40 (2): 138–44.

+
+
+

Ordóñez-Mena, José Manuel, Ben Schöttker, Ute Mons, Mazda Jenab, Heinz Freisling, Bas Bueno-de-Mesquita, Mark G O’Doherty, Angela Scott, Frank Kee, and Bruno H Stricker. 2016. “Quantification of the Smoking-Associated Cancer Risk with Rate Advancement Periods: Meta-Analysis of Individual Participant Data from Cohorts of the Chances Consortium.” Journal Article. BMC Medicine 14 (1): 62.

+
+
+

Osch, Frits HM van, Sylvia HJ Jochems, Frederik-Jan van Schooten, Richard T Bryan, and Maurice P Zeegers. 2016. “Quantified Relations Between Exposure to Tobacco Smoking and Bladder Cancer Risk: A Meta-Analysis of 89 Observational Studies.” Journal Article. International Journal of Epidemiology 45 (3): 857–70.

+
+
+

Oza, Shefali, Michael J Thun, S Jane Henley, Alan D Lopez, and Majid Ezzati. 2011. “How Many Deaths Are Attributable to Smoking in the United States? Comparison of Methods for Estimating Smoking-Attributable Mortality When Smoking Prevalence Changes.” Journal Article. Preventive Medicine 52 (6): 428–33.

+
+
+

Pan, An, Yeli Wang, Mohammad Talaei, Frank B Hu, and Tangchun Wu. 2015. “Relation of Active, Passive, and Quitting Smoking with Incident Type 2 Diabetes: A Systematic Review and Meta-Analysis.” Journal Article. The Lancet Diabetes & Endocrinology 3 (12): 958–67.

+
+
+

Pang, Q., K. Qu, J. Zhang, X. Xu, S. Liu, S. Song, R. Wang, L. Zhang, Z. Wang, and C. Liu. 2015. “Cigarette Smoking Increases the Risk of Mortality from Liver Cancer: A Clinical-Based Cohort and Meta-Analysis.” Journal Article. Journal of Gastroenterology & Hepatology 30 (10): 1450–60.

+
+
+

Peters, Sanne AE, Rachel R Huxley, and Mark Woodward. 2013. “Smoking as a Risk Factor for Stroke in Women Compared with Men: A Systematic Review and Meta-Analysis of 81 Cohorts, Including 3 980 359 Individuals and 42 401 Strokes.” Journal Article. Stroke 44 (10): 2821–8.

+
+
+

Pokhrel, S., L. Owen, A. Lester-George, K. Coyle, Coyle D., West R., Trapero-Bertran M., and Meads C. 2013. “Tobacco Control Return on Investment Tool.” Report. National Institute for Health; Care Excellence.

+
+
+

Prabhu, A, KO Obi, and JH Rubenstein. 2013. “Systematic Review with Meta‐analysis: Race‐specific Effects of Alcohol and Tobacco on the Risk of Oesophageal Squamous Cell Carcinoma.” Journal Article. Alimentary Pharmacology & Therapeutics 38 (10): 1145–55.

+
+
+

Rostron, Brian. 2012. “Smoking-Attributable Mortality by Cause in the United States: Revising the Cdc’s Data and Estimates.” Journal Article. Nicotine & Tobacco Research 15 (1): 238–46.

+
+
+

Shen, Guang Si, Yong Li, GuoYang Zhao, Hai Bin Zhou, Zong Gang Xie, Wei Xu, Hai Nan Chen, Qi Rong Dong, and You Jia Xu. 2015. “Cigarette Smoking and Risk of Hip Fracture in Women: A Meta-Analysis of Prospective Cohort Studies.” Journal Article. Injury 46 (7): 1333–40.

+
+
+

Shiri, Rahman, Jaro Karppinen, Päivi Leino-Arjas, Svetlana Solovieva, and Eira Viikari-Juntura. 2010. “The Association Between Smoking and Low Back Pain: A Meta-Analysis.” Journal Article. The American Journal of Medicine 123 (1): 87. e7–87. e35.

+
+
+

Solmi, Marco, Nicola Veronese, Giuseppe Sergi, Claudio Luchini, Angela Favaro, Paolo Santonastaso, Davy Vancampfort, et al. 2016. “The Association Between Smoking Prevalence and Eating Disorders: A Systematic Review and Meta-Analysis.” Journal Article. Addiction 111 (11): 1914–22. https://doi.org/10.1111/add.13457.

+
+
+

Taskar, Varsha S, and David B Coultas. 2006. “Is Idiopathic Pulmonary Fibrosis an Environmental Disease?” Journal Article. Proceedings of the American Thoracic Society 3 (4): 293–98.

+
+
+

Tobacco Advisory Group of the Royal College of Physicians. 2018. “Hiding in plain sight: Treating tobacco dependency in the NHS.” Research report. Available from: Https://Www.rcplondon.ac.uk/Projects/Outputs/Hiding-Plain-Sight-Treating-Tobacco-Dependency-Nhs.

+
+
+

Tramacere, Irene, Carlo La Vecchia, and Eva Negri. 2011. “Brief Report: Tobacco Smoking and Esophageal and Gastric Cardia Adenocarcinoma: A Meta-Analysis.” Journal Article. Epidemiology, 344–49.

+
+
+

Tredaniel, J., P. Boffetta, E. Buiatti, R. Saracci, and A. Hirsch. 1997. “Tobacco Smoking and Gastric Cancer: Review and Meta-Analysis.” Journal Article. International Journal of Cancer 72 (4): 565–73. https://onlinelibrary.wiley.com/doi/pdf/10.1002/%28SICI%291097-0215%2819970807%2972%3A4%3C565%3A%3AAID-IJC3%3E3.0.CO%3B2-O.

+
+
+

US Surgeon General. 2014. “The Health Consequences of Smoking–50 Years of Progress: A Report of the Surgeon General. US Department of Health and Human Services, Centers for Disease Control and Prevention.” Journal Article. National Center for Chronic Disease Prevention and Health Promotion, Office on Smoking and Health.

+
+
+

Webster, L, C Angus, A Brennan, and D. Gillespie. 2018. “Smoking and the Risks of Adult Diseases.” Journal Article.

+
+
+

Xia, Jia, Lin Wang, Zhiheng Ma, Liping Zhong, Ying Wang, Yachan Gao, Liqun He, and Xiao Su. 2017. “Cigarette Smoking and Chronic Kidney Disease in the General Population: A Systematic Review and Meta-Analysis of Prospective Cohort Studies.” Journal Article. Nephrology Dialysis Transplantation 32 (3): 475–87.

+
+
+

Xu, F. H., D. Xiong, Y. F. Xu, S. M. Cao, W. Q. Xue, H. D. Qin, W. S. Liu, et al. 2012. “An Epidemiological and Molecular Study of the Relationship Between Smoking, Risk of Nasopharyngeal Carcinoma, and Epsteinbarr Virus Activation.” Journal Article. Jnci-Journal of the National Cancer Institute 104 (18): 1396–1410. https://doi.org/10.1093/jnci/djs320.

+
+
+

Ye, Juan, Jinjing He, Changjun Wang, Han Wu, Xin Shi, Huina Zhang, Jiajun Xie, and Sang Yeul Lee. 2012. “Smoking and Risk of Age-Related Cataract: A Meta-Analysis.” Journal Article. Investigative Ophthalmology & Visual Science 53 (7): 3885–95.

+
+
+

Zhang, Peng, Rui Wang, Zhijun Li, Yuhan Wang, Chunshi Gao, Xin Lv, Yuanyuan Song, and Bo Li. 2016. “The Risk of Smoking on Multiple Sclerosis: A Meta-Analysis Based on 20,626 Cases from Case-Control and Cohort Studies.” Journal Article. PeerJ 4: e1797.

+
+
+

Zhong, Guochao, Yi Wang, Yong Zhang, Jeff Jianfei Guo, and Yong Zhao. 2015. “Smoking Is Associated with an Increased Risk of Dementia: A Meta-Analysis of Prospective Cohort Studies with Investigation of Potential Effect Modifiers.” Journal Article. PLoS One 10 (3): e0118333.

+
+
+

Zou, L., R. Zhong, N. Shen, W. Chen, B. Zhu, J. Ke, X. Lu, et al. 2014. “Non-Linear Dose-Response Relationship Between Cigarette Smoking and Pancreatic Cancer Risk: Evidence from a Meta-Analysis of 42 Observational Studies.” Journal Article. European Journal of Cancer 50 (1): 193–203.

+
+
+

Zuo, Jing-Jing, Ze-Zhang Tao, Chen Chen, Zhang-Wei Hu, Ye-Xing Xu, An-Yuan Zheng, and Yi Guo. 2017. “Characteristics of Cigarette Smoking Without Alcohol Consumption and Laryngeal Cancer: Overall and Time-Risk Relation. A Meta-Analysis of Observational Studies.” Journal Article. European Archives of Oto-Rhino-Laryngology 274 (3): 1617–31.

+
+
+
+
+ + + +
+ + + + +
+ + + + + + diff --git a/docs/articles/smoking-disease-risks_files/figure-html/rel risks-1.png b/docs/articles/smoking-disease-risks_files/figure-html/rel risks-1.png new file mode 100644 index 0000000..e8489f1 Binary files /dev/null and b/docs/articles/smoking-disease-risks_files/figure-html/rel risks-1.png differ diff --git a/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison Oropharyngeal-1.png b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison Oropharyngeal-1.png new file mode 100644 index 0000000..48d294f Binary files /dev/null and b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison Oropharyngeal-1.png differ diff --git a/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison laryngeal-1.png b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison laryngeal-1.png new file mode 100644 index 0000000..cdb9e24 Binary files /dev/null and b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison laryngeal-1.png differ diff --git a/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison oesophageal-1.png b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison oesophageal-1.png new file mode 100644 index 0000000..b2bcb6a Binary files /dev/null and b/docs/articles/smoking-disease-risks_files/figure-html/tob lags IARC comparison oesophageal-1.png differ diff --git a/docs/articles/smoking-disease-risks_files/figure-html/tob lags-1.png b/docs/articles/smoking-disease-risks_files/figure-html/tob lags-1.png new file mode 100644 index 0000000..4d3c0ee Binary files /dev/null and b/docs/articles/smoking-disease-risks_files/figure-html/tob lags-1.png differ diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 0000000..c665e73 --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,167 @@ + + + + + + + + +Authors • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + + + +
+ +
+ + + + +
+ + + + + + + + diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css new file mode 100644 index 0000000..5a85941 --- /dev/null +++ b/docs/bootstrap-toc.css @@ -0,0 +1,60 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ + +/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ + +/* All levels of nav */ +nav[data-toggle='toc'] .nav > li > a { + display: block; + padding: 4px 20px; + font-size: 13px; + font-weight: 500; + color: #767676; +} +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 19px; + color: #563d7c; + text-decoration: none; + background-color: transparent; + border-left: 1px solid #563d7c; +} +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 18px; + font-weight: bold; + color: #563d7c; + background-color: transparent; + border-left: 2px solid #563d7c; +} + +/* Nav: second level (shown on .active) */ +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} +nav[data-toggle='toc'] .nav .nav > li > a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 30px; + font-size: 12px; + font-weight: normal; +} +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 29px; +} +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 28px; + font-weight: 500; +} + +/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ +nav[data-toggle='toc'] .nav > .active > ul { + display: block; +} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js new file mode 100644 index 0000000..1cdd573 --- /dev/null +++ b/docs/bootstrap-toc.js @@ -0,0 +1,159 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ +(function() { + 'use strict'; + + window.Toc = { + helpers: { + // return all matching elements in the set, or their descendants + findOrFilter: function($el, selector) { + // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ + // http://stackoverflow.com/a/12731439/358804 + var $descendants = $el.find(selector); + return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); + }, + + generateUniqueIdBase: function(el) { + var text = $(el).text(); + var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); + return anchor || el.tagName.toLowerCase(); + }, + + generateUniqueId: function(el) { + var anchorBase = this.generateUniqueIdBase(el); + for (var i = 0; ; i++) { + var anchor = anchorBase; + if (i > 0) { + // add suffix + anchor += '-' + i; + } + // check if ID already exists + if (!document.getElementById(anchor)) { + return anchor; + } + } + }, + + generateAnchor: function(el) { + if (el.id) { + return el.id; + } else { + var anchor = this.generateUniqueId(el); + el.id = anchor; + return anchor; + } + }, + + createNavList: function() { + return $(''); + }, + + createChildNavList: function($parent) { + var $childList = this.createNavList(); + $parent.append($childList); + return $childList; + }, + + generateNavEl: function(anchor, text) { + var $a = $(''); + $a.attr('href', '#' + anchor); + $a.text(text); + var $li = $('
  • '); + $li.append($a); + return $li; + }, + + generateNavItem: function(headingEl) { + var anchor = this.generateAnchor(headingEl); + var $heading = $(headingEl); + var text = $heading.data('toc-text') || $heading.text(); + return this.generateNavEl(anchor, text); + }, + + // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). + getTopLevel: function($scope) { + for (var i = 1; i <= 6; i++) { + var $headings = this.findOrFilter($scope, 'h' + i); + if ($headings.length > 1) { + return i; + } + } + + return 1; + }, + + // returns the elements for the top level, and the next below it + getHeadings: function($scope, topLevel) { + var topSelector = 'h' + topLevel; + + var secondaryLevel = topLevel + 1; + var secondarySelector = 'h' + secondaryLevel; + + return this.findOrFilter($scope, topSelector + ',' + secondarySelector); + }, + + getNavLevel: function(el) { + return parseInt(el.tagName.charAt(1), 10); + }, + + populateNav: function($topContext, topLevel, $headings) { + var $context = $topContext; + var $prevNav; + + var helpers = this; + $headings.each(function(i, el) { + var $newNav = helpers.generateNavItem(el); + var navLevel = helpers.getNavLevel(el); + + // determine the proper $context + if (navLevel === topLevel) { + // use top level + $context = $topContext; + } else if ($prevNav && $context === $topContext) { + // create a new level of the tree and switch to it + $context = helpers.createChildNavList($prevNav); + } // else use the current $context + + $context.append($newNav); + + $prevNav = $newNav; + }); + }, + + parseOps: function(arg) { + var opts; + if (arg.jquery) { + opts = { + $nav: arg + }; + } else { + opts = arg; + } + opts.$scope = opts.$scope || $(document.body); + return opts; + } + }, + + // accepts a jQuery object, or an options object + init: function(opts) { + opts = this.helpers.parseOps(opts); + + // ensure that the data attribute is in place for styling + opts.$nav.attr('data-toggle', 'toc'); + + var $topContext = this.helpers.createChildNavList(opts.$nav); + var topLevel = this.helpers.getTopLevel(opts.$scope); + var $headings = this.helpers.getHeadings(opts.$scope, topLevel); + this.helpers.populateNav($topContext, topLevel, $headings); + } + }; + + $(function() { + $('nav[data-toggle="toc"]').each(function(i, el) { + var $nav = $(el); + Toc.init($nav); + }); + }); +})(); diff --git a/docs/docsearch.css b/docs/docsearch.css new file mode 100644 index 0000000..e5f1fe1 --- /dev/null +++ b/docs/docsearch.css @@ -0,0 +1,148 @@ +/* Docsearch -------------------------------------------------------------- */ +/* + Source: https://github.com/algolia/docsearch/ + License: MIT +*/ + +.algolia-autocomplete { + display: block; + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1 +} + +.algolia-autocomplete .ds-dropdown-menu { + width: 100%; + min-width: none; + max-width: none; + padding: .75rem 0; + background-color: #fff; + background-clip: padding-box; + border: 1px solid rgba(0, 0, 0, .1); + box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); +} + +@media (min-width:768px) { + .algolia-autocomplete .ds-dropdown-menu { + width: 175% + } +} + +.algolia-autocomplete .ds-dropdown-menu::before { + display: none +} + +.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { + padding: 0; + background-color: rgb(255,255,255); + border: 0; + max-height: 80vh; +} + +.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { + margin-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion { + padding: 0; + overflow: visible +} + +.algolia-autocomplete .algolia-docsearch-suggestion--category-header { + padding: .125rem 1rem; + margin-top: 0; + font-size: 1.3em; + font-weight: 500; + color: #00008B; + border-bottom: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { + float: none; + padding-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { + float: none; + width: auto; + padding: 0; + text-align: left +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content { + float: none; + width: auto; + padding: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content::before { + display: none +} + +.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { + padding-top: .75rem; + margin-top: .75rem; + border-top: 1px solid rgba(0, 0, 0, .1) +} + +.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { + display: block; + padding: .1rem 1rem; + margin-bottom: 0.1; + font-size: 1.0em; + font-weight: 400 + /* display: none */ +} + +.algolia-autocomplete .algolia-docsearch-suggestion--title { + display: block; + padding: .25rem 1rem; + margin-bottom: 0; + font-size: 0.9em; + font-weight: 400 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--text { + padding: 0 1rem .5rem; + margin-top: -.25rem; + font-size: 0.8em; + font-weight: 400; + line-height: 1.25 +} + +.algolia-autocomplete .algolia-docsearch-footer { + width: 110px; + height: 20px; + z-index: 3; + margin-top: 10.66667px; + float: right; + font-size: 0; + line-height: 0; +} + +.algolia-autocomplete .algolia-docsearch-footer--logo { + background-image: url("data:image/svg+xml;utf8,"); + background-repeat: no-repeat; + background-position: 50%; + background-size: 100%; + overflow: hidden; + text-indent: -9000px; + width: 100%; + height: 100%; + display: block; + transform: translate(-8px); +} + +.algolia-autocomplete .algolia-docsearch-suggestion--highlight { + color: #FF8C00; + background: rgba(232, 189, 54, 0.1) +} + + +.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { + box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) +} + +.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { + background-color: rgba(192, 192, 192, .15) +} diff --git a/docs/docsearch.js b/docs/docsearch.js new file mode 100644 index 0000000..b35504c --- /dev/null +++ b/docs/docsearch.js @@ -0,0 +1,85 @@ +$(function() { + + // register a handler to move the focus to the search bar + // upon pressing shift + "/" (i.e. "?") + $(document).on('keydown', function(e) { + if (e.shiftKey && e.keyCode == 191) { + e.preventDefault(); + $("#search-input").focus(); + } + }); + + $(document).ready(function() { + // do keyword highlighting + /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ + var mark = function() { + + var referrer = document.URL ; + var paramKey = "q" ; + + if (referrer.indexOf("?") !== -1) { + var qs = referrer.substr(referrer.indexOf('?') + 1); + var qs_noanchor = qs.split('#')[0]; + var qsa = qs_noanchor.split('&'); + var keyword = ""; + + for (var i = 0; i < qsa.length; i++) { + var currentParam = qsa[i].split('='); + + if (currentParam.length !== 2) { + continue; + } + + if (currentParam[0] == paramKey) { + keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); + } + } + + if (keyword !== "") { + $(".contents").unmark({ + done: function() { + $(".contents").mark(keyword); + } + }); + } + } + }; + + mark(); + }); +}); + +/* Search term highlighting ------------------------------*/ + +function matchedWords(hit) { + var words = []; + + var hierarchy = hit._highlightResult.hierarchy; + // loop to fetch from lvl0, lvl1, etc. + for (var idx in hierarchy) { + words = words.concat(hierarchy[idx].matchedWords); + } + + var content = hit._highlightResult.content; + if (content) { + words = words.concat(content.matchedWords); + } + + // return unique words + var words_uniq = [...new Set(words)]; + return words_uniq; +} + +function updateHitURL(hit) { + + var words = matchedWords(hit); + var url = ""; + + if (hit.anchor) { + url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; + } else { + url = hit.url + '?q=' + escape(words.join(" ")); + } + + return url; +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..4e459d1 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,207 @@ + + + + + + + +Risk Functions and Attributable Fractions for Tobacco and Alcohol • tobalcepi + + + + + + + + + + +
    +
    + + + + +
    +
    +
    + + +

    The package is usable but there are still bugs and further developments that are being worked through i.e. some code and documentation is still incomplete or in need of being refined. The code and documentation are still undergoing internal review by the analyst team.

    +
    +

    +Motivation

    +

    tobalcepi was created as part of a programme of work on the health economics of tobacco and alcohol at the School of Health and Related Research (ScHARR), The University of Sheffield. This programme is based around the construction of the Sheffield Tobacco and Alcohol Policy Model (STAPM), which aims to use comparable methodologies to evaluate the impacts of tobacco and alcohol policies, and investigate the consequences of clustering and interactions between tobacco and alcohol consumption behaviours.

    +

    The motivation for tobalcepi was to organise the information on the relative risks of diseases related to tobacco and alcohol consumption and to provide functions to easily work with these data in modelling. The suite of functions within tobalcepi processes the published data on disease risks that stem from chronic and acute alcohol consumption, from smoking, and on the decline in risk after ceasing or reducing consumption. The package also includes functions to estimate population attributable fractions, and to explore the interaction between the disease risks that stem from tobacco and alcohol consumption.

    +
    +

    The risk functions in this package are all collated from published sources, which we have referenced.

    +
    +
    +
    +

    +Usage

    +

    tobalcepi is a package for predicting individual risk of disease due to tobacco and alcohol consumption based on published sources, and summarising that risk.

    +

    The inputs are the published estimates of relative risk for each disease (sometimes stratified by population subgroup).

    +

    The processes applied by the functions in tobalcepi give options to estimate:

    +
      +
    1. The risk of injury or disease from acute alcohol consumption.
      +
    2. +
    3. The risk of chronic disease based on the current amount of alcohol consumed.
      +
    4. +
    5. The risk of chronic disease based on whether someone currently smokes, and how much they currently smoke.
      +
    6. +
    7. The combined risk of disease in someone who smokes and drinks.
      +
    8. +
    9. The change in risk of disease after someone ceases or reduces their consumption.
      +
    10. +
    11. The population attributable fractions of disease to tobacco and/or alcohol (given suitable data on tobacco and alcohol consumption).
    12. +
    +

    The outputs of these processes are datasets in which an individual’s tobacco and/or alcohol consumption has been matched to their relative risks of certain diseases, and aggregated datasets that summarise the risks of disease within certain population subgroups.

    +
    +
    +

    +Installation

    +

    We would like to ask that since the code and documentation is still under development and is complex, that you consult with the authors before you use it.

    +

    Please cite the latest version of the package using:
    +“Duncan Gillespie, Laura Webster, Maddy Henney, Colin Angus and Alan Brennan (2020). tobalcepi: Risk Functions and Attributable Fractions for Tobacco and Alcohol. R package version x.x.x. https://STAPM.github.io/tobalcepi/. DOI:”

    +
    +

    Since you will be downloading and installing a source package, you might need to set your system up for building R packages:

    +

    It is a good idea to update R and all of your packages.

    +

    Mac OS: A convenient way to get the tools needed for compilation is to install Xcode Command Line Tools. Note that this is much smaller than full Xcode. In a shell, enter xcode-select –install. For installing almost anything else, consider using Homebrew.

    +

    Windows: Install Rtools. This is not an R package! It is “a collection of resources for building packages for R under Microsoft Windows, or for building R itself”. Go to https://cran.r-project.org/bin/windows/Rtools/ and install as instructed.

    +
    +

    You can install the development version of hseclean from github with:

    +
    #install.packages("devtools")
    +devtools::install_github("STAPM/tobalcepi")
    +
    +

    If there is an error with install_github(), one possible work-around is

    +
      +
    1. Download the package “tarball” by copying this into your internet browser (making sure the numbers at the end indicate the latest version) https://github.com/STAPM/tobalcepi/tarball/1.0.0. When the window pops up, choose where to save the .tar.gz file.

    2. +
    3. Go to the Terminal window in R Studio (or a console window in Windows by searching for “cmd”) and install the package from the downloaded file by typing R CMD INSTALL file_path.tar.gz.

    4. +
    +
    +

    Then load the package, and some other packages that are useful. Note that the code within tobalcepi uses the data.table::data.table() syntax.

    +
    # Load the package
    +library(tobalcepi)
    +
    +# Other useful packages
    +library(dplyr) # for data manipulation and summary
    +library(magrittr) # for pipes
    +library(ggplot2) # for plotting
    +
    +
    +

    +Getting started

    +
    +
    +

    +Basic functionality

    +
    +
    +
    + + +
    + + + +
    + + + + + + diff --git a/docs/link.svg b/docs/link.svg new file mode 100644 index 0000000..88ad827 --- /dev/null +++ b/docs/link.svg @@ -0,0 +1,12 @@ + + + + + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 0000000..c01e592 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,367 @@ +/* Sticky footer */ + +/** + * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ + * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css + * + * .Site -> body > .container + * .Site-content -> body > .container .row + * .footer -> footer + * + * Key idea seems to be to ensure that .container and __all its parents__ + * have height set to 100% + * + */ + +html, body { + height: 100%; +} + +body { + position: relative; +} + +body > .container { + display: flex; + height: 100%; + flex-direction: column; +} + +body > .container .row { + flex: 1 0 auto; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; + flex-shrink: 0; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Fix bug in bootstrap (only seen in firefox) */ +summary { + display: list-item; +} + +/* Typographic tweaking ---------------------------------*/ + +.contents .page-header { + margin-top: calc(-60px + 1em); +} + +dd { + margin-left: 3em; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -40px; +} + +/* Navbar submenu --------------------------*/ + +.dropdown-submenu { + position: relative; +} + +.dropdown-submenu>.dropdown-menu { + top: 0; + left: 100%; + margin-top: -6px; + margin-left: -1px; + border-radius: 0 6px 6px 6px; +} + +.dropdown-submenu:hover>.dropdown-menu { + display: block; +} + +.dropdown-submenu>a:after { + display: block; + content: " "; + float: right; + width: 0; + height: 0; + border-color: transparent; + border-style: solid; + border-width: 5px 0 5px 5px; + border-left-color: #cccccc; + margin-top: 5px; + margin-right: -10px; +} + +.dropdown-submenu:hover>a:after { + border-left-color: #ffffff; +} + +.dropdown-submenu.pull-left { + float: none; +} + +.dropdown-submenu.pull-left>.dropdown-menu { + left: -100%; + margin-left: 10px; + border-radius: 6px 0 6px 6px; +} + +/* Sidebar --------------------------*/ + +#pkgdown-sidebar { + margin-top: 30px; + position: -webkit-sticky; + position: sticky; + top: 70px; +} + +#pkgdown-sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#pkgdown-sidebar h2:first-child { + margin-top: 0; +} + +#pkgdown-sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* bootstrap-toc tweaks ------------------------------------------------------*/ + +/* All levels of nav */ + +nav[data-toggle='toc'] .nav > li > a { + padding: 4px 20px 4px 6px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; +} + +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 5px; + color: inherit; + border-left: 1px solid #878787; +} + +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 5px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; + border-left: 2px solid #878787; +} + +/* Nav: second level (shown on .active) */ + +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} + +nav[data-toggle='toc'] .nav .nav > li > a { + padding-left: 16px; + font-size: 1.35rem; +} + +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 15px; +} + +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 15px; + font-weight: 500; + font-size: 1.35rem; +} + +/* orcid ------------------------------------------------------------------- */ + +.orcid { + font-size: 16px; + color: #A6CE39; + /* margins are required by official ORCID trademark and display guidelines */ + margin-left:4px; + margin-right:4px; + vertical-align: middle; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} + +.ref-index td {vertical-align: top;} +.ref-index .icon {width: 40px;} +.ref-index .alias {width: 40%;} +.ref-index-icons .alias {width: calc(40% - 40px);} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + color: #375f84; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + +/* Clipboard --------------------------*/ + +.hasCopyButton { + position: relative; +} + +.btn-copy-ex { + position: absolute; + right: 0; + top: 0; + visibility: hidden; +} + +.hasCopyButton:hover button.btn-copy-ex { + visibility: visible; +} + +/* headroom.js ------------------------ */ + +.headroom { + will-change: transform; + transition: transform 200ms linear; +} +.headroom--pinned { + transform: translateY(0%); +} +.headroom--unpinned { + transform: translateY(-100%); +} + +/* mark.js ----------------------------*/ + +mark { + background-color: rgba(255, 255, 51, 0.5); + border-bottom: 2px solid rgba(255, 153, 51, 0.3); + padding: 1px; +} + +/* vertical spacing after htmlwidgets */ +.html-widget { + margin-bottom: 10px; +} + +/* fontawesome ------------------------ */ + +.fab { + font-family: "Font Awesome 5 Brands" !important; +} + +/* don't display links in code chunks when printing */ +/* source: https://stackoverflow.com/a/10781533 */ +@media print { + code a:link:after, code a:visited:after { + content: ""; + } +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 0000000..7e7048f --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,108 @@ +/* http://gregfranko.com/blog/jquery-best-practices/ */ +(function($) { + $(function() { + + $('.navbar-fixed-top').headroom(); + + $('body').css('padding-top', $('.navbar').height() + 10); + $(window).resize(function(){ + $('body').css('padding-top', $('.navbar').height() + 10); + }); + + $('[data-toggle="tooltip"]').tooltip(); + + var cur_path = paths(location.pathname); + var links = $("#navbar ul li a"); + var max_length = -1; + var pos = -1; + for (var i = 0; i < links.length; i++) { + if (links[i].getAttribute("href") === "#") + continue; + // Ignore external links + if (links[i].host !== location.host) + continue; + + var nav_path = paths(links[i].pathname); + + var length = prefix_length(nav_path, cur_path); + if (length > max_length) { + max_length = length; + pos = i; + } + } + + // Add class to parent
  • , and enclosing
  • if in dropdown + if (pos >= 0) { + var menu_anchor = $(links[pos]); + menu_anchor.parent().addClass("active"); + menu_anchor.closest("li.dropdown").addClass("active"); + } + }); + + function paths(pathname) { + var pieces = pathname.split("/"); + pieces.shift(); // always starts with / + + var end = pieces[pieces.length - 1]; + if (end === "index.html" || end === "") + pieces.pop(); + return(pieces); + } + + // Returns -1 if not found + function prefix_length(needle, haystack) { + if (needle.length > haystack.length) + return(-1); + + // Special case for length-0 haystack, since for loop won't run + if (haystack.length === 0) { + return(needle.length === 0 ? 0 : -1); + } + + for (var i = 0; i < haystack.length; i++) { + if (needle[i] != haystack[i]) + return(i); + } + + return(haystack.length); + } + + /* Clipboard --------------------------*/ + + function changeTooltipMessage(element, msg) { + var tooltipOriginalTitle=element.getAttribute('data-original-title'); + element.setAttribute('data-original-title', msg); + $(element).tooltip('show'); + element.setAttribute('data-original-title', tooltipOriginalTitle); + } + + if(ClipboardJS.isSupported()) { + $(document).ready(function() { + var copyButton = ""; + + $(".examples, div.sourceCode").addClass("hasCopyButton"); + + // Insert copy buttons: + $(copyButton).prependTo(".hasCopyButton"); + + // Initialize tooltips: + $('.btn-copy-ex').tooltip({container: 'body'}); + + // Initialize clipboard: + var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { + text: function(trigger) { + return trigger.parentNode.textContent; + } + }); + + clipboardBtnCopies.on('success', function(e) { + changeTooltipMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }); + + clipboardBtnCopies.on('error', function() { + changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); + }); + }); + } +})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 0000000..c52fa73 --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,10 @@ +pandoc: 2.3.1 +pkgdown: 1.5.1 +pkgdown_sha: ~ +articles: + smoking-disease-risks: smoking-disease-risks.html +last_built: 2020-04-28T13:52Z +urls: + reference: https://github.com/STAPM/tobalcepi/reference + article: https://github.com/STAPM/tobalcepi/articles + diff --git a/docs/reference/AlcBinge.html b/docs/reference/AlcBinge.html new file mode 100644 index 0000000..b5787da --- /dev/null +++ b/docs/reference/AlcBinge.html @@ -0,0 +1,206 @@ + + + + + + + + +Calculate variables to inform alcohol binge model — AlcBinge • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Uses survey data and previously estimated coefficients to describe +the patterns of single occassion drinking.

    +
    + +
    AlcBinge(data)
    + +

    Arguments

    + + + + + + +
    data

    Data table of individual characteristics.

    + +

    Value

    + +

    Returns data plus the estimated variables.

    +

    Details

    + +

    This is based on a study by Hill-McManus 2014, +who analysed drinking occasions using data from detailed diaries in the National Diet and Nutrition Survey 2000/2001. +Using the results, it possible to model each individual's expected number of drinking occasions across the year, +the average amount they drunk on an occasion, the variability in the amount drunk among occasions, +and how these vary socio-demographically.

    + +

    Examples

    +
    +if (FALSE) { + +# Simulate individual data + +# Using the parameters for the Gamma distribution from Kehoe et al. 2012 +n <- 1e3 +grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) + +data <- data.table( + weekmean = grams_ethanol_day * 7 / 8, + peakday = grams_ethanol_day / 8, + age = rpois(n, 30), + sex = sample(x = c("Male", "Female"), size = n, replace = T), + income5cat = "1_lowest income", + imd_quintile = "5_most_deprived", + kids = "0", + social_grade = "C2DE", + eduend4cat = "16-18", # age finished education + ethnic2cat = "white", # white / non-white + employ2cat = "yes", # employed / not + wtval = rnorm(n, mean = 60, sd = 5), # weight in kg + htval = rnorm(n, mean = 1.7, sd = .1) # height in m +) + +test_data <- AlcBinge(data) +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/AlcLags.html b/docs/reference/AlcLags.html new file mode 100644 index 0000000..3db6eaa --- /dev/null +++ b/docs/reference/AlcLags.html @@ -0,0 +1,188 @@ + + + + + + + + +Alcohol lag times — AlcLags • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Prepare the disease specific functions that describe how a change in alcohol consumption +gradually has an effect on the relative risk of disease incidence over time (up to 20 years) +since alcohol consumption changed.

    +
    + +
    AlcLags(disease_name = c("Pharynx", "Oral_cavity"), n_years = 20)
    + +

    Arguments

    + + + + + + + + + + +
    disease_name

    Character - the name of the disease under consideration.

    n_years

    Integer - the number of years from 1 to n over which the effect of a change in +consumption emerges. Defaults to 20 years to fit with the current lag data.

    + +

    Value

    + +

    Returns a data table with two columns - one for the years since consumption changed, and the other +that gives the proportion by which the effect of a change in consumption +on an individual's relative risk of disease has so far emerged.

    +

    Details

    + +

    All lag times are taken from the review by Holmes et al. 2012, + and are the numbers used in the current version of SAPM.

    + +

    Examples

    +
    if (FALSE) { +AlcLags("Pharynx") +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/ExpandCodes.html b/docs/reference/ExpandCodes.html new file mode 100644 index 0000000..66a84ba --- /dev/null +++ b/docs/reference/ExpandCodes.html @@ -0,0 +1,181 @@ + + + + + + + + +Convert groups of ICD-10 codes to single codes — ExpandCodes • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Creates the lookup files for search for single ICD-10 codes related to tobacco and/or alcohol.

    +
    + +
    ExpandCodes(lkup)
    + +

    Arguments

    + + + + + + +
    lkup

    Data frame containing the disease list.

    + +

    Value

    + +

    Returns a data frame containing a row for each single ICD-10 code to be searched for.

    +

    Details

    + +

    For example, if one disease category is C00-C06 (oral cancer), this includes the single codes +C00,C01,C02,C03,C04,C05,C06. The number of rows will be expanded to give each single code +its own row.

    + +

    Examples

    +
    +if (FALSE) { + +ExpandCodes(lkup) + +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/PArisk.html b/docs/reference/PArisk.html new file mode 100644 index 0000000..6eabfec --- /dev/null +++ b/docs/reference/PArisk.html @@ -0,0 +1,323 @@ + + + + + + + + +Relative risks for alcohol-related injuries — PArisk • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Uses the 'new' binge model methods to calculate a relative risk +for each individual for experiencing each cause during one year.

    +
    + +
    PArisk(
    +  SODMean,
    +  SODSDV,
    +  SODFreq,
    +  Weight,
    +  Widmark_r,
    +  cause = "Transport",
    +  grams_ethanol_per_unit = 8,
    +  grams_ethanol_per_std_drink = 12.8,
    +  liver_clearance_rate_h = 0.017
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    SODMean

    Numeric vector - the average amount that each individual is expected to +drink on a single drinking occassion.

    SODSDV

    Numeric vector - the standard deviation of the amount that each individual is expected to +drink on a single drinking occassion.

    SODFreq

    Numeric vector - the expected number of drinking occassions that +each individual has each week.

    Weight

    Numeric vector - each individual's body weight in kg.

    Widmark_r

    Numeric vector - the fraction of the body mass in which alcohol would be present +if it were distributed at concentrations equal to that in blood. +See examples of use of the Widmark equation in Watson (1981) and Posey and Mozayani (2007).

    cause

    Charcter - the acute cause being considered.

    grams_ethanol_per_unit

    Numeric value giving the conversion factor for the number of grams of pure +ethanol in one UK standard unit of alcohol.

    grams_ethanol_per_std_drink

    Numeric value giving the conversion factor for +the number of grams of ethanol in one standard drink.

    liver_clearance_rate_h

    The rate at which blood alcohol concentration declines (percent / hour).

    + +

    Value

    + +

    Returns a numeric vector of each individual's relative risk of the acute consequences of drinking.

    +

    Details

    + +

    This calculation treats an ocassion as a single point in time and therefore does not detail +about the rate of alcohol absorbtion (i.e. there is no alcohol absorbtion rate constant) +or the time interval between drinks within an occassion. This could introduce inaccuracies if + e.g. a drinking occassion lasted several hours. The methods to calculate the total time spent intoxicated + (with blood alcohol content greater than zero) are discussed in Taylor et al 2011 + and the discussion paper by Hill-McManus 2014. The relative risks for alcohol-related injuries + are taken from Cherpitel et al 2015.

    + +

    Examples

    +
    +if (FALSE) { +# For a male with the following characteristics: +Weight <- 70 # weight in kg +Height <- 2 # height in m +Age <- 25 # age in years + +# We can estimate their r value from the Widmark equation +# using parameter values from Posey and Mozayani (2007) +Widmark_r <- 0.39834 + ((12.725 * Height - 0.11275 * Age + 2.8993) / Weight) + +# They might drink from 1 to 100 grams of ethanol on one occassion +grams_ethanol <- 1:100 + +# In minutes, We would expect them to remain intoxicated +# (with blood alcohol content > 0 percent) for +Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * (liver_clearance_rate_h / 60)) + +# and hours +Duration_h <- Duration_m / 60 + +# Duration is the length of time taken to clear all alcohol from the blood +# so we don't apply any thresholds of intoxication, +# we just calculate the expected length of time with a bac greater than 0. + +# Now suppose that on average our example male has 5 drinking occasions per week, and that +# on average they drink 3 units of alcohol on an occasion, +# and that the standard deviation of amount drunk on an occasion is 14 units. + +# The cumulative probability distribution of each amount of alcohol being drunk on an occassion is +x <- pnorm(grams_ethanol, 2 * 8, 14 * 8) + +# Convert from the cumulative distribution to the +# probability that each level of alcohol is consumed on a drinking occasion +interval_prob <- x - c(0, x[1:(length(x) - 1)]) + +# The probability-weighted distribution of time spent intoxicated during a year (52 weeks) is +Time_intox <- 5 * 52 * interval_prob * Duration_h + +# And the expected total time spent intoxicated is +Time_intox_sum <- sum(Time_intox) + +# The relative risk of a transport injury corresponding to each amount drunk on a single occasion +# corresponds to the number of standard drinks consumed + +# We convert to standard drinking and apply the risk parameters from Cherpitel + +v <- grams_ethanol / 12.8 +v1 <- (v + 1) / 100 + +# Parameters from Cherpitel +b1 <- 3.973538882 +b2 <- 6.65184e-6 +b3 <- 0.837637 +b4 <- 1.018824 + +# Apply formula for the risk curve from Cherpital +lvold_1 <- log(v1) + b1 +lvold_2 <- (v1^3) - b2 +logitp <- lvold_1 * b3 + lvold_2 * b4 +p <- boot::inv.logit(logitp) + +# The relative risk associated with each amount drunk on an occasion +rr <- p / p[1] + +# The relative risk multiplied by the time exposed to that level of risk +Current_risk <- rr * Time_intox + +# The sum of the relative risk associated with the time spent intoxicated during one year +Risk_sum <- sum(Current_risk) + +# The average annual relative risk, considering that time in the year spent with a +# blood alcohol content of zero has a relative risk of 1. +Annual_risk <- min( + (Risk_sum + 1 * (365 * 24 - Time_intox_sum)) / (365 * 24), + 365 * 24, na.rm = T) + + + +# THE FOLLOWING ARE NOT CONSIDERED IN THIS CALCULATION + +# Elapsed time in minutes since consuming alcohol +t <- 30 + +# Alcohol absorbtion rate constant +k_empty_stomach <- 6.5 / 60 # grams of ethanol per minute + +# Alcohol absorbtion +alcohol_absorbed <- grams_ethanol * (1 - exp(-k_empty_stomach * t)) + +# Calculate blood alcohol content using the Wildemark eqn +bac <- (100 * alcohol_absorbed / (Widmark_r * Weight * 1000)) - ((liver_clearance_rate_h / 60) * t) +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/RRFunc.html b/docs/reference/RRFunc.html new file mode 100644 index 0000000..7224ec4 --- /dev/null +++ b/docs/reference/RRFunc.html @@ -0,0 +1,408 @@ + + + + + + + + +Individual relative risks of disease — RRFunc • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    This function takes a sample of individuals and computes each individual's relative risk +for each disease according to their current tobacco and alcohol consumption. There is an option to tailor this +to the alcohol only, tobacco only, or joint tobacco and alcohol contexts.

    +
    + +
    RRFunc(
    +  data,
    +  substance = c("tob", "alc", "tobalc"),
    +  k_year = NULL,
    +  alc_diseases = c("Pharynx", "Oral_cavity"),
    +  alc_mort_and_morb = c("Ischaemic_heart_disease", "LiverCirrhosis"),
    +  alc_risk_lags = TRUE,
    +  alc_indiv_risk_trajectories_store = NULL,
    +  alc_protective = TRUE,
    +  alc_wholly_chronic_thresholds = c(6, 8),
    +  alc_wholly_acute_thresholds = c(6, 8),
    +  grams_ethanol_per_unit = 8,
    +  tob_diseases = c("Pharynx", "Oral_cavity"),
    +  tob_include_risk_in_former_smokers = TRUE,
    +  tobalc_include_int = FALSE,
    +  tobalc_int_data = NULL,
    +  show_progress = FALSE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    Data table of individual characteristics - this function uses current smoking and drinking status/amount.

    substance

    Whether to compute relative risks for just alcohol ("alc"), +just tobacco ("tob") or joint risks for tobacco and alcohol ("tobalc").

    k_year

    Integer giving the current year of the simulation.

    alc_diseases

    Character vector of alcohol related diseases.

    alc_mort_and_morb

    Character vector of alcohol related diseases that have separate risk functions for +mortality and morbidity.

    alc_risk_lags

    Logical - should each individual's relative risks for alcohol be lagged according to +their past trajectory of relative risks. Defaults to FALSE. This should only be set to TRUE for a model run that simulates individual trajctories, +and should be FALSE if used as part of the current method for calculating attributable fractions.

    alc_indiv_risk_trajectories_store

    Data table that stores the individual history of relative risks for alcohol related diseases.

    alc_protective

    Logical - whether to include the protective effects of +alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1.

    alc_wholly_chronic_thresholds

    Numeric vector - the thresholds in units/week over +which individuals begin to experience an elevated risk +for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female).

    alc_wholly_acute_thresholds

    Numeric vector - the thresholds in units/day over +which individuals begin to experience an elevated risk +for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female).

    grams_ethanol_per_unit

    Numeric value giving the conversion factor for the number of grams of pure +ethanol in one UK standard unit of alcohol.

    tob_diseases

    Character vector of tobacco related diseases.

    tob_include_risk_in_former_smokers

    Logical - whether the residual risks of smoking in former smokers +should be considered (defaults to TRUE).

    tobalc_include_int

    Logical - in computing joint relative risks for tobacco and alcohol, +should a (synergystic/multiplicative) interaction between exposure to tobacco and alcohol be included. +Defaults to FALSE. If TRUE, then only interactive effects for oesophageal, pharynx, oral cavity and larynx cancers +are considered.

    tobalc_int_data

    Data table containing the disease-specific interactions between tobacco and alcohol.

    show_progress

    Logical - Should the progress of the loop through diseases be shown. Defaults to FALSE.

    + +

    Value

    + +

    Two data tables are returned:

      +
    • "data_plus_rr" is a copy of "data" with added columns that give each +individual's relative risk for each disease.

    • +
    • "new_alc_indiv_risk_trajectories_store" is a copy of "alc_indiv_risk_trajectories_store" with +the relative risks for the current year added to the store.

    • +
    + +

    Details

    + +

    ALCOHOL

    +

    For alcohol, the relative risk for each individual for each disease is calculated based on their average weekly alcohol consumption. + For diseases that have separate mortality and morbidity risk functions, separate variables are created containing + the relative risks for each for the same disease. +Individuals are not recorded as being former drinkers -- instead their alcohol consumption just falls to zero and their +relative risk for disease changes accordingly.

    +

    Alcohol lags:

    +

    To account for the lagged effects of individual drinking history on their +current risk of disease, we add memory by storing each individual's past trajectory of their relative risk for each disease. +In the model, the current relative risk is then adjusted to take account of each individual's stored drinking histories - +this adjustment takes the form of a weighted average of current and past relative risk where the weights are proportional to +the disease specific lag function that describes the gradual emergence of an effect of changed consumption on risk over time. +This uses a slightly different method to SAPM.

    +

    TOBACCO

    +

    For tobacco, the relative risk for each individual is calculated based on whether they are a current, former or never smoker. +Currently, all current smokers have the same relative risk regardless of the amount they currently smoke or have smoked in the past.

    +

    Tobacco lags:

    +

    Former smokers are initially given the relative risk associated with current smokers, which we then scale according to a disease-specific +function that describes how risk declines after quitting smoking.

    +

    ALCOHOL AND TOBACCO

    +

    If both tobacco and alcohol are being considered in a joint model, +we combine the relative risks for current drinkers and smokers. For oral, pharyngeal, laryngeal and oesophageal cancers we also +have the option of scaling the joint risks by a 'synergy index', which takes the result of a meta-analysis of the additional +risk faced by people because they consume both tobacco and alcohol.

    + +

    Examples

    +
    if (FALSE) { +############################# +## ALCOHOL + +# Simulate individual data + +# Using the parameters for the Gamma distribution from Kehoe et al. 2012 +n <- 1e4 +grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) + +# Note: the socioeconomic and other variables are needed for the binge model + +data <- data.table( + year = 2016, + weekmean = grams_ethanol_day * 7 / 8, + peakday = 2 * grams_ethanol_day / 8, + age = rpois(n, 30), + sex = sample(x = c("Male", "Female"), size = n, replace = T), + income5cat = "1_lowest income", + imd_quintile = "5_most_deprived", + kids = "0", + social_grade = "C2DE", + eduend4cat = "16-18", # age finished education + ethnic2cat = "white", # white / non-white + employ2cat = "yes", # employed / not + wtval = rnorm(n, mean = 60, sd = 5), # weight in kg + htval = rnorm(n, mean = 1.7, sd = .1) # height in m +) + +# Add individual ids to the data +data <- MakeSeeds(data, n = 0) + +# Disease names +alc_disease_names <- c( + "Pharynx", + "Ischaemic_heart_disease", + "LiverCirrhosis", + "Transport_injuries", + "Alcohol_poisoning", + "Alcoholic_gastritis" +) + +test_data <- copy(data) + +test_data1 <- RRFunc( + data = test_data, + substance = "alc", + k_year = 2017, + alc_diseases = alc_disease_names, + alc_indiv_risk_trajectories_store = NULL, + alc_wholly_chronic_thresholds = c(2, 2), + alc_wholly_acute_thresholds = c(3, 3), + show_progress = TRUE +) + +test_data1 + +test_data <- copy(data) +test_data[ , year := 2017] + +test_data2 <- RRFunc( + data = test_data, + substance = "alc", + k_year = 2018, + alc_diseases = alc_disease_names, + alc_indiv_risk_trajectories_store = test_data1$new_alc_indiv_risk_trajectories_store, + alc_wholly_chronic_thresholds = c(2, 2), + alc_wholly_acute_thresholds = c(3, 3), + show_progress = TRUE +) + +test_data2 + + +############################# +## TOBACCO + +tob_disease_names <- c( + "Pharynx", + "Chronic_obstructive_pulmonary_disease", + "Ischaemic_heart_disease", + "Lung", + "Influenza_clinically_diagnosed", + "Diabetes", + "Schizophrenia" +) + +n <- 1e4 + +data <- data.table( + smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), + time_since_quit = sample(x = 0:40, size = n, replace = T), + age = rpois(n, 30), + sex = sample(x = c("Male", "Female"), size = n, replace = T) +) + +data[smk.state != "former", time_since_quit := NA] + +# Tobacco relative risks for Pharygeal cancer +RRFunc( + data = data, + substance = "tob", + tob_diseases = tob_disease_names, + show_progress = TRUE +) + + +############################# +## TOBACCO AND ALCOHOL + +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/RRTobDR.html b/docs/reference/RRTobDR.html new file mode 100644 index 0000000..63b5743 --- /dev/null +++ b/docs/reference/RRTobDR.html @@ -0,0 +1,195 @@ + + + + + + + + +Dose-response relative risks for tobacco-related cancers — RRTobDR • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Computes the relative risks for each tobacco-related cancer based on the published risk curves.

    +
    + +
    RRTobDR(data, disease = "Pharynx", av_cigs_day = "cigs_per_day")
    + +

    Arguments

    + + + + + + + + + + + + + + +
    data

    Data table of individual characteristics.

    disease

    Character - the name of the disease for which the relative risks will be computed.

    av_cigs_day

    Character - the name of the variable containing each individual's +average number of daily cigarettes.

    + +

    Value

    + +

    Returns a numeric vector of each individual's relative risks for the tobacco related disease specified by "disease".

    +

    Details

    + +

    Relative risks for come from published risk functions whose parameters have been +hard-coded within this function rather than being read from an external spreadsheet. +These relative risks are based on an individual's current smoking intensity. There are +others measures of smoking exposure including smoking duration and pack-years, which +we will come to think about further.

    + +

    Examples

    +
    +if (FALSE) { + +RRTobDR(data = data, + disease = "Pharynx", + av_cigs_day = "cigs_per_day" + ) + +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/RRalc.html b/docs/reference/RRalc.html new file mode 100644 index 0000000..8b202a5 --- /dev/null +++ b/docs/reference/RRalc.html @@ -0,0 +1,282 @@ + + + + + + + + +Relative risks for alcohol related diseases — RRalc • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Computes the relative risks for each alcohol related disease based on the published risk curves.

    +
    + +
    RRalc(
    +  data,
    +  disease = "Pharynx",
    +  av_weekly_grams_per_day_var = "GPerDay",
    +  peak_grams_per_day_var = "peakday_grams",
    +  sex_var = "sex",
    +  age_var = "age",
    +  mort_or_morb = c("mort", "morb"),
    +  protective = TRUE,
    +  alc_wholly_chronic_thresholds = c(6, 8),
    +  alc_wholly_acute_thresholds = c(6, 8),
    +  grams_ethanol_per_unit = 8
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    Data table of individual characteristics.

    disease

    Character - the name of the disease for which the relative risks will be computed.

    av_weekly_grams_per_day_var

    Character - the name of the variable containing each individual's +average weekly consumption of alcohol in grams of ethanol per day.

    peak_grams_per_day_var

    Character - the name of the variable containing the amount of alcohol +that each individual consumed on their heaviest drinking day of the week.

    sex_var

    Character - the name of the variable containing individual sex.

    age_var

    Character - the name of the variable containing individual age in single years.

    mort_or_morb

    Character - for alcohol related diseases that have separate +relative risk curves for mortality and morbidity, should the curve corresponding to + mortality ("mort") or morbidity ("morb") be used.

    protective

    Logical - whether to include the protective effects of +alcohol in the risk function. Defaults to TRUE. If TRUE, then the part of the risk function < 1 is set to equal 1.

    alc_wholly_chronic_thresholds

    Numeric vector - the thresholds in grams of ethanol /week over +which individuals begin to experience an elevated risk +for chronic diseases that are wholly attributable to alcohol. Input in the form c(male, female).

    alc_wholly_acute_thresholds

    Numeric vector - the thresholds in grams of ethanol /day over +which individuals begin to experience an elevated risk +for acute diseases that are wholly attributable to alcohol. Input in the form c(male, female).

    grams_ethanol_per_unit

    Numeric value giving the conversion factor for the number of grams of pure +ethanol in one UK standard unit of alcohol.

    + +

    Value

    + +

    Returns a numeric vector of each individual's relative risks for the alcohol related disease specified by "disease".

    +

    Details

    + +

    Relative risks for partially attributable chronic come from published risk functions whose parameters have been +hard-coded within this function rather than being read from an external spreadsheet. For some conditions there are +separate risk functions for morbidity and mortality. For conditions that show a J-shaped risk function that +indicates protective effects of alcohol, there is an option to remove the protective effect by setting all +RR < 1 = 1. Relative risks for partially attributable acute are computed by the PArisk function called from within + this function. Relative risks for wholly attributable chronic and wholly attributable acute conditions are calculated + based on the extent to which either weekly or daily consumption exceeds a pre-specified threshold.

    + +

    Examples

    +
    +if (FALSE) { + +# Draw disease specific risk functions + +# Example data +data <- data.table( + GPerDay = 0:100, + peakday_grams = 0:100, + sex = "Female", + age = 30 +) + +# Apply the function +test1 <- RRalc( + data, + disease = "Pharynx", + mort_or_morb = "mort" +) + +test2 <- RRalc( + data, + disease = "Ischaemic_heart_disease", + mort_or_morb = "morb" +) + +test3 <- RRalc( + data, + disease = "LiverCirrhosis", + mort_or_morb = "mort" +) + +# Plot the risk functions +plot(test1 ~ I(0:100), type = "l", ylim = c(0, 10), ylab = "rr", +main = "Females, age 30", xlab = "g per day") +lines(test2 ~ I(0:100), col = 2) +lines(test3 ~ I(0:100), col = 3) +legend("topleft", +c("Pharyngeal cancer", "Ischaemic heart disease morbidity", "Liver Cirrhosis mortality"), +lty = 1, col = 1:3) +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/RRtob.html b/docs/reference/RRtob.html new file mode 100644 index 0000000..0842b8e --- /dev/null +++ b/docs/reference/RRtob.html @@ -0,0 +1,239 @@ + + + + + + + + +Tobacco relative risks — RRtob • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Relative risks for current vs. never cigarette smokers.

    +
    + +
    RRtob(
    +  data,
    +  disease = "Pharynx",
    +  smoker_status_var = "smk.state",
    +  sex_var = "sex",
    +  age_var = "age",
    +  rr_data = tobalcepi::tobacco_relative_risks
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    Data table of individual characteristics.

    disease

    Character - the name of the disease for which the relative risks will be computed.

    smoker_status_var

    Character - the name of the variable containing whether an individual is +a current, former or never smoker.

    sex_var

    Character - the name of the variable containing individual sex.

    age_var

    Character - the name of the variable containing individual age in single years.

    rr_data

    Data table containing the relative risks of current vs. never smokers. +The data table "tobacco_relative_risks" is embedded within the stapmr package.

    + +

    Value

    + +

    Returns a numeric vector of each individual's relative risks for the tobacco-related disease +specified by "disease".

    +

    Details

    + +

    We focus on the risks of current smoking and limit ourselves to diseases that affect the consumer themselves e.g. + excluding secondary effects of smoking on children. + We assume the equivalence of relative risks and odds ratios. + Our starting point was the Royal College of Physician's (RCP) report "Hiding in plain sight: + Treating tobacco dependency in the NHS", + which reviewed smoking-disease associations to produce an updated list of diseases that are caused + by smoking and updated risk sources. + We mainly keep to the RCP report's disease list and risk functions, with any deviations from the RCP list + and risk sources being for one of two reasons:

      +
    • There are often slightly conflicting ICD-10 code definitions used for some diseases and + we have sought to harmonise these consistently across both tobacco and alcohol, + based on the Sheffield Alcohol Policy Model (SAPM) v4.0 disease list;

    • +
    • Since publication of the RCP report, Cancer Research UK (CRUK) produced their own disease + list and risk sources for cancers attributable to modifiable risk factors, + including tobacco and alcohol. + Discussions with CRUK shaped the disease definitions in our updated Sheffield disease list for alcohol. + Where there are differences in the risk sources used in the RCP report and CRUK's work, + we take the estimate that matches most closely to our disease definitions, or the more recent estimate.

    • +
    + + +

    Examples

    +
    if (FALSE) { +# Example data + +n <- 1e2 + +data <- data.table( + smk.state = sample(x = c("current", "former", "never"), size = n, replace = T), + sex = "Female", + age = 30 +) + +# Apply the function +test <- RRtob( + data, + disease = "Pharynx" +) +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/TobAlcInt.html b/docs/reference/TobAlcInt.html new file mode 100644 index 0000000..c7c76f2 --- /dev/null +++ b/docs/reference/TobAlcInt.html @@ -0,0 +1,206 @@ + + + + + + + + +Risk interaction between tobacco and alcohol — TobAlcInt • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Assigns the disease-specific interaction term (synergy index) appropriate to each +individual's tobacco and alcohol consumption.

    +
    + +
    TobAlcInt(
    +  data,
    +  disease = "Pharynx",
    +  alcohol_var = "weekmean",
    +  tobacco_var = "smk.state",
    +  rr.data,
    +  account_for_synergy = TRUE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    Data table

    disease

    Character

    alcohol_var

    Character

    tobacco_var

    Character

    rr.data

    Data table

    account_for_synergy

    Logical

    + +

    Value

    + +

    Returns a numeric vector containing of each individual's relative risks for the tobacco-related disease +specified by "disease".

    + +

    Examples

    +
    +if (FALSE) { + +TobAlcInt() + +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/TobLags.html b/docs/reference/TobLags.html new file mode 100644 index 0000000..3fdd35d --- /dev/null +++ b/docs/reference/TobLags.html @@ -0,0 +1,255 @@ + + + + + + + + +Tobacco lag times — TobLags • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Prepare the disease specific functions that describe how a change in tobacco consumption +gradually has an effect on the relative risk of disease incidence over time (up to 40 years) +since e.g. someone quit smoking

    +
    + +
    TobLags(
    +  disease_name = c("Pharynx", "Oral_cavity"),
    +  n_years = 40,
    +  lag_data = tobalcepi::tobacco_lag_times
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + +
    disease_name

    Character - the name of the disease under consideration.

    n_years

    Integer - the number of years from 1 to n over which the effect of a change in +consumption emerges. Defaults to 20 years to fit with the current lag data.

    lag_data

    Data table containing the numerical description of the lag function. +The data table "tobacco lag times" is embedded within the stapmr package.

    + +

    Value

    + +

    Returns a data table with two columns - one for the years since consumption changed, and the other +that gives the proportion by which the effect of a change in consumption +on an individual's relative risk of disease has so far emerged.

    +

    Details

    + +

    All lag times are taken from a re-analysis of the Cancer prevention II study by Oza et al 2011 and Kontis et al 2014 +The values were sent to us by Kontis. Lags are smoothed functions over time describing the proportion of +the excess risk due to smoking that still remains.

    +

    Kontis et al. re-analysed the change in risk after smoking in the ACS-CPS II study from Oza et al., +producing three functions to describe the decline in risk after quitting for each of cancers, CVD and COPD. +The estimates were informed by data on former smokers with known quit dates who were disease-free at baseline. +The results show the proportion of excess relative risk remaining at each time-point since cessation. +A cross-check showed that the figures for cancers were broadly consistent with the findings of the +International Agency for Research on Cancer's (IARC) +2007 review of the decline in risk after quitting smoking.

    +

    The remaining question is how risk declines after quitting smoking for diseases that are not cancers, +CVD or COPD. Kontis et al. state that +"Randomised trials also indicate that the benefits of behaviour change and pharmacological treatment +on diabetes risk occur within a few years, more similar to the CVDs than cancers. + Therefore, we used the CVD curve for diabetes." In-line with Kontis, we apply the rate of decline + in risk of CVD after quitting smoking to type 2 diabetes. + For other diseases, we assume that the relative risk reverts to 1 immediately after quitting + i.e. an immediate rather than a gradual decline in risk.

    + +

    Examples

    +
    +TobLags("Pharynx")
    #> time_since_quit prop_risk_reduction +#> 1: 0 0.00000000 +#> 2: 1 0.08876399 +#> 3: 2 0.16923763 +#> 4: 3 0.24226931 +#> 5: 4 0.30861345 +#> 6: 5 0.36894171 +#> 7: 6 0.42385267 +#> 8: 7 0.47388041 +#> 9: 8 0.51950194 +#> 10: 9 0.56114374 +#> 11: 10 0.59918751 +#> 12: 11 0.63397523 +#> 13: 12 0.66581360 +#> 14: 13 0.69497793 +#> 15: 14 0.72171559 +#> 16: 15 0.74624910 +#> 17: 16 0.76877877 +#> 18: 17 0.78948509 +#> 19: 18 0.80853085 +#> 20: 19 0.82606301 +#> 21: 20 0.84221434 +#> 22: 21 0.85710491 +#> 23: 22 0.87084340 +#> 24: 23 0.88352822 +#> 25: 24 0.89524863 +#> 26: 25 0.90608559 +#> 27: 26 0.91611261 +#> 28: 27 0.92539650 +#> 29: 28 0.93399802 +#> 30: 29 0.94197248 +#> 31: 30 0.94937023 +#> 32: 31 0.95623718 +#> 33: 32 0.96261520 +#> 34: 33 0.96854251 +#> 35: 34 0.97405401 +#> 36: 35 0.97918161 +#> 37: 36 0.98395447 +#> 38: 37 0.98839930 +#> 39: 38 0.99254055 +#> 40: 39 0.99640061 +#> 41: 40 1.00000000 +#> time_since_quit prop_risk_reduction
    +
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/alc_disease_names.html b/docs/reference/alc_disease_names.html new file mode 100644 index 0000000..e93eac5 --- /dev/null +++ b/docs/reference/alc_disease_names.html @@ -0,0 +1,166 @@ + + + + + + + + +Names of alcohol-related diseases — alc_disease_names • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Names of alcohol-related diseases

    +
    + +
    alc_disease_names
    + + +

    Format

    + +

    A data table

    +

    Source

    + + + + + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/disease_groups.html b/docs/reference/disease_groups.html new file mode 100644 index 0000000..b27c955 --- /dev/null +++ b/docs/reference/disease_groups.html @@ -0,0 +1,164 @@ + + + + + + + + +Groupings of smoking-related diseases into disease types — disease_groups • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Groupings of smoking-related diseases into disease types

    +
    + +
    disease_groups
    + + +

    Format

    + +

    A data table

    +

    Source

    + +

    Following the scheme used in the Royal College of Physicians report 'Hiding in Plain Signt' chapter 3.

    + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 0000000..198585c --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,273 @@ + + + + + + + + +Function reference • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    All functions

    +

    +
    +

    AlcBinge()

    +

    Calculate variables to inform alcohol binge model

    +

    AlcLags()

    +

    Alcohol lag times

    +

    ExpandCodes()

    +

    Convert groups of ICD-10 codes to single codes

    +

    PArisk()

    +

    Relative risks for alcohol-related injuries

    +

    RRFunc()

    +

    Individual relative risks of disease

    +

    RRTobDR()

    +

    Dose-response relative risks for tobacco-related cancers

    +

    RRalc()

    +

    Relative risks for alcohol related diseases

    +

    RRtob()

    +

    Tobacco relative risks

    +

    TobAlcInt()

    +

    Risk interaction between tobacco and alcohol

    +

    TobLags()

    +

    Tobacco lag times

    +

    alc_disease_names

    +

    Names of alcohol-related diseases

    +

    disease_groups

    +

    Groupings of smoking-related diseases into disease types

    +

    subgroupRisk()

    +

    Summarise relative risk

    +

    tob_alc_risk_int

    +

    Synergstic effects of tobacco and alcohol risks

    +

    tob_disease_names

    +

    Names of tobacco-related diseases

    +

    tobacco_lag_times

    +

    Tobacco lag times

    +

    tobacco_relative_risks

    +

    Tobacco relative risks

    +
    + + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/subgroupRisk.html b/docs/reference/subgroupRisk.html new file mode 100644 index 0000000..04f4cd5 --- /dev/null +++ b/docs/reference/subgroupRisk.html @@ -0,0 +1,269 @@ + + + + + + + + +Summarise relative risk — subgroupRisk • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Calculate the sum of the relative risk for all individuals in a subgroup, +or calculate the subgroup specific attributable fraction based on the current relative risks.

    +
    + +
    subgroupRisk(
    +  data,
    +  label = NULL,
    +  disease_names = c("Pharynx", "Oral_cavity"),
    +  af = FALSE,
    +  use_weights = FALSE,
    +  year_range = "all",
    +  pool = FALSE,
    +  subgroups = c("sex", "age_cat")
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    A data table of individual characteristics.

    label

    Character - a label to append to the outcome variable to help identify it in later calculations.

    disease_names

    Character vector - the names of the diseases for which summaries of relative risk are required.

    af

    Logical - if TRUE, then attributable fractions are calculated. If FALSE, then the total relative risk +is calculated. Defaults to FALSE.

    use_weights

    Logical - should the calculation account for survey weights. Defaults to FALSE. +Weight variable must be called "wt_int".

    year_range

    Either an integer vector of the years to be selected or "all". Defaults to "all".

    pool

    Logical - should the years selected be pooled. Defaults to FALSE.

    subgroups

    Character vector - the variable names of the subgroups used to stratify the estimates.

    + +

    Value

    + +

    Returns a data table containing the subgroup specific summaries for each disease.

    +

    Details

    + +

    Attributable fractions are calculated using the method as in Bellis & Jones 2014, which is also equivalent to the +method described in the Brennan et al. 2015 SAPM mathematical description paper.

    + +

    Examples

    +
    if (FALSE) { +# Simulate individual data + +# Using the parameters for the Gamma distribution from Kehoe et al. 2012 +n <- 1e4 +grams_ethanol_day <- rgamma(n, shape = 0.69, scale = 19.03) + +data <- data.table( + year = 2016, + weekmean = grams_ethanol_day * 7 / 8, + peakday = 2 * grams_ethanol_day / 8, + age = rpois(n, 30), + sex = sample(x = c("Male", "Female"), size = n, replace = T), + income5cat = "1_lowest income", + imd_quintile = "5_most_deprived", + kids = "0", + social_grade = "C2DE", + eduend4cat = "16-18", # age finished education + ethnic2cat = "white", # white / non-white + employ2cat = "yes", # employed / not + wtval = rnorm(n, mean = 60, sd = 5), # weight in kg + htval = rnorm(n, mean = 1.7, sd = .1) # height in m +) + +# Disease names +alc_disease_names <- c( + "Pharynx", + "Ischaemic_heart_disease", + "LiverCirrhosis", + "Transport_injuries", + "Alcohol_poisoning", + "Alcoholic_gastritis" +) + +# Run basic function without alcohol lags +test_data <- RRFunc( + data = copy(data), + substance = "alc", + alc_diseases = alc_disease_names, + alc_wholly_chronic_thresholds = c(2, 2), + alc_wholly_acute_thresholds = c(3, 3), + show_progress = TRUE +) + +# Calculate alcohol attributable fractions +test_aafs <- subgroupRisk( + data = test_data$data_plus_rr, + disease_names = alc_disease_names, + af = TRUE, + subgroups = "sex" +) + +test_aafs +}
    +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/tob_alc_risk_int.html b/docs/reference/tob_alc_risk_int.html new file mode 100644 index 0000000..3047d12 --- /dev/null +++ b/docs/reference/tob_alc_risk_int.html @@ -0,0 +1,166 @@ + + + + + + + + +Synergstic effects of tobacco and alcohol risks — tob_alc_risk_int • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Synergstic effects of tobacco and alcohol risks

    +
    + +
    tob_alc_risk_int
    + + +

    Format

    + +

    A data table

    +

    Source

    + + + + + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/tob_disease_names.html b/docs/reference/tob_disease_names.html new file mode 100644 index 0000000..6718a8c --- /dev/null +++ b/docs/reference/tob_disease_names.html @@ -0,0 +1,166 @@ + + + + + + + + +Names of tobacco-related diseases — tob_disease_names • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Names of tobacco-related diseases

    +
    + +
    tob_disease_names
    + + +

    Format

    + +

    A data table

    +

    Source

    + + + + + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/tobacco_lag_times.html b/docs/reference/tobacco_lag_times.html new file mode 100644 index 0000000..51be946 --- /dev/null +++ b/docs/reference/tobacco_lag_times.html @@ -0,0 +1,166 @@ + + + + + + + + +Tobacco lag times — tobacco_lag_times • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Tobacco lag times

    +
    + +
    tobacco_lag_times
    + + +

    Format

    + +

    A data table

    +

    Source

    + + + + + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/reference/tobacco_relative_risks.html b/docs/reference/tobacco_relative_risks.html new file mode 100644 index 0000000..bdeb7cd --- /dev/null +++ b/docs/reference/tobacco_relative_risks.html @@ -0,0 +1,166 @@ + + + + + + + + +Tobacco relative risks — tobacco_relative_risks • tobalcepi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Tobacco relative risks

    +
    + +
    tobacco_relative_risks
    + + +

    Format

    + +

    A data table

    +

    Source

    + + + + + +
    + +
    + + + +
    + + + + + + + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml new file mode 100644 index 0000000..01074e6 --- /dev/null +++ b/docs/sitemap.xml @@ -0,0 +1,60 @@ + + + + https://github.com/STAPM/tobalcepi/index.html + + + https://github.com/STAPM/tobalcepi/reference/AlcBinge.html + + + https://github.com/STAPM/tobalcepi/reference/AlcLags.html + + + https://github.com/STAPM/tobalcepi/reference/ExpandCodes.html + + + https://github.com/STAPM/tobalcepi/reference/PArisk.html + + + https://github.com/STAPM/tobalcepi/reference/RRFunc.html + + + https://github.com/STAPM/tobalcepi/reference/RRTobDR.html + + + https://github.com/STAPM/tobalcepi/reference/RRalc.html + + + https://github.com/STAPM/tobalcepi/reference/RRtob.html + + + https://github.com/STAPM/tobalcepi/reference/TobAlcInt.html + + + https://github.com/STAPM/tobalcepi/reference/TobLags.html + + + https://github.com/STAPM/tobalcepi/reference/alc_disease_names.html + + + https://github.com/STAPM/tobalcepi/reference/disease_groups.html + + + https://github.com/STAPM/tobalcepi/reference/subgroupRisk.html + + + https://github.com/STAPM/tobalcepi/reference/tob_alc_risk_int.html + + + https://github.com/STAPM/tobalcepi/reference/tob_disease_names.html + + + https://github.com/STAPM/tobalcepi/reference/tobacco_lag_times.html + + + https://github.com/STAPM/tobalcepi/reference/tobacco_relative_risks.html + + + https://github.com/STAPM/tobalcepi/articles/smoking-disease-risks.html + + diff --git a/docs/tools/.DS_Store b/docs/tools/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/docs/tools/.DS_Store differ diff --git a/docs/tools/tobalcepi_hex.png b/docs/tools/tobalcepi_hex.png new file mode 100755 index 0000000..186e33c Binary files /dev/null and b/docs/tools/tobalcepi_hex.png differ diff --git a/man/AlcBinge.Rd b/man/AlcBinge.Rd index 0c05562..47e4514 100644 --- a/man/AlcBinge.Rd +++ b/man/AlcBinge.Rd @@ -25,6 +25,8 @@ and how these vary socio-demographically. } \examples{ +\dontrun{ + # Simulate individual data # Using the parameters for the Gamma distribution from Kehoe et al. 2012 @@ -48,6 +50,6 @@ data <- data.table( ) test_data <- AlcBinge(data) - +} } diff --git a/man/AlcLags.Rd b/man/AlcLags.Rd index fc287fd..614a1e7 100644 --- a/man/AlcLags.Rd +++ b/man/AlcLags.Rd @@ -27,7 +27,7 @@ All lag times are taken from the review by Holmes et al. 2012, and are the numbers used in the current version of SAPM. } \examples{ - +\dontrun{ AlcLags("Pharynx") - +} } diff --git a/man/PArisk.Rd b/man/PArisk.Rd index 138fd68..e70e51e 100644 --- a/man/PArisk.Rd +++ b/man/PArisk.Rd @@ -4,9 +4,17 @@ \alias{PArisk} \title{Relative risks for alcohol-related injuries} \usage{ -PArisk(SODMean, SODSDV, SODFreq, Weight, Widmark_r, cause = "Transport", - grams_ethanol_per_unit = 8, grams_ethanol_per_std_drink = 12.8, - liver_clearance_rate_h = 0.017) +PArisk( + SODMean, + SODSDV, + SODFreq, + Weight, + Widmark_r, + cause = "Transport", + grams_ethanol_per_unit = 8, + grams_ethanol_per_std_drink = 12.8, + liver_clearance_rate_h = 0.017 +) } \arguments{ \item{SODMean}{Numeric vector - the average amount that each individual is expected to @@ -51,18 +59,22 @@ or the time interval between drinks within an occassion. This could introduce in are taken from Cherpitel et al 2015. } \examples{ + +\dontrun{ # For a male with the following characteristics: Weight <- 70 # weight in kg Height <- 2 # height in m Age <- 25 # age in years -# We can estimate their r value from the Widmark equation using parameter values from Posey and Mozayani (2007) +# We can estimate their r value from the Widmark equation +# using parameter values from Posey and Mozayani (2007) Widmark_r <- 0.39834 + ((12.725 * Height - 0.11275 * Age + 2.8993) / Weight) # They might drink from 1 to 100 grams of ethanol on one occassion grams_ethanol <- 1:100 -# In minutes, We would expect them to remain intoxicated (with blood alcohol content > 0 percent) for +# In minutes, We would expect them to remain intoxicated +# (with blood alcohol content > 0 percent) for Duration_m <- 100 * grams_ethanol / (Widmark_r * Weight * 1000 * (liver_clearance_rate_h / 60)) # and hours @@ -125,7 +137,6 @@ Annual_risk <- min( 365 * 24, na.rm = T) -\dontrun{ # THE FOLLOWING ARE NOT CONSIDERED IN THIS CALCULATION diff --git a/man/RRFunc.Rd b/man/RRFunc.Rd index 8a08787..7278122 100644 --- a/man/RRFunc.Rd +++ b/man/RRFunc.Rd @@ -4,16 +4,24 @@ \alias{RRFunc} \title{Individual relative risks of disease} \usage{ -RRFunc(data, substance = c("tob", "alc", "tobalc"), k_year = NULL, +RRFunc( + data, + substance = c("tob", "alc", "tobalc"), + k_year = NULL, alc_diseases = c("Pharynx", "Oral_cavity"), alc_mort_and_morb = c("Ischaemic_heart_disease", "LiverCirrhosis"), - alc_risk_lags = TRUE, alc_indiv_risk_trajectories_store = NULL, - alc_protective = TRUE, alc_wholly_chronic_thresholds = c(6, 8), - alc_wholly_acute_thresholds = c(6, 8), grams_ethanol_per_unit = 8, + alc_risk_lags = TRUE, + alc_indiv_risk_trajectories_store = NULL, + alc_protective = TRUE, + alc_wholly_chronic_thresholds = c(6, 8), + alc_wholly_acute_thresholds = c(6, 8), + grams_ethanol_per_unit = 8, tob_diseases = c("Pharynx", "Oral_cavity"), tob_include_risk_in_former_smokers = TRUE, - tobalc_include_int = FALSE, tobalc_int_data = NULL, - show_progress = FALSE) + tobalc_include_int = FALSE, + tobalc_int_data = NULL, + show_progress = FALSE +) } \arguments{ \item{data}{Data table of individual characteristics - this function uses current smoking and drinking status/amount.} @@ -112,7 +120,7 @@ have the option of scaling the joint risks by a 'synergy index', which takes the risk faced by people because they consume both tobacco and alcohol. } \examples{ - +\dontrun{ ############################# ## ALCOHOL @@ -222,5 +230,5 @@ RRFunc( ############################# ## TOBACCO AND ALCOHOL - +} } diff --git a/man/RRTobDR.Rd b/man/RRTobDR.Rd new file mode 100644 index 0000000..b89f45d --- /dev/null +++ b/man/RRTobDR.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/RRTobDR.R +\name{RRTobDR} +\alias{RRTobDR} +\title{Dose-response relative risks for tobacco-related cancers} +\usage{ +RRTobDR(data, disease = "Pharynx", av_cigs_day = "cigs_per_day") +} +\arguments{ +\item{data}{Data table of individual characteristics.} + +\item{disease}{Character - the name of the disease for which the relative risks will be computed.} + +\item{av_cigs_day}{Character - the name of the variable containing each individual's +average number of daily cigarettes.} +} +\value{ +Returns a numeric vector of each individual's relative risks for the tobacco related disease specified by "disease". +} +\description{ +Computes the relative risks for each tobacco-related cancer based on the published risk curves. +} +\details{ +Relative risks for come from published risk functions whose parameters have been +hard-coded within this function rather than being read from an external spreadsheet. +These relative risks are based on an individual's current smoking intensity. There are +others measures of smoking exposure including smoking duration and pack-years, which +we will come to think about further. +} +\examples{ + +\dontrun{ + +RRTobDR(data = data, + disease = "Pharynx", + av_cigs_day = "cigs_per_day" + ) + +} +} diff --git a/man/RRalc.Rd b/man/RRalc.Rd index 29e2b68..adf4f2a 100644 --- a/man/RRalc.Rd +++ b/man/RRalc.Rd @@ -4,12 +4,19 @@ \alias{RRalc} \title{Relative risks for alcohol related diseases} \usage{ -RRalc(data, disease = "Pharynx", +RRalc( + data, + disease = "Pharynx", av_weekly_grams_per_day_var = "GPerDay", - peak_grams_per_day_var = "peakday_grams", sex_var = "sex", - age_var = "age", mort_or_morb = c("mort", "morb"), - protective = TRUE, alc_wholly_chronic_thresholds = c(6, 8), - alc_wholly_acute_thresholds = c(6, 8), grams_ethanol_per_unit = 8) + peak_grams_per_day_var = "peakday_grams", + sex_var = "sex", + age_var = "age", + mort_or_morb = c("mort", "morb"), + protective = TRUE, + alc_wholly_chronic_thresholds = c(6, 8), + alc_wholly_acute_thresholds = c(6, 8), + grams_ethanol_per_unit = 8 +) } \arguments{ \item{data}{Data table of individual characteristics.} @@ -61,6 +68,8 @@ RR < 1 = 1. Relative risks for partially attributable acute are computed by the } \examples{ +\dontrun{ + # Draw disease specific risk functions # Example data @@ -91,9 +100,12 @@ test3 <- RRalc( ) # Plot the risk functions -plot(test1 ~ I(0:100), type = "l", ylim = c(0, 10), ylab = "rr", main = "Females, age 30", xlab = "g per day") +plot(test1 ~ I(0:100), type = "l", ylim = c(0, 10), ylab = "rr", +main = "Females, age 30", xlab = "g per day") lines(test2 ~ I(0:100), col = 2) lines(test3 ~ I(0:100), col = 3) -legend("topleft", c("Pharyngeal cancer", "Ischaemic heart disease morbidity", "Liver Cirrhosis mortality"), lty = 1, col = 1:3) - +legend("topleft", +c("Pharyngeal cancer", "Ischaemic heart disease morbidity", "Liver Cirrhosis mortality"), +lty = 1, col = 1:3) +} } diff --git a/man/RRtob.Rd b/man/RRtob.Rd index f9a0916..057eab2 100644 --- a/man/RRtob.Rd +++ b/man/RRtob.Rd @@ -4,9 +4,14 @@ \alias{RRtob} \title{Tobacco relative risks} \usage{ -RRtob(data, disease = "Pharynx", smoker_status_var = "smk.state", - sex_var = "sex", age_var = "age", - rr_data = tobalcepi::tobacco_relative_risks) +RRtob( + data, + disease = "Pharynx", + smoker_status_var = "smk.state", + sex_var = "sex", + age_var = "age", + rr_data = tobalcepi::tobacco_relative_risks +) } \arguments{ \item{data}{Data table of individual characteristics.} @@ -53,7 +58,7 @@ We focus on the risks of current smoking and limit ourselves to diseases that af } } \examples{ - +\dontrun{ # Example data n <- 1e2 @@ -69,5 +74,5 @@ test <- RRtob( data, disease = "Pharynx" ) - +} } diff --git a/man/TobAlcInt.Rd b/man/TobAlcInt.Rd index 8ce2cd6..c98f55f 100644 --- a/man/TobAlcInt.Rd +++ b/man/TobAlcInt.Rd @@ -4,8 +4,14 @@ \alias{TobAlcInt} \title{Risk interaction between tobacco and alcohol} \usage{ -TobAlcInt(data, disease = "Pharynx", alcohol_var = "weekmean", - tobacco_var = "smk.state", rr_data, account_for_synergy = TRUE) +TobAlcInt( + data, + disease = "Pharynx", + alcohol_var = "weekmean", + tobacco_var = "smk.state", + rr.data, + account_for_synergy = TRUE +) } \arguments{ \item{data}{Data table} @@ -16,7 +22,7 @@ TobAlcInt(data, disease = "Pharynx", alcohol_var = "weekmean", \item{tobacco_var}{Character} -\item{rr_data}{Data table} +\item{rr.data}{Data table} \item{account_for_synergy}{Logical} } @@ -28,3 +34,13 @@ specified by "disease". Assigns the disease-specific interaction term (synergy index) appropriate to each individual's tobacco and alcohol consumption. } +\examples{ + +\dontrun{ + +TobAlcInt() + +} + + +} diff --git a/man/TobLags.Rd b/man/TobLags.Rd index 0fdf3ac..09c80a8 100644 --- a/man/TobLags.Rd +++ b/man/TobLags.Rd @@ -4,8 +4,11 @@ \alias{TobLags} \title{Tobacco lag times} \usage{ -TobLags(disease_name = c("Pharynx", "Oral_cavity"), n_years = 40, - lag_data = tobalcepi::tobacco_lag_times) +TobLags( + disease_name = c("Pharynx", "Oral_cavity"), + n_years = 40, + lag_data = tobalcepi::tobacco_lag_times +) } \arguments{ \item{disease_name}{Character - the name of the disease under consideration.} diff --git a/man/alc_disease_names.Rd b/man/alc_disease_names.Rd new file mode 100644 index 0000000..bfe7625 --- /dev/null +++ b/man/alc_disease_names.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/alc_disease_names.R +\docType{data} +\name{alc_disease_names} +\alias{alc_disease_names} +\title{Names of alcohol-related diseases} +\format{ +A data table +} +\source{ + +} +\usage{ +alc_disease_names +} +\description{ +Names of alcohol-related diseases +} +\keyword{datasets} diff --git a/man/disease_groups.Rd b/man/disease_groups.Rd index 19e08a5..86e958b 100644 --- a/man/disease_groups.Rd +++ b/man/disease_groups.Rd @@ -4,7 +4,9 @@ \name{disease_groups} \alias{disease_groups} \title{Groupings of smoking-related diseases into disease types} -\format{A data table} +\format{ +A data table +} \source{ Following the scheme used in the Royal College of Physicians report 'Hiding in Plain Signt' chapter 3. } diff --git a/man/hse_data_smoking.Rd b/man/hse_data_smoking.Rd deleted file mode 100644 index 6c60281..0000000 --- a/man/hse_data_smoking.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/hse_data_smoking.R -\docType{data} -\name{hse_data_smoking} -\alias{hse_data_smoking} -\title{Health Survey for England data used for modelling smoking} -\format{A data table} -\source{ -see the processing code in the data-raw folder, which uses the hseclean R package -} -\usage{ -hse_data_smoking -} -\description{ -For years 2001-2016. -} -\keyword{datasets} diff --git a/man/subgroupRisk.Rd b/man/subgroupRisk.Rd index 09c0fd6..e273941 100644 --- a/man/subgroupRisk.Rd +++ b/man/subgroupRisk.Rd @@ -4,9 +4,16 @@ \alias{subgroupRisk} \title{Summarise relative risk} \usage{ -subgroupRisk(data, label = NULL, disease_names = c("Pharynx", - "Oral_cavity"), af = FALSE, use_weights = FALSE, - year_range = "all", pool = FALSE, subgroups = c("sex", "age_cat")) +subgroupRisk( + data, + label = NULL, + disease_names = c("Pharynx", "Oral_cavity"), + af = FALSE, + use_weights = FALSE, + year_range = "all", + pool = FALSE, + subgroups = c("sex", "age_cat") +) } \arguments{ \item{data}{A data table of individual characteristics.} @@ -39,7 +46,7 @@ Attributable fractions are calculated using the method as in Bellis & Jones 2014 method described in the Brennan et al. 2015 SAPM mathematical description paper. } \examples{ - +\dontrun{ # Simulate individual data # Using the parameters for the Gamma distribution from Kehoe et al. 2012 @@ -92,5 +99,5 @@ test_aafs <- subgroupRisk( ) test_aafs - +} } diff --git a/man/tob_alc_risk_int.Rd b/man/tob_alc_risk_int.Rd new file mode 100644 index 0000000..ff42b9b --- /dev/null +++ b/man/tob_alc_risk_int.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tob_alc_risk_int.R +\docType{data} +\name{tob_alc_risk_int} +\alias{tob_alc_risk_int} +\title{Synergstic effects of tobacco and alcohol risks} +\format{ +A data table +} +\source{ + +} +\usage{ +tob_alc_risk_int +} +\description{ +Synergstic effects of tobacco and alcohol risks +} +\keyword{datasets} diff --git a/man/tob_disease_names.Rd b/man/tob_disease_names.Rd new file mode 100644 index 0000000..bececf0 --- /dev/null +++ b/man/tob_disease_names.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tob_disease_names.R +\docType{data} +\name{tob_disease_names} +\alias{tob_disease_names} +\title{Names of tobacco-related diseases} +\format{ +A data table +} +\source{ + +} +\usage{ +tob_disease_names +} +\description{ +Names of tobacco-related diseases +} +\keyword{datasets} diff --git a/man/tobacco_lag_times.Rd b/man/tobacco_lag_times.Rd new file mode 100644 index 0000000..3ed39f8 --- /dev/null +++ b/man/tobacco_lag_times.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tobacco_lag_times.R +\docType{data} +\name{tobacco_lag_times} +\alias{tobacco_lag_times} +\title{Tobacco lag times} +\format{ +A data table +} +\source{ + +} +\usage{ +tobacco_lag_times +} +\description{ +Tobacco lag times +} +\keyword{datasets} diff --git a/man/tobacco_relative_risks.Rd b/man/tobacco_relative_risks.Rd new file mode 100644 index 0000000..f55b47b --- /dev/null +++ b/man/tobacco_relative_risks.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tobacco_relative_risks.R +\docType{data} +\name{tobacco_relative_risks} +\alias{tobacco_relative_risks} +\title{Tobacco relative risks} +\format{ +A data table +} +\source{ + +} +\usage{ +tobacco_relative_risks +} +\description{ +Tobacco relative risks +} +\keyword{datasets} diff --git a/tools/.DS_Store b/tools/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/tools/.DS_Store differ diff --git a/tools/tobalcepi_hex.png b/tools/tobalcepi_hex.png new file mode 100755 index 0000000..186e33c Binary files /dev/null and b/tools/tobalcepi_hex.png differ diff --git a/data-raw/Relative risks/disease_groups.csv b/vignettes/disease_groups.csv similarity index 100% rename from data-raw/Relative risks/disease_groups.csv rename to vignettes/disease_groups.csv diff --git a/vignettes/excess_risk_decline_from_KontisLancet.csv b/vignettes/excess_risk_decline_from_KontisLancet.csv old mode 100644 new mode 100755 diff --git a/vignettes/smoking-disease-risks.Rmd b/vignettes/smoking-disease-risks.Rmd index 146aa15..7357fbf 100644 --- a/vignettes/smoking-disease-risks.Rmd +++ b/vignettes/smoking-disease-risks.Rmd @@ -1,39 +1,36 @@ --- title: "Smoking and the risks of adult diseases" -author: "Duncan Gillespie, Laura Webster, Colin Angus, Alan Brennan" -date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Smoking disease risks} %\VignetteEngine{knitr::rmarkdown} - \usepackage[utf8]{inputenc} + %\VignetteEncoding{UTF-8} bibliography: disease-risks.bib -header-includes: - \usepackage{float} - \usepackage{amsmath} link-citations: yes citation_package: natbib biblio-style: vancouver urlcolor: blue --- - -```{r setup, include = FALSE, results = 'hide', warning = FALSE} +```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.pos = 'H' ) +``` -library(readxl) -library(data.table) +```{r setup, include = FALSE, results = 'hide', warning = FALSE, eval = T} +suppressPackageStartupMessages(library(dplyr)) +suppressPackageStartupMessages(library(magrittr)) +suppressPackageStartupMessages(library(data.table)) +suppressPackageStartupMessages(library(testthat)) suppressPackageStartupMessages(library(ggplot2)) -#library(cowplot) - -#knitr::opts_knit$set(root.dir = "/Volumes/Shared/ScHARR/PR_STAPM/Code/R_packages/tobalcepi") -#knitr::opts_knit$set(root.dir = "X:/ScHARR/PR_STAPM/Code/R_packages/tobalcepi") - +suppressPackageStartupMessages(library(tobalcepi)) +suppressPackageStartupMessages(library(readxl)) ``` +# Acknowledgements +We thank Professor John Britton and Dr Katrina Brown. This work was conducted as part of our development of the Sheffield Tobacco and Alcohol Policy Model as part of the UK Centre for Tobacco and Alcohol Studies (http://ukctas.net/). Funding for UKCTAS from the British Heart Foundation, Cancer Research UK, the Economic and Social Research Council, the Medical Research Council and the National Institute of Health Research, under the auspices of the UK Clinical Research Collaboration, is gratefully acknowledged. The funders had no role in study design, data collection and analysis, decision to publish or preparation of this work. # Summary In the Sheffield Tobacco Policy Model (STPM), we consider 52 adult diseases related to smoking and the corresponding relative risks of developing these diseases in current vs. never smokers, and in former smokers according to the time since they quit [@Webster2018]. For current smokers, we assume that the relative risks of disease are the same for all smokers regardless of the amount currently smoked and the length of time as a smoker. We limit ourselves to diseases that affect the consumer themselves e.g. excluding secondary effects of smoking. @@ -230,7 +227,7 @@ p2 # oesophageal -data_oesophageal <- read_xlsx("2015-09-06_Risk_changes_after_cessation.xlsx", sheet = "Oesophargeal_comparison") +data_oesophageal <- readxl::read_xlsx("2015-09-06_Risk_changes_after_cessation.xlsx", sheet = "Oesophargeal_comparison") setDT(data_oesophageal) @@ -278,26 +275,6 @@ This average risk is calculated by the function `subgroupRisk()`. The functon `U The `tobalcepi` package contains data on smoking from the Health Survey for England, 2001-2016 in `hse_data_smoking`. To illustrate, we take a subset of 10,000 individuals from these data, assign them their smoking attributable relative risks for laryngeal cancer, and calculate the average risk for males and females. -```{r example risk calc, eval = T, echo=T, warning=F, out.extra='', fig.width = 4, fig.height = 4, fig.cap = "Example calculation of average relative risks for a subgroup."} - -#install.packages("X:/ScHARR/PR_STAPM/Code/R_packages/tobalcepi_0.1.0.zip", repos = NULL) -library(tobalcepi) - -# Create sample -n <- nrow(hse_data_smoking) -data <- hse_data_smoking[sample(1:n, 1e4, replace = F, prob = wt_int)] - -# Assign relative risks for laryngeal cancer -data <- RRFunc(data, substance = "tob", tob_diseases = "Larynx") - -# Calculate the average risk for males and females -av_risk <- subgroupRisk(data, disease_names = "Larynx", pool = T, subgroups = "sex") - -# Plot the results -ggplot(av_risk) + geom_bar(aes(x = sex, y = av_risk_), stat = "identity") + - ggtitle("Laryngeal cancer") + theme_minimal() - -``` # Code developments To integrate dose-response risk functions into our modelling, we have started to develop a new function to replace `RRtob()`. The function `RRTobDR` estimates each individual in the data their dose-response relative risk based on the number of cigarettes they consume per day. This function has not yet been integrated into the function `RRFunc()`. @@ -305,8 +282,7 @@ To integrate dose-response risk functions into our modelling, we have started to In order to this this we need to work out if and how we assign risk to former smokers, as there is no cigs per day information for former smokers. -# Acknowledgements -We thank Professor John Britton and Dr Katrina Brown. This work was conducted as part of our development of the Sheffield Tobacco and Alcohol Policy Model as part of the UK Centre for Tobacco and Alcohol Studies (http://ukctas.net/). Funding for UKCTAS from the British Heart Foundation, Cancer Research UK, the Economic and Social Research Council, the Medical Research Council and the National Institute of Health Research, under the auspices of the UK Clinical Research Collaboration, is gratefully acknowledged. The funders had no role in study design, data collection and analysis, decision to publish or preparation of this work. + # References diff --git a/vignettes/tob_alc_interactions_180119.csv b/vignettes/tob_alc_interactions_180119.csv new file mode 100755 index 0000000..ef074a9 --- /dev/null +++ b/vignettes/tob_alc_interactions_180119.csv @@ -0,0 +1,5 @@ +Version,Disease,oddsratio_or_relrisk,alc1_tob0,alc1_tob0_lower95,alc1_tob0_upper95,alc0_tob1,alc0_tob1_lower95,alc0_tob1_upper95,alc1_tob1,alc1_tob1_lower95,alc1_tob1_upper95,Source +Current,Oral_cavity,OR,1.06,0.88,1.28,2.37,1.66,3.39,5.73,3.62,9.06,Hashibe_CancerEpiBioPrev2009 +Current,Pharynx,OR,1.06,0.88,1.28,2.37,1.66,3.39,5.73,3.62,9.06,Hashibe_CancerEpiBioPrev2009 +Current,Larynx,OR,1.06,0.88,1.28,2.37,1.66,3.39,5.73,3.62,9.06,Hashibe_CancerEpiBioPrev2009 +Current,Oesophageal_SCC,OR,1.21,0.81,1.81,1.36,1.14,1.61,3.28,2.11,5.08,Prabhu_AJGastroEnt2014