chris campbell, phd – senior consultant [email protected] non-compartmental analysis...

47
Chris Campbell, PhD – Senior Consultant [email protected] Non-Compartmental Analysis using R Chris Campbell, PhD

Upload: brice-parker

Post on 23-Dec-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Chris Campbell, PhD – Senior [email protected]

Non-Compartmental Analysis using R

Chris Campbell, PhD

Chris Campbell, PhD – Senior [email protected]

R as an Analysis Engine

Chris Campbell, PhD – Senior [email protected]

Building Apps

• Java

• .NET

• R

Chris Campbell, PhD – Senior [email protected]

Why Build Analytic Applications?

Why Build Analytic Applications on R?

Why Analytics?

Chris Campbell, PhD – Senior [email protected]

Why Analytics?

• Analytics answer many 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

Chris Campbell, PhD – Senior [email protected]

Who is a good driver? How do we win more games?What bonus should I pay?

Will someone like this? What’s the right dose?When might this break?

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

Deploying Analytics

• Adding analytics into a business process

more informed decisions

• Complex analytics shouldn’t be attempted by non-analysts

• Communication between the decision maker and the analyst

Chris Campbell, PhD – Senior [email protected]

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!

Chris Campbell, PhD – Senior [email protected]

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?

Chris Campbell, PhD – Senior [email protected]

UserInterface

Data

AnalyticOutputs

DataStorage

AnalyticCode

Code Mgment

Analytic App Structure

AnalyticEngine

Chris Campbell, PhD – Senior [email protected]

Why build Analytic Applications on R?

We want a programmable engine so that it can be readily extended (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 available

R is rapidly developed

Chris Campbell, PhD – Senior [email protected]

Why build Analytic Applications on R?

Building applications requires installing analytic engine on desktops, servers, clusters, clouds

R 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

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

Project Mgment Requirements

Behaviour Driven

Code Review

Review board

StatET

testthatroxygen2

Continuous Integration

Issue TrackingQuality Manual

Dev Procedures

Coding Standards

Knowledge Mgment

TestCoverage

Chris Campbell, PhD – Senior [email protected]

RapidNCA, the non-compartmental analysis workflow tool

• Need for RapidNCA• Using .NET• RapidNCA Structure• Code Quality• Connections with R.NET• Complete & Deploy RapidNCA

Chris Campbell, PhD – Senior [email protected]

Need for RapidNCA

• Customer needed to send monthly reports to dozens of trial centres

• Small team, so time limited• Predefined non-compartmental

analysis• Standardized report

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

Using .NET Visual Studio

• A graphical programming tool (IDE)• Visual Studio Express - free version

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

UserInterface

Data

AnalyticOutputs

DataStorage

AnalyticCode

Code Mgment

Data Service

RapidNCA Structure

AnalyticEngine

Chris Campbell, PhD – Senior [email protected]

RapidNCA StructureMangoNca Analytic Code

AnalyseElement

DoAnalysis

GetAnalysis

UnitTests

DataChecks

Chris Campbell, PhD – Senior [email protected]

RapidNCA StructureMangoNca Analytic Code

Chris Campbell, PhD – Senior [email protected]

Code QualityUnit Tests

• Ensure product works!• User/Customer/Payer trust• Ease of maintenance/extension

Chris Campbell, PhD – Senior [email protected]

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!

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

Connections with R.NET

• What will be provided to R?• What will be returned from R?• What happens if something goes wrong?

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

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>

Chris Campbell, PhD – Senior [email protected]

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) }

Chris Campbell, PhD – Senior [email protected]

Connections with R.NET

• R is efficiently accessed, via R.Net (as pictured in Visual Studio) via a Plugin (as above)

_pluginsManager = new RPluginManager(PluginLocation, RLocation);_pluginsManager.SetActivePlugin();_session = _pluginsManager.GetSession();bool sessionOk = _pluginsManager.TryMakeSession(out _session);

Chris Campbell, PhD – Senior [email protected]

Connections with R.NET

UserInterface

Data

AnalyticOutputs

DataStorage

AnalyticCode

Code Mgment

AnalyticEngine

Data Service

R.NET

AnalyticEngine

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

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();

Chris Campbell, PhD – Senior [email protected]

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

Chris Campbell, PhD – Senior [email protected]

Deploy Tool

Chris Campbell, PhD – Senior [email protected]

Data Import

Chris Campbell, PhD – Senior [email protected]

Map Variables

Chris Campbell, PhD – Senior [email protected]

Review Analysis

Chris Campbell, PhD – Senior [email protected]

Review Grouping

Chris Campbell, PhD – Senior [email protected]

Generate Report

Chris Campbell, PhD – Senior [email protected]

Select Report Type

Chris Campbell, PhD – Senior [email protected]

Add Group Comments

Chris Campbell, PhD – Senior [email protected]

View Report

Chris Campbell, PhD – Senior [email protected]

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