Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Rstudio - stan question! The data I have is Can someone help me writing

ID: 3729512 • Letter: T

Question

This is Rstudio - stan question!

The data I have is

Can someone help me writing stan model for this data set, and generate prior sampling ???

x1 x2 y 6.248172154 6.413018119 27.72807173 0.54703115 6.056001452 22.44002569 6.281978793 8.862859786 33.68782804 0.508492752 4.933395644 22.53121003 2.824082461 2.276334735 17.63636167 4.750213944 7.117214578 25.87253408 5.143914712 5.887609066 25.98171722 5.71135357 3.691281418 25.55650022 8.359403685 7.814751931 32.54884238 2.352218286 0.990475598 11.50362995 4.42239817 3.904418189 22.49111019 6.120472953 2.42620792 18.5724994 6.8200059 5.912395045 28.5100516 1.260275587 1.465872233 15.14436334 5.358677122 3.262856484 23.64729322 4.986722854 3.357216995 20.83595183 8.017413809 7.136779611 31.62212518 3.137353186 0.893726663 13.33961344 7.115391979 7.88339365 34.52448643

Explanation / Answer

R code for stan model:
data {
int<lower=0> J;   
real y[J];
real<lower=0> sigma[J];  
}
parameters {
real mu;
real<lower=0> tau;
vector[J] eta;
}
transformed parameters {
vector[J] theta;
theta = mu + tau * eta;
}
model {
target += normal_lpdf(eta | 0, 1);
target += normal_lpdf(y | theta, sigma);
}

The first section of the Stan program above, the data block, specifies the data that is conditioned upon in Bayes Rule, J the vector of estimates, (y1,…,yJ), and the vector of standard errors of the estimates (1,…,J). Data are declared as integer or real and can be vectors (or, more generally, arrays) if dimensions are specified. Data can also be constrained; for example, in the above model J has been restricted to be at least 1 and the components of y must all be positive.
The parameters block declares the parameters whose posterior distribution is sought.
Finally, the model block looks similar to standard statistical notation.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote