Guest User

Untitled

a guest
Nov 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. # y_scale_coeff is the
  2. # coefficient to reduce y axis values
  3. # only to display
  4. y_scale_coeff = 1/1000
  5.  
  6. min_time = 0
  7. max_time = 10000
  8. max_time = max_time * y_scale_coeff
  9. xlim_bottom = c(0,200)
  10.  
  11. nx = 20
  12. ny = 40
  13.  
  14. ylim = c(min_time,max_time)
  15.  
  16. # x
  17. # Cum. Hazard % values for faiure hours
  18. # diesel engine fan NELSON data
  19. x = c(1.4,2.9,4.4,5.9,7.7,9.6,11.5,13.6,15.8,18.7,22.7,35.2)
  20.  
  21. # y
  22. # faiure hours
  23. # diesel engine fan NELSON data
  24. y = c(450,1150,1150,1600,2070,2070,2080,3100,3450,4600,6100,8750)
  25.  
  26. y = y * y_scale_coeff
  27.  
  28. # ticks at bottom x axis
  29. ticks_x = c(0,50,100,150,200)
  30.  
  31. # ticks at y axis
  32. ticks_y = seq(0, max_time, 1)
  33.  
  34. # labels at top x axis
  35. x_top_labels = 100 * (1 - 1 / (exp(1) ^ (ticks_x / 100)))
  36. x_top_labels = round(x_top_labels,digits = 1)
  37.  
  38. # plot
  39. plot(x,y,bty="n",xlim=xlim_bottom,ylim=ylim,xaxs="i",yaxs="i",col="red",pch=16,axes=FALSE,xlab="",ylab="")
  40.  
  41. #x axis at bottom
  42. axis(1,ticks_x,col="red",col.ticks="red",col.axis="red")
  43. mtext("Cum. Hazard %",1,line=2.5,at=100,col="red")
  44.  
  45. #x axis at top
  46. axis(3,ticks_x,labels=x_top_labels,col="blue",col.ticks="blue",col.axis="blue")
  47. mtext("CDF %",3,line=2.5,at=100,col="blue")
  48.  
  49. # y axis on left
  50. axis(2,ticks_y,col="black",col.ticks="black",col.axis="black")
  51. mtext(paste("Failure Hours ( X ",y_scale_coeff,")"),2,line=2.5,at=max_time/2,col="black")
  52.  
  53. # add grid to the plot
  54. grid(nx,ny,col="lightgray",lty="solid",lwd=par("lwd"),equilogs=TRUE)
  55.  
  56. # add points again
  57. # (to layer dots over grid lines)
  58. points(x,y,col="red")
  59.  
  60. # draw line to determine mttf
  61. # vertical line from top to Cum Haz. % = 100
  62. segments(100,0,100,max_time,col="green")
  63.  
  64. # get best linear fit
  65. fit = lm(y~x)
  66.  
  67. # draw best fit line
  68. abline(fit)
  69.  
  70. summary(fit)
  71.  
  72. newdata = data.frame(x=100)
  73. predict(fit,newdata,interval="predict")
  74. ## R prediction 24538.7
  75. ## Wayne Nelson's prediction 29000
  76. ## Best Numeric Prediction 28703.3
Add Comment
Please, Sign In to add comment