####################################################################################### ## Exemplo nlsmsn ####################################################################################### library(nlsmsn) ##Load the data data(Oil) ##Define non linear function nlf<-function(x,betas){ resp<- betas[1]/(1 +betas[2]*exp(-betas[3]*x)) return(resp) } ##Set the response y and covariate x y <- Oil$y x <- Oil$x ## See relationship between y and x plot(x,y) ##Set initial values betas <- c(37,4.81,0.78) sigma2 <- 2.95 shape <- -2 nu <- 3 ## Skew.normal regression analysis.n <- smsn.nl(y=y, x=x, betas=betas, sigma2=sigma2, shape = shape, nlf = nlf, criteria = TRUE, family = "Normal", iter.max = 200) ## Skew.normal regression analysis.sn <- smsn.nl(y=y, x=x, betas=betas, sigma2=sigma2, shape = shape, nlf = nlf, criteria = TRUE, family = "Skew.normal", iter.max = 200) ## Skew.t regression analysis.st <- smsn.nl(y=y, x=x, betas=betas, sigma2=sigma2, shape = shape, nu = nu, nlf = nlf, criteria = TRUE, family = "Skew.t", iter.max = 200) analysis.n$AIC analysis.sn$AIC analysis.st$AIC ####################################################################################### ## Exemplo car ####################################################################################### library(car) data(DNase) DNase <- subset(DNase, Run == 1) plot(DNase$conc,DNase$density) plot(log(DNase$conc),DNase$density) ## fit a representative run fm1 <- nls(density ~ SSlogis( log(conc), Asym, xmid, scal ), data = DNase, subset = Run == 1) ## compare with a four-parameter logistic fm2 <- nls(density ~ SSfpl( log(conc), A, B, xmid, scal ), data = DNase, subset = Run == 1) summary(fm2) anova(fm1, fm2) ####################################################################################### ## Compare car x nlsmsn ####################################################################################### data(Oil) ##Define non linear function nlf<-function(x,betas){ resp<- betas[1]/(1 +betas[2]*exp(-betas[3]*x)) return(resp) } ##Set the response y and covariate x y <- Oil$y x <- Oil$x ## See relationship between y and x plot(x,y) ##Set initial values betas <- c(37,4.81,0.78) sigma2 <- 2.95 shape <- -2 nu <- 3 ## Skew.normal regression analysis.n <- smsn.nl(y=y, x=x, betas=betas, sigma2=sigma2, shape = shape, nlf = nlf, criteria = TRUE, family = "Normal", iter.max = 200) ##Define non linear function nlf2<-function(x,beta1,beta2,beta3){ resp<- beta1/(1 +beta2*exp(-beta3*x)) return(resp) } analysis.nl <- nls(y ~ nlf2(x,beta1,beta2,beta3), data = Oil, start = list(beta1=37,beta2=4.81,beta3=0.78)) coef(analysis.nl) analysis.n$betas