R

Steps for \(i=1,2,\dots,n\) Sample candidate value \(x^i\) from a proposal distribution \(q(x^i|x^{i-1})\) Compute acceptance probability: \[\alpha=\frac{p(x^i)q(x^{i-1}|x^i)}{p(x^{i-1})q(x^i|x^{i-1})}\] 3. Compute \(r=min(1,\alpha)\) Sample \(U\sim Unif(0,1)\) \[ x^i=\begin{cases} x^{i-1}, &u<r \\x^i, &u\geq r\end{cases} \] An example
2022-01-07
1 min read
In practice, we always find the function in a published R package can not meet our needs very well. However, it’s not necessary to write a new function all over. It would be more convenient if we can modify the function directly. Let’s look at an example. We check the source code of sd() function in the stats package. The source code is as following: library(stats) sd function (x, na.rm = FALSE) sqrt(var(if (is.
2021-05-10
1 min read
R
R code for bootstrap and permutation test.
2021-04-17
1 min read