【发布时间】:2020-08-10 08:19:26
【问题描述】:
因此,我一直在尝试使用伽马误差分布优化 Michaelis-Menten 关系,以对我收集的一些数据的平均值进行建模。但是,无论我如何优化函数,我得到的最低 AIC 是用于甚至不接近数据的参数。有什么办法可以解决吗?
这是我的代码:
我首先创建一个最大似然函数:
MicNLL <- function(a,b){
#a=150.6727
#b=319.7007 optim val
top <- a*x
bot <- b+x
Mic <- top/bot
nll <- -sum(dgamma(y, shape=(Mic^2/var(x)), scale=(var(x)/Mic), log=TRUE))
return(nll)
}
然后我使用bbmle包中的mle2()函数编写了优化函数:
MN <- mle2(minuslogl = MicNLL, parameters=list(a~Treatment, b~Treatment), start=list(a=100,b=260), data=list(x=NSug3$VolpulT, y=NSug3$SugarpugT), control=list(maxit=1e4), method="SANN", hessian=T)
MN
AICMN <- (2*2)-(2*logLik(MN))
AICMN
虽然 a=100 和 b=260 的目测参数很适合我的数据,但它通常会将参数优化为 a=242 和 b=182,结果
Michealis <- function(a, b, x){
top <- a*x
bot <- b+x
Mic <- top/bot
return(Mic)
}
ggplot(NSug3, aes(x=VolpulT, y=SugarpugT))+
geom_point(stat="identity", size=0.8)+
theme_classic()+
ggtitle("help")+
ylab("Sugar concentration")+
xlab("Volume per Extra floral nectary")+
stat_function(fun= Michealis, args=c(a=100, b=260), colour="Orange", size=0.725)+
stat_function(fun= Michealis, args=c(a=MN@coef[[1]], b=MN@coef[[2]]), colour="Red", size=0.725)
长话短说,我怎样才能确保我的优化模型真正贯穿我的数据?
【问题讨论】:
标签: r statistics data-modeling