Solved – How to get p value and confidence intervals for nls functions

confidence intervalnlsnonlinear regression

I have 2 questions.

1) How can I have p.value for my 2 functions? My hypothesis is that I have a correlation between my function and my data.

2) How can I have a confidence intervals for my 2 functions?

library(ggplot2)
g <- function (x, a,b,c) a * (1-exp(-(x-c)/abs(b)))
X1 <- c(129.08,109.92,85.83,37.72)
Y1 <- c(0.7,0.5,0.39,-1.36)
dt1 <- data.frame(x1=X1,y1=Y1)
model1 <- nls(Y1 ~ g(X1, a, b, c), 
          start = list(a=0.5, b=60, c=50),control=nls.control(maxiter = 200))

ggplot(data = dt1,aes(x = x1, y = y1)) + 
     theme_bw() + geom_point() + 
     geom_smooth(data=dt1, method="nls", formula=y~g(x, a, b, c),
       se=F, start=list(a=0.5, b=60, c=50))


f <- function (x, a, b, c) a*(x^2)+b*x+c   
X2 <- c(589.62,457.92,370.16,295.98,243.99,199.07,159.91,142.63,
124.15, 101.98, 87.93, 83.16, 82.2, 74.48, 47.68, 37.51, 31,
27.9, 21.24,18.28)
Y2 <- c(0.22,0.37,0.49,0.65,0.81,0.83,1,0.81,0.65,0.44,0.55,0.63,
0.65,0.55,0.37,0.32,0.27,0.22,0.17,0.14)
dt2 <- data.frame(x2=X2,y2=Y2)
model2 <- nls(Y2 ~ f(X2, a, b, c), 
           start = list(a=-1, b=3, c=0),control=nls.control(maxiter = 200))
ggplot(data = dt2,aes(x = x2, y = y2)) + 
      theme_bw() + geom_point() + 
      geom_smooth(data=dt2, method="nls", formula=y~f(x, a, b, c),
       se=F, start=list(a=-1, b=3, c=0))

Thank you in advance

Best Answer

1. - You could try (this is an approximation)

library(nls2)  
summary(as.lm(model))  
  • You can obtain a p-value for all parameters used in your model using

    summary(model)

  • You can get p values for a model by comparing it to another ("nested") model using

    anova(model1, model2)

    where model 2 is a simplified version of model 1 (it is your null hypothesis)

  • You can use methods such a bootstrapping, to get a measure of the probability of fit of your complete model.

    2.

  • You can possibly get full model confidence interval using (this is an approximation)

    library(nls2) predict(as.lm(model2), interval = "confidence")

  • You can obtain the confidence interval of the parameters using

    confint(model)

  • You can get more information about these parameter intervals using

    profile(model)

    plot(profile(model))

  • You can obtain the pair wise confidence interval for two of your parameters (for both plotting and to get the matrix) using

    ellipse.nls(model)