How to do it...

In the following example, we will fit a linear regression model to our house price dataset. The objective is to model the house prices in terms of several variables, such as the size of the property, the number of bathrooms, the number of bedrooms, the number of entrances, the size of the balcony, and the size of the house entrance. In this example, we won't be very specific about the priors, but we do know that all these variables should have a positive impact. One natural possibility is to use a gamma() distribution, which is naturally bounded by zero:

  1. We first load STAN and the data as follows:
library(rstan)data = read.csv("./house_prices.csv")
  1. We then create our STAN model. This has the following three parts:
    • The ...

Get R Statistics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.