J'utilise R pour ajuster les données sur une courbe logarithmique avec l'équation:Utiliser nls et ggplot2 pour ajuster une courbe logarithmique aux données
y = a * log (b * x)
Mes données ressemble ceci:
#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()
Mais lorsque je tente d'ajuster une courbe logarithmique en utilisant geom_smooth, je reçois une erreur.
# 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)))
Les messages d'avertissement:
1: In log(b * x) : NaNs produced
2: Computation failed in `stat_smooth()`:
Missing value or an infinity produced when evaluating the model
Je reçois des problèmes similaires lorsque je tente de créer un modèle logarithmique nls, sans utiliser ggplot
model <- nls(data=data,
formula=y~a*log(b*x),
start=list(a=100, b=2))
Messages d'avertissement:
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
Comme quelqu'un qui est nouveau à R, je ne comprends pas très bien ce que les messages d'erreur essayent de me dire. Je sais que je dois changer comment je spécifie les conditions de départ, mais je ne sais pas comment.