35
Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Embed Size (px)

Citation preview

Page 1: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Progress on the software developed under E-STAT

Bill Browne and Chris Charlton

Page 2: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Why the slides?• To remind me which templates to demonstrate

• Let’s start with simply demonstrating 1 templateTemplate1lev with the tutorial dataset and a

regression model in E-STAT• Run in E-STAT• Show generated C code • Show java script and explain the server

possibilities• Show the template code (maybe discuss input

functions)

Page 3: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Explanation for following screenshots

• We show how to set up the model and run using the E-STAT engine

• The generated C code can be taken away and run on it’s own or modified by an algorithm writer

• The Java script code is similar however offers the opportunity of hosting the software on a server but running the estimation (via Java script) on the local machine.

Page 4: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Setting up first model

Page 5: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Equations for model and model code

Page 6: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Output from the E-STAT engine

Page 7: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Output of generated C code

Page 8: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

View of Java Script source

Page 9: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Java Script output

Page 10: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Template input codeclass Template1Lev(Template): invars = '''y = DataVector('response: ')D = Text('specify distribution: ', ['Normal', 'Binomial', 'Poisson'])if D.name == 'Binomial': n = DataVector('denominator: ') link = Text('specify link function: ', ['logit', 'probit', 'cloglog'])if D.name == 'Poisson': link = Text(value = 'ln') offset = Text('Is there an offset: ', ['yes', 'no']) if offset.name == 'yes': n = DataVector('offset: ')if D.name == 'Normal': tau = ParamScalar() sigma = ParamScalar()x = DataMatrix('explanatory variables: ')beta = ParamVector()beta.ncols = len(x.name) '''

This code matches with the inputs in the web interface

Page 11: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Stringing Templates together

• Use rats dataset and aim to fit random intercepts model:

• Use template split and demonstrate the view and summary buttons

• Form the dataset called ratlong• Choose as template2lev and ratlong dataset.• Again use view to look at the dataset created.• Setup the random intercepts model

Page 12: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Viewing a data set via the view button

Page 13: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Summarising the data (like MLwiN names window)

Page 14: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Converting repeated measures data to a single response (Templatesplit)

Page 15: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Viewing the new dataset

Page 16: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Setting up a random intercepts model (with template2lev)

Page 17: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Output from the model

Page 18: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Rats continued

• Fit the model storing results in ratout• Construct the VPC (= (1/tau_u)/((1/tau_u)

+(1/tau)) !!!) using TemplateEvalute storing in ratsout again

• Then view the chain using TemplateColumndiag

• Finally look at the residuals using Templatecaterpillar

Page 19: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Using TemplateEvaluate to construct the VPC

Page 20: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

View the file ratout (including VPC)

Page 21: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Using TemplateColumnDiag to look at the VPC

Page 22: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Set up templateCaterpillar for Caterpillar plot

Page 23: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Caterpillar plot

Page 24: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Other Stuff

• Graphics – show with tutorial (or with output u_1 and tau_u)

TemplateXYlabelTemplateHistogramAnd then show the python code!• Finally large numbers of model templates –

some still to do depends on Bruce’s algebra system.

Page 25: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

TemplateXYlabel

Page 26: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

All code for templateXYlabel – quite a short template!

from EStat.Templating import *from mako.template import Template as MakoTemplateclass TemplateXYLabel(Template): invars = '''yaxis = DataMatrix('Y values: ')xaxis = DataVector('X values: ')

yaxislabel = Text('Y label: ')xaxislabel = Text('X label: ')''‘ def preparedata(self, data): self.data = data return self.data def resultdata(self, m): return self.data def graphdata(self, data): import numpy from matplotlib.figure import Figure import matplotlib.lines as lines from matplotlib.backends.backend_agg import

FigureCanvasAgg

import subprocess import tempfile import os fig = Figure(figsize=(8,8)) ax = fig.add_subplot(100 + 10 + 1, xlabel = str(self.objects['xaxislabel'].name), ylabel = str(self.objects['yaxislabel'].name)) for n in self.objects['yaxis'].name: ax.plot(self.data[self.objects['xaxis'].name], self.data[n], 'x')

canvas = FigureCanvasAgg(fig) directory = tempfile.mkdtemp() + os.sep canvas.print_figure(directory + 'xyplot.png', dpi=80) return directory + 'xyplot.png'

Page 27: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

TemplateHistogram

Page 28: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Classification as index notation

• Tutorial dataset and Template2levindex• Set up model then fire up Bruce’s demo (via

notepad)• Next show the C code• Finally run the model• Camille to demo interoperability later.• Going off piste: Any other models ?• Any suggestions for improvements, wish list etc.

Page 29: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Setting up model in E-Stat

Page 30: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Model Code in detailmodel { for (i in 1:length(normexam)) { normexam[i] ~ dnorm(mu[i], tau) mu[i] <- cons[i] * beta0 + standlrt[i] * beta1 + u[school[i]] * cons[i] } for (j in 1:length(u)) { u[j] ~ dnorm(0, tau_u) } # Priors beta0 ~ dflat() beta1 ~ dflat() tau ~ dgamma(0.001000, 0.001000) tau_u ~ dgamma(0.001000, 0.001000) }

Page 31: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Bruce’s Demo algebra system step for u

Page 32: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Generated C code – note the if statements for u

Page 33: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Model executed in E-Stat

Note code takes longer but generalises easily to cross-classified models.

Page 34: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Interoperability with WinBUGS

Page 35: Progress on the software developed under E-STAT Bill Browne and Chris Charlton

Output from WinBUGS with multiple chains