I have a 3x3 factorial experimental design and I want to perform a non-linear regression to adjust exponentially. I can easily adjust the curves individually in the following way:
dataUrea0 <- subset(Suelo, Nurea == "0")
dataUrea90 <- subset(Suelo, Nurea == "90")
dataUrea180 <- subset(Suelo, Nurea == "180")
plotPoints(P ~ NCP, data = dataUrea0)
nlsUrea0 <- nls(P~a*exp(b*NCP), dataUrea0, start=list(a= 5, b=0.04))
summary(nlsUrea0)
pcrGOF(nlsUrea0, PRESS = FALSE)
overview(nlsUrea0)
plotfit(nlsUrea0, smooth = TRUE, xlab="Norg (Kg/ha)", ylab="P (ppm)", col.fit = "blue", lwd = 3)
plotPoints(P ~ NCP, data = dataUrea90)
nlsUrea90 <- nls(P~a*exp(b*NCP), dataUrea90, start=list(a= 5, b=0.04))
summary(nlsUrea90)
pcrGOF(nlsUrea90, PRESS = FALSE)
overview(nlsUrea90)
plotfit(nlsUrea90, smooth = TRUE, xlab="Norg (Kg/ha)", ylab="P (ppm)", col.fit = "blue", lwd = 3)
plotPoints(P ~ NCP, data = dataUrea180)
nlsUrea180 <- nls(P~a*exp(b*NCP), dataUrea180, start=list(a= 5, b=0.04))
summary(nlsUrea180)
pcrGOF(nlsUrea180, PRESS = FALSE)
overview(nlsUrea180)
plotfit(nlsUrea180, smooth = TRUE, xlab="Norg (Kg/ha)", ylab="P (ppm)", col.fit = "blue", lwd = 3)
However, when I want to make a comparative graph I get an error. I write in the r:
S <- within(S, {
Nmin <- as.factor(NM)
})
S <- within(S, {
Norg <- as.factor(NCP)
})
S$Tratamiento <- as.factor(S$Tratamiento)
S%>%
split(.$NM) %>%
map( ~nls(P~a*exp(b*Norg)),
start = list(a = 5),
(b = 0.04),
trace = TRUE,
algorithm = "port",
data=.) %>%
map_df(~augment(.), .id="NM") %>%
as.tibble() %>%
ggplot(aes(x=Norg, y=P, color=NM)) +
geom_line(aes(y=.fitted))+
labs(title="",
x="x",
y="y")+
theme_minimal()
And I get the following error:
Error: '.x' is not a vector (language)
To do all this I use the libraries:
library(mosaic)
library(ggplot2)
library(nlstools)
library(minpack.lm)
library(qpcR)
library(broom)
library(purrr)
library(tidyverse)
Here is a sample of the data: link Thanks!