Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #Packages
  2. library(minpack.lm)
  3.  
  4. # Data set - Diameter in function of Feature and Age
  5. Feature<-sort(rep(c("A","B"),22))
  6. Age<-c(60,72,88,96,27,
  7. 36,48,60,72,88,96,27,36,48,60,72,
  8. 88,96,27,36,48,60,27,27,36,48,60,
  9. 72,88,96,27,36,48,60,72,88,96,27,
  10. 36,48,60,72,88,96)
  11. Diameter<-c(13.9,16.2,
  12. 19.1,19.3,4.7,6.7,9.6,11.2,13.1,15.3,
  13. 15.4,5.4,7,9.9,11.7,13.4,16.1,16.2,
  14. 5.9,8.3,12.3,14.5,2.3,5.2,6.2,8.6,9.3,
  15. 11.3,15.1,15.5,5,7,7.9,8.4,10.5,14,14,
  16. 4.1,4.9,6,6.7,7.7,8,8.2)
  17. d<-dados <- data.frame(Feature,Age,Diameter)
  18. str(d)
  19.  
  20. #Create a nls model (Levenberg-Marquardt algoritm) for each Feature (A abd B)
  21. e1<- Diameter ~ a1 * Age^a2
  22. Fecture_vec<-unique(d$Feature)
  23. mod_ND <- list() #List for save each model
  24. for(i in 1:length(Fecture_vec)){
  25. d2 <- subset(d, d$Feature == Fecture_vec[i])
  26. mod_ND[[i]] <- nlsLM(e1, data = d2,
  27. start = list(a1 = 0.1, a2 = 10),
  28. control = nls.control(maxiter = 1000))
  29. print(summary(mod_ND[[i]]))
  30. }
  31. #
  32.  
  33. e1<- Diameter ~ a1 * Age^a2
  34. Fecture_vec<-unique(d$Feature)
  35. mod_ND <- list() #List for save each model
  36. for(i in 1:length(Fecture_vec)){
  37. d2 <- subset(d, d$Feature == Fecture_vec[i])
  38. mod_ND[[i]] <- nlsLM(e1, data = d2,
  39. start = list(a1 = 0.1, a2 = 10),
  40. control = nls.control(maxiter = 1000))
  41. Xs<-data.frame()
  42. for(z in 1:999){
  43. d2 <- subset(d, d$Feature == Fecture_vec[i])
  44. mod_ND[[z]] <- nlsLM(e1, data = d2,
  45. start = list(a1 = coef(mod_ND[[i]])[1], a2 = mod_ND[[i]])[2]),
  46. control = nls.control(maxiter = 1000))
  47. if (mod_ND[[z,c(finIter")]] == 1){ break } ## Stop when iteractions =1
  48. print(summary(mod_ND[[z]]))
  49. }
  50. }
  51. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement