Deming
facilitates a non-parametric check of neuromodulation.
This class is a wrapper around a cmdstanr::CmdStanModel
class.
cmdstanr_version
Version of cmdstanr used to build models
cmdstan_version
Version of cmdstan used to build models
standata
used to fit model
prior
used to fit model
cmdstanmodel
Underlying cmdstanr::CmdStanModel
new()
Initialize new instance of class Deming
Deming$new(d, x, y, tuning_var, voxel_var = "voxel", prior = DemingPrior$new())
d
dataframe from which to make standata.
x, y
Names of columns in d which contain the x and y values
tuning_var
Name of column across which there was testing
voxel_var
Name of column indexing voxels
prior
m <- sub02 %>% tidyr::pivot_wider(names_from = contrast, values_from = y) %>% dplyr::mutate(orientation = factor(orientation)) %>% Deming$new(low, high, tuning_var = orientation, voxel_var = voxel) m m$cmdstanmodel
make_standata()
Prepare data for running model
Deming$make_standata(d, x, y, tuning_var, voxel_var = "voxel")
d
dataframe from which to make standata.
x, y
Names of columns in d which contain the x and y values.
tuning_var
Name of column across which there was testing. Column must be a factor.
voxel_var
Name of column indexing voxels. Column must be a factor.
named list
sample()
Draw samples from the posterior of the model
Deming$sample(...)
...
arguments passed to cmdstanr::sample().
An object of class cmdstanr::CmdStanMCMC
clone()
The objects of this class are cloneable with this method.
Deming$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `Deming$new` ## ------------------------------------------------ m <- sub02 %>% tidyr::pivot_wider(names_from = contrast, values_from = y) %>% dplyr::mutate(orientation = factor(orientation)) %>% Deming$new(low, high, tuning_var = orientation, voxel_var = voxel) m#> <Deming> #> Public: #> clone: function (deep = FALSE) #> cmdstan_version: 2.26.1 #> cmdstanmodel: active binding #> cmdstanr_version: package_version, numeric_version #> initialize: function (d, x, y, tuning_var, voxel_var = "voxel", prior = DemingPrior$new()) #> make_standata: function (d, x, y, tuning_var, voxel_var = "voxel") #> prior: active binding #> sample: function (...) #> standata: active binding #> Private: #> .cmdstanmodel: CmdStanModel, R6 #> .prior: DemingPrior, R6 #> .standata: list #> .write_file: function ()m$cmdstanmodel#> data { #> int<lower=1> n; // total number of observations #> int n_voxel; #> int<lower=1, upper=n_voxel> voxel[n]; #> int n_tuning; #> int<lower=1, upper=n_tuning> tuning[n]; #> int<lower=1, upper=n_tuning*n_voxel> voxel_tuning[n]; // index to pick out from matrix of tuning x voxel #> vector[n] y; // response variable (high) #> vector[n] x; // noisy values (low) #> #> // priors #> vector[2] prior_z_mu_mu; #> vector[2] prior_z_mu_sigma; #> vector[2] prior_z_sigma_mu; #> vector[2] prior_z_sigma_sigma; #> vector[2] prior_x_sigma_mu; #> vector[2] prior_x_sigma_sigma; #> vector[2] prior_y_sigma_mu; #> vector[2] prior_y_sigma_sigma; #> vector[2] prior_g_mu; #> vector[2] prior_g_sigma; #> vector[2] prior_a_mu; #> vector[2] prior_a_sigma; #> } #> parameters { #> real<lower=0> g_sigma; #> real g_mu; #> vector<multiplier=g_sigma, offset=g_mu>[n_voxel] g; #> real<lower=0> a_sigma; #> real a_mu; #> vector<multiplier=a_sigma, offset=a_mu>[n_voxel] a; #> real<lower=0> z_mu_sigma; #> real z_mu_mu; #> row_vector[n_voxel] z_mu; #> matrix[n_tuning, n_voxel] z_raw; #> real<lower=0> z_sigma_sigma; #> real<lower=0> z_sigma_mu; #> vector<lower=-z_sigma_mu/z_sigma_sigma>[n_voxel] z_sigma_raw; #> real<lower=0> x_sigma_sigma; #> real<lower=0> x_sigma_mu; #> vector<lower=0>[n_voxel] x_sigma; #> real<lower=0> y_sigma_sigma; #> real<lower=0> y_sigma_mu; #> vector<lower=0>[n_voxel] y_sigma; #> } #> transformed parameters{ #> vector[n_tuning*n_voxel] zeta; #> #> { #> matrix[n_tuning, n_voxel] z; #> vector[n_voxel] z_sigma = z_sigma_mu + z_sigma_raw * z_sigma_sigma; #> for (v in 1:n_voxel) z[,v] = z_sigma[v] * z_raw[,v] + z_mu[v]; #> zeta = to_vector(z); #> } #> #> } #> model { #> z_mu_mu ~ normal(prior_z_mu_mu[1], prior_z_mu_mu[2]); #> z_mu_sigma ~ normal(prior_z_mu_sigma[1], prior_z_mu_sigma[2]); #> z_mu ~ normal(z_mu_mu, z_mu_sigma); #> #> to_vector(z_raw) ~ std_normal(); #> #> z_sigma_mu ~ normal(prior_z_sigma_mu[1], prior_z_sigma_mu[2]); #> z_sigma_sigma ~ normal(prior_z_sigma_sigma[1], prior_z_sigma_sigma[2]); #> z_sigma_raw ~ std_normal(); #> target += -normal_lccdf(-z_sigma_mu/z_sigma_sigma | 0, 1)*n_voxel; #> #> x_sigma_mu ~ normal(prior_x_sigma_mu[1], prior_x_sigma_mu[2]); #> x_sigma_sigma ~ normal(prior_x_sigma_sigma[1], prior_x_sigma_sigma[2]); #> x_sigma ~ normal(x_sigma_mu, x_sigma_sigma); #> target += -normal_lccdf(0 | x_sigma_mu, x_sigma_sigma) * n_voxel; #> #> y_sigma_mu ~ normal(prior_y_sigma_mu[1], prior_y_sigma_mu[2]); #> y_sigma_sigma ~ normal(prior_y_sigma_sigma[1], prior_y_sigma_sigma[2]); #> y_sigma ~ normal(y_sigma_mu, y_sigma_sigma); #> target += -normal_lccdf(0 | y_sigma_mu, y_sigma_sigma) * n_voxel; #> #> g_mu ~ normal(prior_g_mu[1], prior_g_mu[2]); #> g_sigma ~ normal(prior_g_sigma[1], prior_g_sigma[2]); #> g ~ normal(g_mu, g_sigma); #> #> a_mu ~ normal(prior_a_mu[1], prior_a_mu[2]); #> a_sigma ~ normal(prior_a_sigma[1], prior_a_sigma[2]); #> a ~ normal(a_mu, a_sigma); #> #> // likelihood #> x ~ normal(zeta[voxel_tuning], x_sigma[voxel]); #> y ~ normal(a[voxel] + zeta[voxel_tuning] .* g[voxel], y_sigma[voxel]); #> }