TEXT   91

robust code

Guest on 10th May 2022 02:01:43 AM

  1.  
  2. R : Copyright The R Foundation for Statistical Computing
  3. Version 2.0.1 , ISBN 3-900051-07-0
  4.  
  5. R is free software and comes with ABSOLUTELY NO WARRANTY.
  6. You are welcome to redistribute it under certain conditions.
  7. Type 'license()' or 'licence()' for distribution details.
  8.  
  9. R is a collaborative project with many contributors.
  10. Type 'contributors()' for more information and
  11. 'citation()' on how to cite R or R packages in publications.
  12.  
  13. Type 'demo()' for some demos, 'help()' for on-line help, or
  14. 'help.start()' for a HTML browser interface to help.
  15. Type 'q()' to quit R.
  16.  
  17. Error in file.choose() : file choice cancelled
  18. > data(chem)
  19. Warning message:
  20. Data set 'chem' not found in: data(chem)
  21. > library(MASS)
  22. > data(chem)
  23. > chem
  24.  [1]  2.90  3.10  3.40  3.40  3.70  3.70  2.80  2.50  2.40  2.40  2.70  2.20
  25. [13]  5.28  3.37  3.03  3.03 28.95  3.77  3.40  2.20  3.50  3.60  3.70  3.70
  26. > mean(chem)
  27. [1] 4.280417
  28. > median(chem)
  29. [1] 3.385
  30. > sqrt(var(chem))
  31. [1] 5.297396
  32. > mad(chem)
  33. [1] 0.526323
  34. > ?mad
  35. > IQR(chem)
  36. [1] 0.925
  37. > ?IQR
  38. > .925/1.349
  39. [1] 0.6856931
  40. > chem2 <- chem
  41. > chem2[17] <- 289.5
  42. > median(chem2)
  43. [1] 3.385
  44. > mean(chem2)
  45. [1] 15.13667
  46. > sqrt(var(chem2))
  47. [1] 58.44301
  48. > mad(chem2)
  49. [1] 0.526323
  50. > IQR(chem2)
  51. [1] 0.925
  52. > huber(chem)
  53. $mu
  54. [1] 3.206724
  55.  
  56. $s
  57. [1] 0.526323
  58.  
  59. > hubers(chem)
  60. $mu
  61. [1] 3.205498
  62.  
  63. $s
  64. [1] 0.673652
  65.  
  66. > huber(chem2)
  67. $mu
  68. [1] 3.206724
  69.  
  70. $s
  71. [1] 0.526323
  72.  
  73. > hubers(chem2)
  74. $mu
  75. [1] 3.205498
  76.  
  77. $s
  78. [1] 0.673652
  79.  
  80. > ?fitdistr
  81. > fitdistr(chem,"t",list(m=mean(chem),s=sqrt(var(chem)))
  82. + )
  83. Error in dt((x - m)/s, df, log = TRUE) : Argument "df" is missing, with no default
  84. > fitdistr(chem,"t",list(m=mean(chem),s=sqrt(var(chem))),df=5)
  85.        m           s    
  86.   3.1855470   0.6423029
  87.  (0.1474964) (0.1279958)
  88. Warning messages:
  89. 1: NaNs produced in: log(x)
  90. 2: NaNs produced in: log(x)
  91. > fitdistr(chem,"t",list(m=mean(chem),s=sqrt(var(chem))),df=25)
  92.        m           s    
  93.   3.3891189   2.2569286
  94.  (0.4743110) (0.6777613)
  95. > hist(chem)
  96. > ?hist
  97. > hist(chem,breaks=2:25)
  98. Error in hist.default(chem, breaks = 2:25) :
  99.         some `x' not counted; maybe `breaks' do not span range of `x'
  100. > hist(chem,breaks=2:26)
  101. Error in hist.default(chem, breaks = 2:26) :
  102.         some `x' not counted; maybe `breaks' do not span range of `x'
  103. > hist(chem,15)
  104. > hist(chem,breaks=c(1,2,3,4,5,10,15,20,25))
  105. Error in hist.default(chem, breaks = c(1, 2, 3, 4, 5, 10, 15, 20, 25)) :
  106.         some `x' not counted; maybe `breaks' do not span range of `x'
  107. > dotplot(chem)
  108. Error: couldn't find function "dotplot"
  109. > dot(chem)
  110. Error: couldn't find function "dot"
  111. > help.search(dot.plot)
  112. Error in help.search(dot.plot) : Object "dot.plot" not found
  113. > help.search("dot")
  114. > dotchart(chem)
  115. > hist(chem[-17])
  116. >
  117. > ?dt
  118. > lines(chem[-17],dt((chem[-17]-3.39)/0.64),df=5)
  119. Error in dt((chem[-17] - 3.39)/0.64) : Argument "df" is missing, with no default
  120. > lines(chem[-17],dt((chem[-17]-3.39)/0.64,df=5))
  121. > lines(chem[-17],dt((chem[-17]-3.39)/0.64,df=5)/0.64)
  122. > lines(sort(chem[-17]),dt(sort((chem[-17]-3.39)/0.64),df=5)/0.64)
  123. > lines(sort(chem[-17]),dt(sort((chem[-17]-3.39)/0.64),df=5)/0.64,col="red")
  124. > hist(chem[-17],freq=FALSE)
  125. > lines(sort(chem[-17]),dt(sort((chem[-17]-3.39)/0.64),df=5)/0.64,col="red")
  126. > quartz()
  127. > hist(chem,freq=FALSE)
  128. > lines(sort(chem),dt(sort((chem-3.39)/0.64),df=5)/0.64,col="red")

Raw Paste


Login or Register to edit or fork this paste. It's free.