statistics - r cumulative plot simplication and what should it be called -
statistics - r cumulative plot simplication and what should it be called -
i have numeric vector data. need gather next data, i.e., histogram, in cumulative sense.
a=c() s=seq(0,1000,10) for(i in s) { a<-c(a,length(data[data>=i])) } plot(s,a) how can create vectorized, , should operation called? not good, because have know range in order write s in above, there existing function in r operation?
thank you.
something this??
set.seed(1) # reproducible illustration info <- rnorm(100) # random sample n(0,1) par(mfrow=c(1,2)) # set graphics device 2 plots z <- hist(data,ylab="counts",main="histogram") barplot(cumsum(z$counts), names.arg=z$breaks[-1],main="cuml. histogram") this takes advantage of fact hist(...) function not plots histogram, returns , object of type histogram. object has elements $breaks containing upper , lower limits on histogram bins, , $counts containing count of info in each bin. cumsum function calculates cumulative sum. plot on right cumulative sum of counts vs. breaks.
another, simpler way "hack" histogram object returned hist(...) , utilize plot(...) on that:
z <- hist(data,ylab="counts",main="histogram") z$counts <- cumsum(z$counts) plot(z, main="cuml. histogram") finally, ecdf(...) (empirical cumulative distribution function) returns function can plotted easily.
plot(ecdf(data)) r statistics
Comments
Post a Comment