Skip to content

Instantly share code, notes, and snippets.

@djhocking
Created January 7, 2015 04:20
Show Gist options
  • Save djhocking/4f28ef6ebf751a2d6758 to your computer and use it in GitHub Desktop.
Save djhocking/4f28ef6ebf751a2d6758 to your computer and use it in GitHub Desktop.
First example of using Markdown with LaTeX equations
We assumed stream temperature measurements were normally distributed following,
\\[ t_{s,h,d,y} \sim \mathcal{N}(\mu_{s,h,d,y}, \sigma) \\]
where $t_{s,h,d,y}$ is the observed stream water temperature at the site ($s$) within the sub-basin identified by the 8-digit Hydrologic Unit Code (HUC8; $h$) for each day ($d$) in each year ($y$). We describe the normal distribution with the standard deviation ($\sigma$). The expected temperature follows a linear trend
\\[ \omega_{s,h,d,y} = X^0 B^0 + X_{h}^{huc} B_{h}^{huc} + X_{s,h}^{site} B_{s,h}^{site} + X_{y}^{year} B_{y}^{year} \\]
but the expected temperature ($\mu_{s,h,d,y}$) is adjusted based on the residual error from the previous day
\\[ \mu_{s,h,d,y} = \left\{
\begin{array}{1 1}
\omega_{s,h,d,y} + \delta_{s}(t_{s,h,d-1,y} - \omega_{s,h,d-1,y}) & \quad \text{for $t_{s,h,d-1,y}$ is real} \\
\omega_{s,h,d,y} & \quad \text{for $t_{s,h,d-1,y}$ is not real}
\end{array} \right.
\\]
where $\delta_{s}$ is an autoregressive [AR(1)] coefficient that varies randomly by site and $\omega_{s,h,d,y}$ is the expected temperature before accounting for temporal autocorrelation in the error structure.
$X_{d}^0$ is the $n \times K_0$ matrix of predictor values. $B^0$ is the vector of $K_0$ coefficients, where $K_0$ is the number of fixed effects parameters including the overall intercept. $B^0$ is distributed as
\\[ B^0 \sim \mathcal{N}(0,\sigma_{k_0}), \text{for $k_0 = 1,...,K_0$,} \\]
We used 10 fixed effect parameters including the overall intercept. These include latitude, longitude, upstream drainage area, percent forest cover, elevation, surficial coarseness classification, percent wetland area, upstream impounded area, and an interaction of drainage area and air temperature. We describe how we derived each of the parameters below.
The effects of air temperature on the day of observation ($d$) and mean air temperature over the previous 5 days varied randomly with site nested within HUC8, as did precipitation, the previous 30-day precipitation mean, and the interactions of air temperature and preciptation (all 4 combinations).
$B_{s,h}^{site}$ is the $S \times K_{S}$ matrix of regression coefficients where $S$ is the number of unique sites and $K_{S}$ is the number of regression coeffcients that vary randomly by site within HUC8.
$X_{h}^{huc}$ is the matrix of parameters that vary by HUC8. We allowed for correlation among the effects of these HUC8 coefficients such that
\\[ B_{h}^{huc} \sim \mathcal{N}(M_{h},\Sigma_{B_{h}}), \text{for $h = 1,...,H$} \\]
as described by Gelman and Hill [-@Gelman2007], where $H$ is the number of HUC8 groups and $K_h$ is the number of paramaters that vary by HUC8 including a constant term. $B_{h}^{huc}$ is the $H \times K_{H}$ matrix of coefficients and $M_{h}$ is a vector of length $K_{h}$. In our model, $K_{h}$ = $K_{S}$. \Sigma_{B_{h}} is the $K_{h} \times K_{h}$ covariance matrix.
Similarly, we allowed the some effects of some parameters ($X_{y}^{year}$) to vary randomly by year with potential correlation among the coefficients
\\[ B_{y}^{year} \sim \mathcal{N}(M_{h},\Sigma_{B_{y}}), \text{for $y = 1,...,Y$} \\]
The intercept, day of the year ($day$), $day^2$, and $day^3$ all varied randomly with year so that $K_{y} = 4$. \Sigma_{B_{y}} represents the $K_{y} \times K_{y}$ covariance matrix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment