How to merge bins in R -


so, trying merge bins of histogram whenever number of observations in bin less 6.

library(fitdistrplus) mydata <-read.csv("book2.csv",stringsasfactors=false) qf3<-as.numeric(mydata[,1]) histrv<-hist(qf3,breaks="fd") binvec<-data.frame(diff(histrv$breaks)) binbreak=histrv$breaks freq<-histrv$count datmean=as.numeric(mean(qf3)) datsigma=as.numeric(sd(qf3)) templist<-as.numeric()#empty list (i in 1:nrow(binvec)){   templist[i]=pnorm(binbreak[i+1],datmean,datsigma)-pnorm(binbreak[i],datmean,datsigma) } pi<-data.frame(templist) chisqvec<-(freq-length(qf3)*pi)^2/(length(qf3)*pi) xstat=sum(chisqvec) 

the above code provide histogram 5 bins contain less 6 observations, bins 6000-7000, 7000-8000, 8000-9000, 9000-10000, , 10000-11000. each of these 5 bins contain 2, 5, 2, 2, , 1 observations respectively. merge bins can have more 5 observations.

in other words, have 2 bins 6000-8000 , 8000-11000 can contain 7 observations , 5 observations.

does have clue on how approach problem?

qf3 looks following:

> qf3  [1]  2016  1425  2000   785   823  2484  1870   770  1220  3454  1056  2745  2830 [14]   950   601  1245  2663  1500  1717  1070  1704  2517  1090  3310  3389  2200 [27]   882  2113   600  1900  4417   745   530  1630  1600  4530   948  2764  2202 [40]  1052  2685  1120  1275  2300  1590  1935  3957  4283  3215  5684  4092  7548 [53]  4547  3510  3063  5549  6460  5204  4626  4965  5023  8111  5525  4804  5994 [66]  8471  4767  7142  3420  4061  5102  9135  3861  5372  7274  5054  7318  3791 [79]  4901  3549  4758  4859 10190  5609  7624  5841  4908  4974  6691  5713  3235 [92]  4464  2656  4399  9581  3993  4061 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -