1
データに多項式のマージンを当てはめる方法を教えてもらえますか?私は二項と二項の二項演算をしましたが、私は多項式をどのように適合させるかを見たいと思います。私はそれがあなたがする方法を知っている何かあれば、ガンマを試みることにも興味があります。ヒストグラムへのマージナル分布の例R
これまで私が行ってきたことです。ここで
nodes <- read.table("https://web.stanford.edu/~hastie/CASI_files/DATA/nodes.txt",
header = T)
nodes %>%
ggplot(aes(x=x/n))+
geom_histogram(bins = 30)+
theme_bw()+
labs(x = "nodes",
n = "p=x/n")
# log-likelihood function
ll <- function(alpha, beta) {
x <- nodes$x
total <- nodes$n
-sum(VGAM::dbetabinom.ab(x, total, alpha, beta, log = TRUE))
}
# maximum likelihood estimation
m <- mle(ll, start = list(alpha = 1, beta = 10), method = "L-BFGS-B",
lower = c(0.0001, .1))
ab <- coef(m)
alpha0 <- ab[1]
beta0 <- ab[2]
nodes %>%
ggplot() +
geom_histogram(aes(x/n, y = ..density..), bins= 30) +
stat_function(fun = function(x) dbeta(x, alpha0, beta0), color = "red",
size = 1) +
xlab("p=x/n")
ガンマ分布を装着するための別のフィット
ll <- function(a){
x <- nodes$x
total <- nodes$n
-sum(stats::dbinom(x, total, a, log = TRUE))
}
#stats::dbinom()
m <- mle(ll, start = list(a=.5), method = "L-BFGS-B",
lower = c(0.0001, .1))
a = coef(m)
nodes %>%
ggplot() +
geom_histogram(aes(x/n, y = ..density..), bins=40) +
stat_function(fun = function(x) dbeta(x, a, 1), color = "red",
size = 1) +
xlab("proportion x/n")
カスタム多項式はどのようにフィットしますか? fitdistrはそれを許しますか? – Alex
ここであなたの目標が何であるかをもう少し説明できますか?私はちょうどヒストグラムにカスタム多項式を当てはめたことは聞いたことがありません。カスタム多項式回帰に適合させたい場合は、lm()関数を使用できます。 – Jay
はい、私は前の投稿からプロットを複製しようとしていますが、私はまだそれを行う方法がわかりません。https://stackoverflow.com/questions/45290265/reproduce-a-prior-density-plot-in -r – Alex