designing and creating applications built on r richard pugh, andy nicholls & chris campbell 23...
TRANSCRIPT
![Page 1: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/1.jpg)
Designing and Creating applications built on RRichard Pugh, Andy Nicholls & Chris Campbell23rd October 2012
![Page 2: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/2.jpg)
Thank you for the invitation to speak tonight
![Page 3: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/3.jpg)
Andy NichollsSenior R Consultant
Chris CampbellSenior R Consultant
Richard PughPrincipal R
Consultant & Co-Founder
![Page 4: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/4.jpg)
Agenda
• Who are Mango Solutions?• Why Build Analytic Applications on R?• Formal R Application Development• Case Studies• The R Community• Discussion
![Page 5: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/5.jpg)
Who are Mango Solutions?
![Page 6: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/6.jpg)
Overview of Mango Solutions
• Private Company formed in 2002• Global Team of ~70• Cross-Sector Software and Services• ISO 9001 Accredited
![Page 7: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/7.jpg)
Located here ...
Bath, UK London, UK Shanghai, CN Basel, CH
![Page 8: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/8.jpg)
Spend a lot of time here ...
![Page 9: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/9.jpg)
The Beginning: October 2002
• Started by 2 ex-Insightful colleagues• Sales Guy (BO, Cognos
etc)• Techy Guy (S+, SAS, R
etc)
• Idea to deploy predictive analytics to business users
![Page 10: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/10.jpg)
Why Mango?
• Early awful ideas• DataStatz• Stats Entertainment• VizUStat• Stats2U
• In the end, named after my colleagues cat
![Page 11: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/11.jpg)
Growth of Mango Solutions
Number of Employees
Other
Support
Testers
PMs
Developers
Consultants
Total = 10
2006
Other
Support
Testers
PMs
Developers
Consultants
Total = 28
2010
Other
Support
Testers
PMs
Developers
Consultants
0 2 4 6 8 10 12 14 16 18 20 22
Total = 71
2012
![Page 12: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/12.jpg)
What we do?
R Training
Code Creation
Validation
Support
Consultants
![Page 13: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/13.jpg)
What we do?
Consultants Developers
Analytic Application Development
![Page 14: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/14.jpg)
Mango Key Industries
• Mango work across sectors:• Pharmaceuticals
• Mango Imaging• Finance• Energy• Sensory
![Page 15: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/15.jpg)
Why Build Analytic Applications on R?
![Page 16: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/16.jpg)
Why Analytics?
• Analytics can help people answer all sorts of questions
• I believe there is no company in the world today who cannot benefit from analytics in some way
• More and more people are realising it
![Page 17: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/17.jpg)
Who is a good driver? How do we win more games?What bonus should I pay?
Will someone like this? What are they likely to want?When might this break?
![Page 18: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/18.jpg)
Why build Analytic Applications?
• 3 key reasons we see:• To deploy analytical tools to decision
makers• To make an analysts life more efficient• To add rigour to an analysts workflow
![Page 19: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/19.jpg)
Deploying Analytics
• Adding analytics into a business process can mean more informed decisions can be made
• Complex analytics shouldn’t be attempted by non-analysts
• Means there is a communication between the decision maker and the analyst
![Page 20: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/20.jpg)
Deploying Analytics
• If we build an application which …• is easy for the decision maker to use• contains the correct analysis to apply• communicates analytical results in suitable
manner• … this leads to some major benefits!
![Page 21: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/21.jpg)
Benefits for the Analyst
Benefits for the Decision Maker
No need to wait for information
Can perform “what if” analysis
Decision not dependent on analyst availability
Less need to perform often-repetitive tasks
Comfortable that the “right” analysis is being
run
Can get on with more strategic things?
![Page 22: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/22.jpg)
AnalyticEngine
UserInterface
Data
AnalyticOutputs
DataStorage
AnalyticCode
Code Mgment
Analytic App Structure
![Page 23: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/23.jpg)
Why build Analytic Applications on R?Building applications requires installing analytic engine on desktops, servers, clusters, cloudsR is license free
Building analytic applications involves integrating an analytic engine with other technologies (data sources, UI etc)R’s open nature means it can be readily integrated
![Page 24: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/24.jpg)
Why build Analytic Applications on R?We want a programmable engine so that it can be readily extended (i.e. no black boxes please)R can be extended by the developer as needed
We often want to be able to deploy new algorithms and techniques as they become availableR is rapidly developed
![Page 25: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/25.jpg)
Formal R Application Development
![Page 26: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/26.jpg)
Formal R Development
• Creating sophisticated analytic applications requires a formal development approach
• This mostly means taking standard development practices and applying it to analytics
• Mango’s formal R development procedures and structure has been evolving since its inception ~2004
![Page 27: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/27.jpg)
Project Mgment Requirements
Behaviour Driven
Code Review
Review board
StatET
runitroxygen2
Continuous Integration
Issue TrackingQuality Manual
Dev Procedures
R Coding Standards
mangoUtils
Knowledge Mgment
![Page 28: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/28.jpg)
Project Mgment Requirements
Behaviour Driven
Code Review
Review board
StatET
runitroxygen2
Continuous Integration
Issue TrackingQuality Manual
Dev Procedures
Coding Standards
mangoUtils
Knowledge Mgment
![Page 29: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/29.jpg)
Project Mgment Requirements
Behaviour Driven
Code Review
Review board
StatET
testthatroxygen2
Continuous Integration
Issue TrackingQuality Manual
Dev Procedures
R Coding Standards
mangoUtils
Knowledge Mgment
![Page 30: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/30.jpg)
Case Studies
![Page 31: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/31.jpg)
Case Studies
• These are examples of applications we’ve built that use R in some way
• We’re presented a range of information about each including:• Business Reason for the application• Technical Approach• Some Technical Detail where applicable• Things that worked well / things that didn’t
![Page 32: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/32.jpg)
Case Studies
• Ranges from information we can fully disclose to only being able to say vague things about the customer
• Only so much info we can give today – please see us after or contact us and we can step through things in more detail
Richard Pugh = [email protected]
Andy Nicholls = [email protected]
Chris Campbell = [email protected]
![Page 33: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/33.jpg)
Case Studies
• PKPD Web Modelling Platform• M&S Workflow Platform• Non-Compartmental Analysis Application• Coffee Blend Optimisation Tool• Pipeline Corrosion Forecasting Application• Backtesting Application
![Page 34: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/34.jpg)
CASE STUDYPKPD WEB PLATFORM
![Page 35: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/35.jpg)
Case Study: PKPD ModellingOverview• Pharmacokinetics-
pharmacodynamics (PKPD) is the study of the manner in which a drug transitions through the body and its impact on a target disease
• PK is highly complex, involving sophisticated non-linear mixed effects modelling approaches
![Page 36: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/36.jpg)
Case Study: PKPD ModellingOverview• Modellers use “NONMEM” software in order to
fit these models• Inputs and outputs to NONMEM are a mixture
of structured and unstructured textual files• R often used to analyse the outputs in order to
assess model fit (see “xpose4” library)
![Page 37: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/37.jpg)
Case Study: PKPD ModellingOverview• PKPD is an evolving and exciting area, with
modellers needing flexibility and a variety of tools
• However, being within life sciences, rigour around workflows is key in order to satisfy regulatory requirements
![Page 38: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/38.jpg)
Case Study: PKPD ModellingThe Challenge• Build a modern modelling platform that provides
rigour whilst allowing the modellers the flexibility they need
• Range of technical users from “everything is a shell script” to “which button do I click”
• Execution of third party tools (NONMEM, R, SAS, PsN, …) in a controlled manner
• Interface to generate reproducible graphics, tables and reports
![Page 39: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/39.jpg)
Case Study: PKPD ModellingThe “R” bit• Where does R fit in?
• Many users use R and want to be able to develop scripts and execute them on an internal grid
• R used as the graphics engine to support the model evaluation and reporting processes
• Users want to be able to execute R interactively with objects in their project
![Page 40: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/40.jpg)
The App
App Server
Execution Server(s)
MIFMIF Queue
Cloud
Grid
+ Others
+ Others
RPool Mgr
![Page 41: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/41.jpg)
Case Study: PKPD ModellingWhat is a “Report Item Definition”• Definition of a graph or table that can be
executed from Navigator• Consists of snippet of R code, options that may
be presented to the user, required columns, and a few other bits
• Can be used in a number of situations in the application
• Originally XML then stored in Db (XML shown to give a feel for structure on next slide)
![Page 42: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/42.jpg)
Report Options
Source Data
Command Definition
![Page 43: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/43.jpg)
The App / RPool Manager
Data GraphTableText
DataItem
GraphItem
TableItem
TextItem
Data Frame
GraphicsTable
ObjectCharacter
xmlMethod
xmlMethod
xmlMethod
xmlMethod
![Page 44: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/44.jpg)
Execution Engine (Java)
CommandDefinitions
CommandResultsV
ers
ion
Contr
ol
![Page 45: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/45.jpg)
Case Study: PKPD ModellingHow are “RIDs” used?• Created, managed by Super Users (under version
control)• Called in a few places in the application:
• Directly (create this graph with this data)• In “Run Views” (reports)• In “Comparison Views” (reports that compare
models)• In “Template Reports” (tagged docx files)
![Page 46: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/46.jpg)
Case Study: PKPD ModellingOutcome• The app in general was a big success• The “R” part was created as a separate service that we
have since reused in a number of other applications (e.g. Lloyds Risk Platform!)
• Shame that regulatory rules forced some design which we’re now building alternatives too
• Next: interactive graphical presentation
![Page 47: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/47.jpg)
CASE STUDYM&S WORKFLOW PLATFORM
![Page 48: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/48.jpg)
Case Study: M&S Workflow PlatformOverview• Exciting project for major pharmaceutical company• Possibly the closest we’ve come to deploying an
analysts workflow in a scalable platform
• Hundreds of pre-clinical (animal) studies are run by a team of ~400 scientists
• Analysis performed by roughly 15 advanced modellers• Outcome: most studies not analysed!
![Page 49: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/49.jpg)
Case Study: M&S Workflow PlatformThe Challenge• Idea to create a truly scalable platform to allow bench
scientists to run their own analysis• Modeller publishes an analysis “protocol” containing
analysis paths, code, and support documentation• Desktop application pulls from central set of protocols
and “derives” the interface which is presented to the user
• Modelling can put in checks to ensure things look right (e.g. data is of right format, model fit is particularly poor but user seems keep to create predictions from it)
![Page 50: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/50.jpg)
Case Study: M&S Workflow PlatformThe Solution• Eclipse RCP application executing R and NONMEM
scripts on an internal LSF grid, with protocols and code held in SVN
• Generated workflow “protocol” definition (XML) detailing possible paths in a step, linked to R scripts and NONMEM model code with corresponding dialog
• Built “Protocol Developer” Eclipse interface onto repository
• RCP application derives analysis paths, UI, options and commentary to guide the end user
![Page 51: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/51.jpg)
Protocol Metadata
Workflow
Analysis StepData Check Step Commentary
RScript
RScript
NM ModelFile
Options Options
![Page 52: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/52.jpg)
Modeller Scientist
NONMEM
NONMEM
LSF GridProtocol Server
FileSystem
![Page 53: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/53.jpg)
Possible Models
Derived Options Commentary
![Page 54: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/54.jpg)
![Page 55: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/55.jpg)
Case Study: M&S Workflow PlatformHow did it go• Technical solution was very strong and
applicable to other areas• RCP good technology, but steep learning curve• Testing was complex • Agile project – pros and cons• Ultimately, not deployed (site closure)
![Page 56: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/56.jpg)
CASE STUDYNON-COMPARTMENTAL ANALYSIS
![Page 57: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/57.jpg)
RapidNCA, the non-compartmental analysis workflow tool• Need for RapidNCA
• Using .NET
• RapidNCA Structure
• Code Quality
• Connections with R.NET
• Complete & Deploy RapidNCA
![Page 58: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/58.jpg)
Need for RapidNCA
• Customer needed to send monthly reports to dozens of trial centres
• Small team, so time limited
• Predefined non-compartmentalanalysis
• Standardized report
![Page 59: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/59.jpg)
Using .NET What is .NET?
• Object-oriented environment to develop applications
• Safe execution environment
• Choice of programming languages
• Framework consisting of:• runtime• class library
• Developed with Visual Studio
![Page 60: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/60.jpg)
Using .NET Visual Studio
• A graphical programming tool (IDE)
• Visual Studio Express - free version
![Page 61: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/61.jpg)
Using .NETChoice of languages
• C# is the main one
• F# is a functional language (similar concepts to OCaml)
• XAML (a Microsoft declarative XML language) for interactive graphics
• C++/CLI useful for legacy and bespoke parallel processing (including GPGPU)
• Other possibilities...
• Vb.Net is very like C# (no advantage over it)
• Third parties have added languages to the CLI platform
![Page 62: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/62.jpg)
Using .NET“Ajar Source” Platform
• Not exactly open source, but…
• Most CLI third party languages are open
• C# and VB.Net are not, but many open source projects based on them
• Microsoft have made F# open source
• Compiler is free
• Other editors / IDEs are available
![Page 63: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/63.jpg)
Using .NETPerformance
• Performance is very good
• On graphics (millions of data points will plot with ease and zoom smoothly)
• Computation is fast enough in C#, calling R adds little overhead
• Standard Maths library is limited; third parties and MS maths for “drawing” are better
• Data parallel computation is possible on the desktop (GPGPU)
• F# provides further “big data” capabilities
![Page 64: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/64.jpg)
UserInterface
Data
AnalyticOutputs
DataStorage
AnalyticCode
Code Mgment
AnalyticEngine
Data Service
RapidNCA Structure
![Page 65: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/65.jpg)
RapidNCA StructureMangoNca Analytic Code
AnalyseElement
DoAnalysis
GetAnalysis
UnitTests
DataChecks
![Page 66: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/66.jpg)
RapidNCA StructureMangoNca Analytic Code
![Page 67: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/67.jpg)
Code QualityUnit Tests
• Ensure product works!
• User/Customer/Payer trust
• Ease of maintenance/extension
![Page 68: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/68.jpg)
Code QualityRun Code, Check Output
• Working Cases
> test1 <- ncaAnalysis(Conc = c(4, 9, 8, 6, 4:1, 1), + Time = 0:8, Dose = 100, Dof = 2) > checkEquals(test1[1, "ROutput_adjr2"], 0.9714937901,+ tol = 1e-8)[1] TRUE
> require(RUnit) > # there are other automated test packages!
![Page 69: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/69.jpg)
Code QualityError Case Unit Tests
• Use try
• Handled Error Cases
> test7 <- try(AUCLast(Conc = 1:10, Time = 9:0), + silent = TRUE)> checkEquals(test7, + "Error in checkOrderedVector(Time, ... ")[1] TRUE
> test26 <- ncaAnalysis(Conc = c(4, 9, 8, 6, 4:1, 1),+ Time = 0:8, Dof = 1)> checkEquals(test26[, "ROutput_Error"], + "Error in checkSingleNumeric(Dose, ... ")[1] TRUE
![Page 70: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/70.jpg)
Connections with R.NET
• What will be provided to R?
• What will be returned from R?
• What happens if something goes wrong?
![Page 71: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/71.jpg)
Connections with R.NETUsing the R Service
• R.NET allows R calls to be submitted to an R service
• R.NET connects to R down to Expression level
• Data from return objects passed back into .NET
![Page 72: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/72.jpg)
Connections with R.NETData Checks
• Function may be passed data outside its anticipated structure
> checkOrderedVector(c(0, 1, 3, 2, 4), + description = "Time") Error in checkOrderedVector(c(0, 1, 3, 2, 4), description = "Time") : Error: Time is not ordered. Actual value is 0 1 3 2 4>
![Page 73: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/73.jpg)
Connections with R.NETData Checks
• The tool expects a certain return object
• An error in an R call should be trapped by the communicating function
• Return object passed as normal
• An error checking element of the return object can report information about the error
> check01 <- try(checkOrderedVector(Time, + description = "Time"), silent = TRUE)> if (is(check01, "try-error")) { return(object) }
![Page 74: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/74.jpg)
Connections with R.NET
_pluginsManager = new RPluginManager(PluginLocation, RLocation);_pluginsManager.SetActivePlugin();_session = _pluginsManager.GetSession();bool sessionOk = _pluginsManager.TryMakeSession(out _session);
• R is efficiently accessed, via R.Net (as pictured in Visual Studio) via a Plugin (as above)
![Page 75: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/75.jpg)
Connections with R.NET
UserInterface
Data
AnalyticOutputs
DataStorage
AnalyticCode
Code Mgment
AnalyticEngine
Data Service
R.NET
![Page 76: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/76.jpg)
AnalysisDisplay
Get PK Params
DataService
DialogService
AppLogger
Status BarService
App Config
Mgment
DataImporters
ProjectWizard
Validators
Receive R
Output
Create R Expressns
Connections with R.NET.NET Data Service
R.NET
![Page 77: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/77.jpg)
Connections with R.NETUsing the framework
_pluginsManager = new RPluginManager(PluginLocation, RLocation);_pluginsManager.SetActivePlugin();_session = _pluginsManager.GetSession();bool sessionOk = _pluginsManager.TryMakeSession(out _session);
_session.SetNumericSymbol("TimePtVector", CheckTimePointData(toAnalyse));_session.SetNumericSymbol("ConcVector", CheckConcentrationPointData(toAnalyse));
var evalString = string.Format("ncaAnalysis(TimePtVector, ConcVector, …
MathEngineDataRowDto<double> ncaGetBack = _session.PerformNumericEvaluation(evalString, "ROutput_Error");_lastErrors = ncaGetBack.ErrorStrings;
_session.FlushConsole();_pluginsManager.RelinquishSession();
![Page 78: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/78.jpg)
Complete & Deploy RapidNCA
• Can users understand how to use tool?
• How confident are we in tool output?
• On-going code review• Independent test team• Installation Qualification• Operational Qualification• Performance Qualification
![Page 79: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/79.jpg)
Deploy Tool
![Page 80: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/80.jpg)
Data Import
![Page 81: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/81.jpg)
Map Variables
![Page 82: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/82.jpg)
Review Analysis
![Page 83: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/83.jpg)
Review Grouping
![Page 84: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/84.jpg)
Generate Report
![Page 85: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/85.jpg)
Select Report Type
![Page 86: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/86.jpg)
Add Group Comments
![Page 87: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/87.jpg)
View Report
![Page 88: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/88.jpg)
Conclusions
• Great graphical interfaces can be built using .NET
• Intuitive interactive features are available
• R.NET allows R analysis to be accessed as a service
• Good coding practice will ensure application is robust
• Work on a well engineered framework will be rewarded with desktop solutions created at high speed
![Page 89: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/89.jpg)
CASE STUDYCOFFEE BLEND OPTIMIZATION
![Page 90: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/90.jpg)
Company Background
• A global chocolatier, biscuit baker, candy maker and maker of gum.
![Page 91: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/91.jpg)
Business /Technical Situation
• The client was using a desktop SPLUS application to simulate and optimise coffee blends for their manufacturing teams
• Hugely successful application saving the company $millions
• They wanted to make improvements and expand the usage beyond Global Statistics and beyond coffee
• Also keen to remove the license fee
![Page 92: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/92.jpg)
Application Workflow
Import Data from Excel
Graphical Visualisations
Export Data
Run Blend Optimiser
Simulate Blends
Audit Log
![Page 93: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/93.jpg)
System Architecture
Functions for GUI
Functions for Analysis
R Package
Optimizer
Data Import
Data Export
![Page 94: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/94.jpg)
Approach• Development phase split into three separate pieces:
• Code conversion
• GUI creation
• Development and integration of a new optimiser
• Each required the generation of unit and system tests and appropriate documentation, including help files
• Design specifications captured prior to development
• Project estimated at c90 man days over 3 months
![Page 95: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/95.jpg)
Creation of new GUI
![Page 96: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/96.jpg)
GUI ChoicesSome R/R-based technologies we could have used...
• tcltk is R’s ‘recommended’ menu builder
• Glade, RGtk2
• gWidgets
• rpanel
• Deducer
• manipulate (Rstudio)
• ...
![Page 97: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/97.jpg)
GUI Choices
Other options:
• Choice is almost limitless
• Often they require a knowledge of other languages such as Java or C
• Possibly warrants a standalone talk...
![Page 98: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/98.jpg)
Creation of a New GUI using RGtk2• RGtk2 adapter for R of the GTK+ engine
• Gimp Toolkit
• Glade can be used to trial new features
• GTK allows for automated testing of the GUI• Huge time saving
![Page 99: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/99.jpg)
![Page 100: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/100.jpg)
![Page 101: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/101.jpg)
Code Conversion
Mango took a test-based approach for the code conversion (RUnit)
• Allows for automated testing in future revisions
• Simple PASS/FAIL reporting
• SPLUS knowledge not required for R code development
![Page 102: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/102.jpg)
![Page 103: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/103.jpg)
Optimization
• The original SPLUS application used the SPLUS NuOpt optimizer
• R NuOpt exists but only on license
• Mango used an open source optimiser that we integrated into the R GUI
• Mango implemented a ‘quick run’ option to allow quick comparisons with the simulation piece
![Page 104: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/104.jpg)
![Page 105: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/105.jpg)
Primary Benefits
• New departments are now benefitting from the application
• The application is now in the hands of the manufacturing teams, reducing the burden on Global Statistics
• Test-based approach facilitates future development of the application
![Page 106: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/106.jpg)
CASE STUDYPIPELINE CORROSION APP
![Page 107: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/107.jpg)
Background
• One of the biggest companies in the world with thousands of staff
• Oilfield Exploration Team based in the UK but with responsibility for complex exploration areas• Alaska, shale fields etc
![Page 108: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/108.jpg)
Business Situation
• Thousands of miles of pipeline corroding in freezing, isolated areas
• How do you choose how often to inspect them?
• The cost of a leak can run into many billions of £s
![Page 109: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/109.jpg)
Technical Situation
• Customer Team were analysing data using S-PLUS Insightful Miner with many non-analytical workarounds
• Process was messy and took a long time to run
![Page 110: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/110.jpg)
System Architecture• This piece is one of several in a continuous
workflow
• All information is fed back into the database
Functions for GUI
Functions for Analysis
R Package
Access Database
General Workflow
Read
Write
![Page 111: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/111.jpg)
Approach• Consulting engagement to improve programming
techniques and statistical methodology
• Create an R package for the code
• Construct a GUI in order to deploy to non-technical users on the frontline
![Page 112: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/112.jpg)
![Page 113: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/113.jpg)
![Page 114: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/114.jpg)
An Interesting Challenge:Converting S-Plus Code to R
![Page 115: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/115.jpg)
This is Easy, Right?
Some (true?) statements:
• R can be considered as a different implementation of S
• There are some important differences, but much code written for S runs unaltered under R
Discuss...
Source: www.r-project.org
![Page 116: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/116.jpg)
Considerations
S+ applications can generally be split into two pieces:
• An underlying library of code
• A set of functions defining the menu system and help pages
![Page 117: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/117.jpg)
Approach
There are essentially two approaches to code conversion:
• Direct Conversion
• Test-based Conversion
![Page 118: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/118.jpg)
Direct Conversion
• Requires knowledge of both languages (stdev vs sd)
• Relatively quick to achieve
• Difficult to prove the new code does what the old code did
![Page 119: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/119.jpg)
Test-based Conversion
• Generating unit tests in S+ requires some S+ knowledge
• Takes some time to generate and document tests but better in the long-run
• Unit tests give a definitive PASS/FAIL result
• Can often be automated
![Page 120: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/120.jpg)
Code Conversion Challenges
• The application upgrade usually coincides with an operating system upgrade
• Windows (or other) version and R version need to be determined in advance
• It is almost guaranteed that the new system will produce different results for the same test data!
![Page 121: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/121.jpg)
What is “different”?
• Often this is simply rounding• Still require agreement on precision: 0.049782 vs
0.050436
• If simulation is involved this can be VERY difficult to define!!!
• Appearance of graphics may also differ
![Page 122: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/122.jpg)
Other Challenges
As the business owner I want to use the opportunity to improve the application:
• New menu items
• New functionality
• Modifications to existing functionality
All of these require careful planning
![Page 123: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/123.jpg)
Primary Benefits for Customer
• Rationalised code base means the analysis is quicker and extensible by end-users
• Construction of a front-end has enable rollout to users on the font-line in Alaska
• Conversion to R has removed license cost
![Page 124: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/124.jpg)
CASE STUDYBACKTESTING APP FOR HEDGE FUND
![Page 125: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/125.jpg)
Case Study: Backtesting AppOverview• Backtesting has a key role to play in the testing
of automated trading strategies• Asked by a Hedge Fund Manager to build for his
team of users (who love Excel)• Mango were asked to build a backtesting
platform that was more sophisticated that what was on offer from other vendors
• Sorry that the details may be occasionally sketchy in this section
![Page 126: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/126.jpg)
Case Study: Backtesting AppThe Challenge• Key parts of the challenge included:
• Integration with standard finance data streams
• Advanced portfolio optimisation• Flexibility to define automated strategy• Transaction-cost based benefit analysis• Leverage of financial hurdle• ARCH-style error incorporation• Advanced reporting
![Page 127: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/127.jpg)
AlphaStorage
DataStorage
DataFlow
.NETInterface
RdotNet
CInterface!
.RdaFiles
![Page 128: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/128.jpg)
How I learnt apply functions!!Some hacky code here …
![Page 129: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/129.jpg)
Case Study: Backtesting AppThe Outcome• Very successful hedge fund• Convinced the users to use R – UI dropped!
![Page 130: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/130.jpg)
The R Community
![Page 131: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/131.jpg)
IP Considerations
• IP based on R includes:• New libraries & code• New scripts
• Mango attempt to open source (with client permission) any “R-side” generic functionality
• Also feedback and assist library authors
UserInterface
AnalyticCode
New RLibraries
![Page 132: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/132.jpg)
Great Example
• MSToolkit library built for Pfizer• Funded by Pfizer, built by Mango• Released as open source library• Since extended by other companies
![Page 133: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/133.jpg)
R Community
• Contribute code where allowed/useful• Sponsor R conferences and events• Provide free training courses / webinars• Organise and fund many R user groups
(LondonR, BaselR, ZurichR, ShanghaiR, NewJerseyR, …)
![Page 134: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/134.jpg)
The End!
![Page 135: Designing and Creating applications built on R Richard Pugh, Andy Nicholls & Chris Campbell 23 rd October 2012](https://reader035.vdocuments.site/reader035/viewer/2022062511/551abfd6550346b2288b52ed/html5/thumbnails/135.jpg)
Summary
• Thank you for the invitation• Hope the discussion was useful
• We could only cover certain amount of detail in time, so ask us for more if interested!