Skip to content

Commit

Permalink
updated build pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
morrowcj committed Jan 21, 2023
1 parent 5068e7d commit 1a4f466
Show file tree
Hide file tree
Showing 8 changed files with 564 additions and 498 deletions.
8 changes: 8 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ data/ndvi_AK3000\.rda
cran-comments\.md

README\.html

# build pipeline
build.R
render_vignette.R
check_pkg.R
build_pipeline.R
builds/
figure/
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ data-raw
/Meta/

README.html

# built versions of the package
builds/
figure/
3 changes: 3 additions & 0 deletions build.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rcpp::compileAttributes()
devtools::document()
devtools::build(path = "builds")
3 changes: 3 additions & 0 deletions build_pipeline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source("check_pkg.R")
source("build.R")
source("render_vignette.R")
3 changes: 3 additions & 0 deletions check_pkg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rcpp::compileAttributes()
devtools::document()
devtools::check()
1,015 changes: 531 additions & 484 deletions docs/Alaska.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions render_vignette.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
rmarkdown::render(input = "vignettes/Alaska.Rmd",
output_format = "html_document",
output_file = "Alaska.html",
output_dir = "docs/")
22 changes: 8 additions & 14 deletions vignettes/Alaska.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ this covariance function.
```{r visualize_range, fig.asp = 1, fig.width = 4.5, include = FALSE}
curve(covar_exp(x, r = .1), xlab = "distance", ylab = "covar_exp(d, r)")
curve(covar_exp(x, r = .2), add = TRUE, col = "red")
legend("topright", legend = c("0.1", "0.2"), title = "r",
col = c("black", "red"), lty = 1)
legend("topright", legend = c("0.1", "0.2"), title = "r", col = c("black", "red"), lty = 1)
```

`V` represents the correlation among points if all variation is accounted for.
Expand All @@ -267,8 +266,7 @@ $I$ is the identity matrix.
nugget <- .3
curve(covar_exp(x, r = .1), xlab = "distance", ylab = "covar_exp(d, r)")
curve((1-nugget)*covar_exp(x, r = .1), add = TRUE, col = "red")
legend("topright", legend = c(0, .2), title = expression(eta),
col = c("black", "red"), lty = 1)
legend("topright", legend = c(0, .2), title = expression(eta), col = c("black", "red"), lty = 1)
```

If we know the range parameter $r$, we can calculate `V` from `D` with `covar_exp()`:
Expand Down Expand Up @@ -381,9 +379,8 @@ at 0.1. For this example, we will also specify `fit.n = 3000`, which ensures
that all pixels are used to estimate spatial parameters.

```{r fit_range_parameter}
corfit <- fitCor(resids = residuals(ARfit), coords = coords,
covar_FUN = "covar_exp", start = list(range = 0.1),
fit.n = 3000)
corfit <- fitCor(resids = residuals(ARfit), coords = coords, covar_FUN = "covar_exp",
start = list(range = 0.1), fit.n = 3000)
(range.opt = corfit$spcor)
```

Expand All @@ -397,9 +394,8 @@ map:

```{r fit_range_km, eval = FALSE}
max.dist <- max(distm_km(coords))
corfit.km <- fitCor(resids = residuals(ARfit), coords = coords,
covar_FUN = "covar_exp", start = list(range = max.dist*0.1),
distm_FUN = "distm_km", fit.n = 3000)
corfit.km <- fitCor(resids = residuals(ARfit), coords = coords, covar_FUN = "covar_exp",
start = list(range = max.dist*0.1), distm_FUN = "distm_km", fit.n = 3000)
```

Note that, depending on the covariance function used, not all parameters will
Expand Down Expand Up @@ -428,8 +424,7 @@ so that F-tests are calculated. For the F-tests, the default reduced model is th
it is also possible to specify alternative reduced models as a formula in the `formula0` option.

```{r optimized_nugget}
GLS.opt <- fitGLS(formula = AR_coef ~ 0 + land, data = ndvi_AK3000, V = V.opt, nugget = NA,
no.F = FALSE)
GLS.opt <- fitGLS(formula = AR_coef ~ 0 + land, data = ndvi_AK3000, V = V.opt, nugget = NA, no.F = FALSE)
(nug.opt = GLS.opt$nugget)
coefficients(GLS.opt)
```
Expand Down Expand Up @@ -528,8 +523,7 @@ Finally, to test the hypothesis that "temporal trends in NDVI differ with
latitude", we can regress the AR coefficient on latitude in our GLS model:

```{r fit_GLS_latitude}
(GLS.lat <- fitGLS(AR_coef ~ 1 + lat, data = ndvi_AK3000, V = V.opt, nugget = nug.opt,
no.F = FALSE))
(GLS.lat <- fitGLS(AR_coef ~ 1 + lat, data = ndvi_AK3000, V = V.opt, nugget = nug.opt, no.F = FALSE))
```

The t-tests show that temporal trends in NDVI did not differ with latitude.
Expand Down

0 comments on commit 1a4f466

Please sign in to comment.