Cross Validated Asked by student_R123 on September 7, 2020

I have fitted following Bayesian linear regression model using **rjags** package in **R**, with the help of cars data set.

I used some weakly informative priors for parameters.

```
require(rjags)
dim(cars)
N=length(cars$speed)
bayes_model="model {
for(i in 1:N){
dist[i] ~ dnorm(mu[i],tau)
mu[i] = beta[1] + beta[2]*speed[i]
}
for (l in 1:2) { beta[l] ~dnorm(0, 100) }
tau ~ dgamma(.001,.001)
sigma_tau = 1/tau
}"
model2 <- jags.model(textConnection(bayes_model),
data = list(dist=cars$dist,N=N,speed=cars$speed),
n.chains=2)
params <- c('beta','sigma_tau')
samps.1 <- coda.samples(model2, params, n.iter = 2000)
burn.in=1000
summary.model.1=summary(window(samps.1, start = burn.in))
Stat.model.1=as.data.frame(summary.model.1$statistics)
```

This is how the results looks like .

```
> Stat.model.1
Mean SD Naive SE Time-series SE
beta[1] 9.937366e-03 0.09806290 0.002191658 0.002238168
beta[2] 1.650041e-01 0.09903592 0.002213404 0.002330977
sigma_tau 2.341437e+03 522.81381343 11.684631408 11.700676273
```

When I fit a classical linear regression model , following results are obtained .

```
summary(lm(dist~speed ,data=cars))
Call:
lm(formula = dist ~ speed, data = cars)
Residuals:
Min 1Q Median 3Q Max
-29.069 -9.525 -2.272 9.215 43.201
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -17.5791 6.7584 -2.601 0.0123 *
speed 3.9324 0.4155 9.464 1.49e-12 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared: 0.6511, Adjusted R-squared: 0.6438
F-statistic: 89.57 on 1 and 48 DF, p-value: 1.49e-12
```

It can be observed that the results based on Bayesian and classical method is not similar. What may be the reason for this ? Is there any problem with my prior distributions ?

Are there any diagnostic plots that should look into ? Also please feel free to let me know if I have missed any important steps in this analysis.

I am relatively new to Bayesian and I am working with different sort of examples to learn how to assign correct prior distributions.

Try:

```
bayes_model="model {
for(i in 1:N){
dist[i] ~ dnorm(mu[i],tau)
mu[i] = beta[1] + beta[2]*speed[i]
}
for (l in 1:2) { beta[l] ~dnorm(0, 0.001) }
tau ~ dgamma(.01,.01)
sigma_tau = 1/tau
}"
```

You'll get something like:

```
> Stat.model.1
Mean SD Naive SE Time-series SE
beta[1] -16.88098 6.2008860 0.138586750 0.53168398
beta[2] 3.89631 0.3812761 0.008521332 0.03262728
sigma_tau 244.69856 53.4120568 1.193733180 1.25568735
```

Why? Because in JAGS the parameters of the normal distribution are mean $mu$ and precision $tau$, and $tau=sigma^{-2}$, so

beta[l] ~ dnorm(0, 100)is a very strong, not a weakly informative prior, it forces

`beta[l]`

to be as close to zero as possible.
Correct answer by Sergio on September 7, 2020

1 Asked on January 4, 2021 by new

hypothesis testing manova proportion self study statistical significance

1 Asked on January 3, 2021 by jarek-duda

1 Asked on January 3, 2021

0 Asked on January 3, 2021

1 Asked on January 2, 2021 by wasif

1 Asked on January 2, 2021 by aishwarya-a-r

1 Asked on January 2, 2021 by mark-f

attention computer vision loss functions neural networks unsupervised learning

0 Asked on January 2, 2021 by jonasc

0 Asked on January 2, 2021

1 Asked on January 1, 2021 by ambleu

1 Asked on January 1, 2021

clustered standard errors descriptive statistics error error propagation machine learning

1 Asked on December 31, 2020 by mvharen

0 Asked on December 31, 2020 by rik

3 Asked on December 31, 2020 by wishihadabettername

1 Asked on December 31, 2020 by helmut

bayesian conjugate prior hierarchical bayesian poisson distribution

3 Asked on December 30, 2020

2 Asked on December 30, 2020 by joanne-cheung

0 Asked on December 30, 2020 by woodpigeon

1 Asked on December 30, 2020 by prinzvonk

Get help from others!

Recent Answers

- haakon.io on Why fry rice before boiling?
- Jon Church on Why fry rice before boiling?
- Lex on Does Google Analytics track 404 page responses as valid page views?
- Peter Machado on Why fry rice before boiling?
- Joshua Engel on Why fry rice before boiling?

Recent Questions

- How Do I Get The Ifruit App Off Of Gta 5 / Grand Theft Auto 5
- Iv’e designed a space elevator using a series of lasers. do you know anybody i could submit the designs too that could manufacture the concept and put it to use
- Need help finding a book. Female OP protagonist, magic
- Why is the WWF pending games (“Your turn”) area replaced w/ a column of “Bonus & Reward”gift boxes?
- Does Google Analytics track 404 page responses as valid page views?

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP