1

I'm new to R and my question might be a little silly, but any help is appreciated. I want to graphically explore a sample to find an appropriate distribution from which the sample could have been drawn. But when I plot a histogram of the sample, the density of the sample exceeds the theoretical maximum value of 1 : see image

How do I adjust this error? Do I need to transform the data or do I have to adjust the bins of the histogram?

My R code:

dataSample = read.table("sample6.txt", fill = TRUE)
sampleMatrix = as.matrix(dataSample)
sampleVector = as.vector(sampleMatrix)

h = hist(sampleVector, plot=F)
x =c(min(sampleVector, na.rm=T), max(sampleVector, na.rm=T))
ylim = range(0, max(get("density", h), max(density)))

hist(sampleVector, prob = T, col = "lightgreen", xlim = x, 
ylim = ylim, main = "Histogram of data sample", xlab = "sample", ylab = "density")

This is my data sample:

0.5604785 0.0231508 0.2715692 0.2464922 0.2743465
0.434444 0.1779845 1.163666 0.5195378 0.08565649
0.2003622 0.3372351 0.02383633 0.2765776 0.1596984
0.3688299 0.2727399 0.3578011 0.4405475 0.07207568
0.424764 1.406219 1.12157 2.170512 0.6944183
2.429551 0.889546 0.1930762 0.579666 0.06834702
0.03690897 0.391838 1.019549 0.272865 0.1993042
0.02951076 0.3739699 0.2612313 1.988982 1.100386
0.9509101 1.978394 0.2469858 0.1256963 1.645895
0.1024105 0.336701 0.1322722 0.3881196 1.152153
0.6207026 1.506684 0.2826296

Thanks in advance!

K.R.
  • 31
  • 2
  • 5
  • Possible duplicate -- see [this post](http://stackoverflow.com/q/7324683/2572423) -- notice the difference between percentage and "normalization" with `freq = FALSE`. In addition, the density [*can* be greater than 1](http://stats.stackexchange.com/q/4220/31007). – JasonAizkalns Feb 22 '16 at 15:46
  • just use the freq argument with value of FALSE. – SabDeM Feb 22 '16 at 15:47
  • The density is allowed to be larger than 1. See for example [this comment](http://math.stackexchange.com/questions/105455/how-can-a-probability-density-be-greater-than-one-and-integrate-to-one) – ekstroem Feb 22 '16 at 15:47
  • @K.R. give your example data if possible –  Feb 22 '16 at 16:17
  • Hey guys thanks for the reply. I'll go ahead and give your advices a try. I added the data sample too so it's easier to replicate. – K.R. Feb 22 '16 at 16:36

0 Answers0