Skip to content

Commit

Permalink
added value of information example
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed May 11, 2012
1 parent 80c65d5 commit e5d913b
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 13 deletions.
14 changes: 9 additions & 5 deletions R/ForwardSimulate.R
Expand Up @@ -15,11 +15,13 @@
#' assessment of stock size
#' @param z_i a function which returns a random number from a distribution
#' for the implementation uncertainty in quotas
#' @param profit function, if known
#' @return a data frame with the time, fishstock, harvested amount,
#' and what the escapement ("unharvested").
#' @export
ForwardSimulate <- function(f, pars, x_grid, h_grid, x0, D, z_g,
z_m=function(x) 1, z_i = function(x) 1){
z_m=function(x) 1, z_i = function(x) 1,
profit=NULL){
# initialize variables with initial conditions
OptTime <- dim(D)[2] # Stopping time
x_h <- numeric(OptTime) # population dynamics with harvest
Expand All @@ -28,7 +30,8 @@ ForwardSimulate <- function(f, pars, x_grid, h_grid, x0, D, z_g,

s <- x_h # also track escapement
x <- x_h # What would happen with no havest

p <- numeric(OptTime)


## Simulate through time ##
for(t in 1:(OptTime-1)){
Expand All @@ -43,12 +46,13 @@ ForwardSimulate <- function(f, pars, x_grid, h_grid, x0, D, z_g,
z <- z_g()
# population grows
x_h[t+1] <- z * f(x_h[t], h[t], pars) # with havest
s[t] <- x_h[t] - q_t # anticipated escapement
s[t+1] <- x_h[t] - q_t # anticipated escapement
x[t+1] <- z * f(x[t], 0, pars) # havest-free dynamics
}
p[t] <- profit(x_h[t], h[t])
}
# formats output
data.frame(time = 1:OptTime, fishstock = x_h, harvest = h,
unharvested = x, escapement = s)
unharvested = x, escapement = s, profit = p)
}


Expand Down
75 changes: 69 additions & 6 deletions inst/examples/Reed.md
Expand Up @@ -213,7 +213,7 @@ ggplot(subset(dt,reps==1)) +
geom_line(aes(time, harvest), col="darkgreen")
```

![plot of chunk p0](http://farm8.staticflickr.com/7047/6983802282_7bceb5cd87_o.png)
![plot of chunk p0](http://farm9.staticflickr.com/8015/7178088946_4ab62a1ed1_o.png)



Expand All @@ -224,10 +224,27 @@ This plot summarizes the stock dynamics by visualizing the replicates. Reed's S
```r
p1 <- ggplot(dt) + geom_abline(intercept=opt$S, slope = 0) +
geom_abline(intercept=xT, slope = 0, lty=2)
```



```
Error: object 'xT' not found
```



```r
p1 + geom_line(aes(time, fishstock, group = reps), alpha = 0.2)
```

![plot of chunk p1](http://farm8.staticflickr.com/7193/7129886257_51bb453c13_o.png)


```
Error: object 'p1' not found
```




We can also look at the harvest dynamics:
Expand All @@ -238,7 +255,13 @@ We can also look at the harvest dynamics:
p1 + geom_line(aes(time, harvest, group = reps), alpha = 0.1, col="darkgreen")
```

![plot of chunk p2](http://farm9.staticflickr.com/8167/6983803634_7699492b79_o.png)


```
Error: object 'p1' not found
```




This strategy is supposed to be a constant-escapement strategy. We can visualize the escapement:
Expand All @@ -249,7 +272,13 @@ This strategy is supposed to be a constant-escapement strategy. We can visualize
p1 + geom_line(aes(time, escapement, group = reps), alpha = 0.1, col="darkgrey")
```

![plot of chunk p3](http://farm8.staticflickr.com/7050/7129887427_4f690c5d65_o.png)


```
Error: object 'p1' not found
```





Expand All @@ -272,10 +301,27 @@ p5 <- ggplot(policy_zoom) +
scale_colour_gradientn(colours = rainbow(4)) +
geom_abline(intercept=opt$S, slope = 0) +
geom_abline(intercept=xT, slope=0, lty=2)
```



```
Error: object 'xT' not found
```



```r
p5
```

![plot of chunk policy](http://farm8.staticflickr.com/7188/7129887821_5430106a9f_o.png)


```
Error: object 'p5' not found
```




The harvest intensity is limited by the stock size.
Expand All @@ -290,9 +336,26 @@ p6 <- ggplot(policy_zoom) +
scale_colour_gradientn(colours = rainbow(4)) +
geom_abline(intercept=opt$S, slope = 0) +
geom_abline(intercept=xT, slope=0, lty=2)
```



```
Error: object 'xT' not found
```



```r
p6 + geom_line(aes(time, fishstock, group = reps), alpha = 0.1, data=dt)
```

![plot of chunk policy2](http://farm8.staticflickr.com/7108/7129888199_255a56ecb2_o.png)


```
Error: object 'p6' not found
```




2 changes: 1 addition & 1 deletion inst/examples/Reed_knit_.md
@@ -1,4 +1,4 @@
`ro cache=TRUE, tidy=FALSE, warning=FALSE, comment=NA, message=FALSE, refresh=1 or`
`ro cache=TRUE, tidy=FALSE, warning=FALSE, comment=NA, message=FALSE, refresh=2 or`

``` {r echo=FALSE }
opts_knit$set(upload.fun = socialR::flickr.url)
Expand Down

0 comments on commit e5d913b

Please sign in to comment.