【发布时间】:2018-02-10 10:51:24
【问题描述】:
我正在使用 R 用方程拟合对数曲线上的数据:
y = a * log(b * x)
我的数据如下所示:
#Creating example data
pre <- c(946116, 1243227, 1259646, 1434124, 1575268, 2192526, 3252832, 6076519)
post <- c(907355, 1553586, 1684253, 2592938, 1919173, 1702644,3173743, 3654198)
data <- data.frame(pre,post)
#Plotting data
ggplot(data, aes(x=pre, y=post))+
geom_point()
但是,当我尝试使用 geom_smooth 拟合对数曲线时,出现错误。
# Fitting logarithmic curve
ggplot(data, aes(x=pre, y=post))+
geom_point()+
geom_smooth(method="nls", se=FALSE,
method.args=list(formula=y~a*log(b*x),
start=c(a=100, b=2)))
警告信息:
1: In log(b * x) : NaNs produced
2: Computation failed in `stat_smooth()`:
Missing value or an infinity produced when evaluating the model
当我尝试在 nls 中创建对数模型而不使用 ggplot 时,我遇到了类似的问题
model <- nls(data=data,
formula=y~a*log(b*x),
start=list(a=100, b=2))
警告信息:
Error in numericDeriv(form[[3L]], names(ind), env) :
Missing value or an infinity produced when evaluating the model
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In log(b * x) : NaNs produced
作为 R 新手,我不太明白错误消息试图告诉我什么。我知道我需要更改指定开始条件的方式,但我不知道如何。
【问题讨论】: