I have a lot of data, like the image below, which have a relationship with each other. I want to make an equation to describe this relationship, something like Power = a * WindSpeed ^ b
. How can I use Bayesian Inference to find a and b? I want to use R for this.
Asked
Active
Viewed 205 times
-4
-
1Welcome to SO. Please take some time familiarising yourself with [how to ask](https://stackoverflow.com/help/how-to-ask) questions here on SO. SO is about *specific* coding questions/issues and in order for us to be able to help, you will need to significantly improve the quality of your post by providing (1) representative & minimal sample data, (2) a code attempt and (3) a clear and answerable problem statement. At the moment your question is too broad and therefore not only difficult to answer but also [off-topic](https://stackoverflow.com/help/on-topic). – Maurits Evers Aug 29 '18 at 10:22
-
1There are *many* resources available on the net that provide introductions to Bayesian inference/modelling in R. I suggest you start there, and when you get stuck with a specific problem come back with a post detailing your efforts. – Maurits Evers Aug 29 '18 at 10:24
1 Answers
1
Welcome to SO and good luck. Do not forget to pay attention to the comment (they are really relevant & you can increase probability to get an answer).
Please see below example of using Bayesian univariate regression using Bolstadt
package.
library(Bolstad)
# Simulation of Power vs Wind
# Power = 5 * Windspeed ^ 2
set.seed(123)
n <- 100
# y = Power
# x = WindSpeed
# e = error term
x <- (1:(25 * n))/ n
e <- rnorm(length(x)) / 10
# y = a * x ^ b
# log(y) = log(a) + b * log(x) + e
# or
# in exponential form
y <- exp(log(5) + e) * x ^ 2
# bayes univariate linear regression model
z <- bayes.lin.reg(log(y), log(x))
# Standard deviation of residuals: 0.0943
# Posterior Mean Posterior Std. Deviation
# -------------- ------------------------
# Intercept: 6.076 0.0059657
# Slope: 1.996 0.0062209
# ------------------------------------------------
# pay attention the result of bayession regression
# are shifted for intercept by the mean
# is is accouted as below
intercept_shifted <- z$intercept$mean - z$slope$mean * mean(log(x))
intercept_shifted
# [1] 1.617218
# validate by standar linear model:
lm(log(y) ~ log(x))
# Coefficients:
# (Intercept) log(x)
# 1.617 1.996
a = exp(intercept_shifted)
a
# [1] 5.039051
b = z$slope$mean
b
# [1] 1.996134

Artem
- 3,304
- 3
- 18
- 41