Skip to content
This repository has been archived by the owner on Sep 10, 2023. It is now read-only.

Commit

Permalink
Remove Gadfly and update dependencies (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Sep 8, 2021
1 parent 0437dba commit 25bd8c4
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 260 deletions.
14 changes: 6 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Franklin = "713c75ef-9fc9-4b05-94a9-213340da978e"
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
RData = "df47a6cb-8c03-5eed-afd8-b6050d6c41da"
Expand All @@ -21,15 +20,14 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"

[compat]
CSV = "0.8"
CategoricalArrays = "0.9, 0.10"
DataFrames = "0.22, 1.1"
CSV = "0.9"
CategoricalArrays = "0.10"
DataFrames = "1"
DifferentialEquations = "6.16"
Distributions = "0.24"
Distributions = "0.25"
Franklin = "0.10"
Gadfly = "1.3"
RData = "0.8"
StatsFuns = "0.9"
StatsPlots = "0.14"
Turing = "0.15, 0.16"
julia = "1"
Turing = "0.18"
julia = "1.6"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TuringModels

[![CI][ci-img]][ci-url]

[![Site Analytics](https://img.shields.io/badge/Site-Analytics-blueviolet)](https://app.usefathom.com/share/ovpyqiuq/turingmodels.jl)

## Introduction

Expand Down
3 changes: 3 additions & 0 deletions _layout/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
{{if hascode}} {{insert head_highlight.html }} {{end}}
<link rel="stylesheet" href="/css/franklin.css">
{{isdef title}} <title>{{fill title}}</title> {{end}}

<!-- Analytics with a strong focus on privacy. This allows us to know how much attention updating the tutorials should have. -->
<script src="https://cdn.usefathom.com/script.js" data-site="OVPYQIUQ" defer></script>
</head>
<body>

Expand Down
1 change: 0 additions & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Before you look at the models below, you might want to look at the [Basic Exampl
- [m13.1](models/varying-slopes-cafe): Varying slopes cafes
- [m13.2](models/multinomial-poisson): Multinomial Poisson regression
- [m13.3](models/varying-intercepts-admission): Varying intercepts admission decisions
- [m16.5](models/lynx-hare): Lynx and hare populations

### 1st Edition (2016)

Expand Down
1 change: 1 addition & 0 deletions models/africa-first-candidate.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
+++
title = "Africa first candidate model"
showall = true
reeval = true
+++

In Edition 2 on page 244, McElreath defines the model as
Expand Down
25 changes: 0 additions & 25 deletions models/lynx-hare.md

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/africa-first-candidate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ model = model_fn(df.log_gdp, df.rugged_std, mean(df.rugged_std));

chns = sample(model, NUTS(), MCMCThreads(), 1000, 3)

# \defaultgadflyoutput{}
# \defaultoutput{}

#
158 changes: 0 additions & 158 deletions scripts/lynx-hare.jl

This file was deleted.

28 changes: 1 addition & 27 deletions src/TuringModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ module TuringModels

using CategoricalArrays
using DataFrames
using Gadfly

const project_root = pkgdir(TuringModels)
const project_root = string(pkgdir(TuringModels))::String

"""
output_dir(name)
Expand All @@ -16,29 +15,4 @@ function output_dir(name)
joinpath(project_root, "__site", "assets", "models", name, "code")
end

function write_gadfly_svg(output_dir, name, p; width=6inch, height=4inch)
fig_path = joinpath(output_dir, "$name.svg")
draw(SVG(fig_path, width, height), p)
end

function gadfly_plot(chns)
df = DataFrame(chns)
params = names(chns, :parameters)
sdf = DataFrames.stack(df, params, variable_name=:parameter)
sdf[!, :chain] = categorical(sdf.chain)

p1 = plot(sdf, ygroup=:parameter, x=:iteration, y=:value, color=:chain,
Geom.subplot_grid(Geom.line, free_x_axis=true, free_y_axis=true),
Guide.ylabel("sample value"),
# Key is shown on the right plot, so no need to show it twice.
Theme(key_position=:none)
)
p2 = plot(sdf, ygroup=:parameter, x=:value, color=:chain,
Geom.subplot_grid(Geom.density, free_x_axis=true, free_y_axis=true,
Guide.xlabel(orientation=:horizontal)),
Guide.ylabel("density"))

hstack(p1, p2)
end

end # module
39 changes: 0 additions & 39 deletions utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,3 @@ function lx_defaultoutput(com, _)
\fig{chns.svg}
"""
end

"""
\\defaultgadflyoutput{}
Plot `chns` via Gadfly.
Don't combine this with a call to StatsPlots or `\\defaultoutput` to avoid conflict errors.
"""
function lx_defaultgadflyoutput(com, _)
raw"""
```julia:write_helper
# hideall
using DataFrames
using Gadfly
using TuringModels
output_dir = @OUTPUT
function write_svg(name, p, width, height)
fig_path = joinpath(output_dir, "$name.svg")
draw(SVG(fig_path, width, height), p)
end;
df = DataFrame(chns)
params = names(chns, :parameters)
width = 8inch
height = length(params) * 2inch
nothing
```
\output{write_helper}
```julia:plot
write_svg("chns", # hide
TuringModels.gadfly_plot(chns)
, width, height) # hide
nothing # hide
```
\output{plot}
\fig{chns.svg}
"""
end

0 comments on commit 25bd8c4

Please sign in to comment.