R-具有2个参数的指数函数的Optimx-无法在初始参数值处评估函数 [英] R- Optimx for exponential function with 2 parameters - cannot evaluate function at initial parameter values

查看:890
本文介绍了R-具有2个参数的指数函数的Optimx-无法在初始参数值处评估函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我错过了一些非常明显的事情,但是经过一个小时的摆弄/搜索,我无法使它正常工作.代码:

I feel like I missed something very obvious but after an hour of fiddling/googling I cannot get this to work. Code:

#Generate data from exponential model

xdata<-seq_len(100)
ydata<-2*exp(-2*(xdata+rnorm(100)))

#Fit exponential model to data
firstorder<-function(C0,k){
 ynew<-C0*exp(-k*xdata)
 RMSE<-sum((ynew-ydata)^2,na.rm=TRUE)
 return(RMSE)
}

#Initial parameter values
params<-c(1,1)

#Optimize
optimx(params,firstorder)

optimx.check中的错误(par,optcfg $ ufn,optcfg $ ugr,optcfg $ uhess,更低, 无法在初始参数处评估功能

Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, : Cannot evaluate function at initial parameters

我尝试了多种输入参数的方法.

I tried a variety of ways to input the parameters.

推荐答案

尝试

optimx(params, function(x) firstorder(x[1], x[2]))

这篇关于R-具有2个参数的指数函数的Optimx-无法在初始参数值处评估函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆