Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Packages
- library(minpack.lm)
- # Data set - Diameter in function of Feature and Age
- Feature<-sort(rep(c("A","B"),22))
- Age<-c(60,72,88,96,27,
- 36,48,60,72,88,96,27,36,48,60,72,
- 88,96,27,36,48,60,27,27,36,48,60,
- 72,88,96,27,36,48,60,72,88,96,27,
- 36,48,60,72,88,96)
- Diameter<-c(13.9,16.2,
- 19.1,19.3,4.7,6.7,9.6,11.2,13.1,15.3,
- 15.4,5.4,7,9.9,11.7,13.4,16.1,16.2,
- 5.9,8.3,12.3,14.5,2.3,5.2,6.2,8.6,9.3,
- 11.3,15.1,15.5,5,7,7.9,8.4,10.5,14,14,
- 4.1,4.9,6,6.7,7.7,8,8.2)
- d<-dados <- data.frame(Feature,Age,Diameter)
- str(d)
- #Create a nls model (Levenberg-Marquardt algoritm) for each Feature (A abd B)
- e1<- Diameter ~ a1 * Age^a2
- Fecture_vec<-unique(d$Feature)
- mod_ND <- list() #List for save each model
- for(i in 1:length(Fecture_vec)){
- d2 <- subset(d, d$Feature == Fecture_vec[i])
- mod_ND[[i]] <- nlsLM(e1, data = d2,
- start = list(a1 = 0.1, a2 = 10),
- control = nls.control(maxiter = 1000))
- print(summary(mod_ND[[i]]))
- }
- #
- e1<- Diameter ~ a1 * Age^a2
- Fecture_vec<-unique(d$Feature)
- mod_ND <- list() #List for save each model
- for(i in 1:length(Fecture_vec)){
- d2 <- subset(d, d$Feature == Fecture_vec[i])
- mod_ND[[i]] <- nlsLM(e1, data = d2,
- start = list(a1 = 0.1, a2 = 10),
- control = nls.control(maxiter = 1000))
- Xs<-data.frame()
- for(z in 1:999){
- d2 <- subset(d, d$Feature == Fecture_vec[i])
- mod_ND[[z]] <- nlsLM(e1, data = d2,
- start = list(a1 = coef(mod_ND[[i]])[1], a2 = mod_ND[[i]])[2]),
- control = nls.control(maxiter = 1000))
- if (mod_ND[[z,c(finIter")]] == 1){ break } ## Stop when iteractions =1
- print(summary(mod_ND[[z]]))
- }
- }
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement