# Normal linear regression with known variance via rstanarm

Hi Stan/rstanarm Users,

I am new to the overall Stan environment and still trying to learn it’s many subtleties. One simple problem I am trying to solve is normal linear regression where I have a known diagonal covariance matrix that isn’t the identity matrix. Using the standard `LM` template, this would be

``````model.lm <- lm(formula = Y ~ X, data=d, weights=W)
``````

where the weights `W` are the precision estimates of the dependent variable `Y` at each `X` point. Since the syntax is very similar, the R code below was my guess as to what it should be in rstanarm.

``````model.rstanarm <- stan_glm(
formula = Y ~ X, data=d, weights=W,
family = gaussian(),
prior=priors.slope, prior_intercept=priors.int
)
``````

Is this correct or should I be using the `prior.aux` variable in `stan_glm()` to specify my knowledge about the covariance matrix rather than weights?

Since nobody replied, I will give it a try. Please check me twice, this is not my area of expertise.

I am not completely sure weights in `rstanaram` would accomplish exactly this. A good way to check is to simulate a small dataset with the given covaraince matrix and see if that works :-)

Also `brms` (which is also formula-based stan interface) has the feature to specify the standard error of your observations instead of fitting (which might be what you are actually after, but is AFAIK different than weights as the model has fewer parameters) with something like

``````d\$sd <- 1/W
brm(Y | se(sd) ~ X)
``````

See the section on “Additional response information” at https://rdrr.io/cran/brms/man/brmsformula.html for more detail.