使用贝叶斯推理寻找变量之间的关系
Use bayesian inference to find relationship between variables
我有很多数据,如下图,它们之间有关系。我想做一个方程来描述这种关系,比如 Power = a * WindSpeed ^ b
。如何使用贝叶斯推理找到 a 和 b?我想为此使用 R。
欢迎来到 SO,祝你好运。不要忘记关注评论(它们真的很相关,你可以增加获得答案的可能性)。
请参阅下面使用 Bolstadt
包使用贝叶斯单变量回归的示例。
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
我有很多数据,如下图,它们之间有关系。我想做一个方程来描述这种关系,比如 Power = a * WindSpeed ^ b
。如何使用贝叶斯推理找到 a 和 b?我想为此使用 R。
欢迎来到 SO,祝你好运。不要忘记关注评论(它们真的很相关,你可以增加获得答案的可能性)。
请参阅下面使用 Bolstadt
包使用贝叶斯单变量回归的示例。
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