This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Written by Chris Brown at Griffith Uni | |
| #Tips for setting up R packages on windows 10 | |
| I recommend installing packages to your local drive, not the shared network drive. Though R will default to the network drive (which is "\\\\staff\..."), so some knowledge is required to overcome this. | |
| You could also ask IT to bind a letter to your network drive. I've read that works (see here: https://github.com/r-lib/devtools/issues/353) | |
| Here's the steps I followed to install packages: | |
| Create a shortcut to R on desktop. | |
| Right click it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(INLA) | |
| nprec <- 100000 | |
| prec <- seq(0.05, 1000, length.out = nprec) #precisions | |
| sd <- 1/sqrt(prec) | |
| U <- 1 | |
| alpha <- 0.025 | |
| lambda <- -log(alpha)/U #rate for exponential on sd | |
| pr_prec <- inla.pc.dprec(prec, U, alpha) #Density for the precision. | |
| pr_sd <- dexp(sd, rate = lambda) #Density for sd | |
| #nb see inla.pc.dprec for how to get density for the precision. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Semivariance function for over water distance | |
| semivariance <- function(xdists, yresp, ncats = NA){ | |
| #Function to calculate semivariance using a distance matrix | |
| # | |
| #Where: | |
| #xdists is the distance matrix | |
| #yresp is the response and rows of yresp correspond to sites in rows and columns of dists | |
| #ncats is the resolution. Defaults to sturges rule for histogram classes (as per Legendre book) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Visualise priors for a variance component selected using the method of Fong et al. 2010 (see page 400 of that paper) | |
| R <- log(10) #+-range. Use log for GLMs that have log-link functions(e.g. poisson) or no logs for a gaussian model with identity link | |
| d <- 1 #Degrees of freedom for student t | |
| quant <-0.95 #quantile you want random effect estimates to vary between | |
| #Parameters of Gamma | |
| a1 <- d/2 | |
| qtemp <- 1-(1-quant)/2 | |
| a2 <- (d/2) * (R^2)/(qt(qtemp, df = 1)^2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Simulate data | |
| # | |
| a <- 2 | |
| x <- seq(0, 1, length.out = 100) | |
| n <- length(x) | |
| sigma <- 0.5 | |
| set.seed(42) | |
| lny <- rnorm(n, mean = a*x, sd = sigma) | |
| y <- exp(lny) |
NewerOlder