Posts by R-bloggers | A Random Walk
Author: R-bloggers | A Random Walk
Mesmerizing multi-scale Turing patterns in R with Rcpp
Feed: R-bloggers. Author: R-bloggers | A Random Walk. Turing patterns are a type of reaction-diffusion systems that have attracted much interest as a basic model for the formation of patterns in nature, such as stripes, spots and spirals. The behavior of such diffusion systems was studied by Alan Turing in his classical paper (Turing 1952) and a few decades later re-discovered by (Gierer and Meinhardt 1972), which lead to a more widespread use of the systems in biology as well as other fields. Turing-like patterns involve activating and inhibiting substances that diffuse through a tissue. If the activator substance diffuses ... Read More
Automatic differentiation in R with Stan Math
Feed: R-bloggers. Author: R-bloggers | A Random Walk. Automatic differentiation in R with Stan Math | R-bloggers .grad[, "A"] .grad[, "lam"] .grad[, "b"] attr(.value, "gradient") .value #> } Since we specified the function.arg argument, deriv() returns a function –instead of an expression– that can be used directly to evaluate both the function values and the gradient (or Jacobian) for different values of the independent variable and parameters. Inspecting the body of the returned function, we see that the expression in the "gradient" attribute corresponds exactly to the manually derived gradient. ## evaluate function + jacobian fdot(x = (1:10) / 10, ... Read More
GSL nonlinear least squares fitting in R
Feed: R-bloggers. Author: R-bloggers | A Random Walk. GSL nonlinear least squares fitting in R | R-bloggers model: y ~ b1/(1 + exp(b2 - b3 * x)) #> data: Ratkowsky2 #> b1 b2 b3 #> 72.46224 2.61808 0.06736 #> residual sum-of-squares: 8.057 #> #> Algorithm: levenberg-marquardt, (scaling: more, solver: qr) #> #> Number of iterations to convergence: 10 #> Achieved convergence tolerance: 4.619e-14 The gsl_nls() function returns an object that inherits from the class "nls". For this reason, all generic functions available for "nls"-objects are also applicable to objects returned by gsl_nls(). For instance, ## model fit summary summary(rat42_gsl) #> ... Read More
Step function regression in Stan
Feed: R-bloggers. Author: R-bloggers | A Random Walk. Tha aim of this post is to provide a working approach to perform piecewise constant or step function regression in Stan. To set up the regression problem, consider noisy observations (y_1, ldots, y_n in mathbb{R}) sampled from a standard signal plus i.i.d. Gaussian noise model of the form: [ begin{aligned} y_i & = f(x_i) + epsilon_i, quad i = 1,ldots, n \ epsilon_i & overset{text{iid}}{sim} N(0, sigma^2) end{aligned} ] with the independent variables (x_1,ldots, x_n in (0, 1]) assumed to be observed at regular (e.g. time) intervals. The function (f: (0,1] to mathbb{R}) ... Read More
Recent Comments