Dear R Users,

I am trying to use the function boot of the boot package to sample from a 
dataframe of two character variables (N=1127). Each character variable can take 
five different values. Here is an example of the data:
1  b95-99.9         d25%
2  b95-99.9          a1%
3  b95-99.9          a1%
4  b95-99.9          a1%
5  b95-99.9          a1%
6    a>99.9          a1%
7  b95-99.9          a1%
8  b95-99.9          a1%
9  b95-99.9          a1%
10 b95-99.9          a1%

The statistic I want to use is the median polish (I created my own function 
that calls function medpolish from stats package). In my function, I included a 
second argument for the weight as asked by the boot function. Here is my 
function, which basically creates the table from the two variables, divides 
each cell by the sum of the column to obtain percentage, does the median 
polish, and computes the median of some of the cells:

>juste.polish<-function(data,w=rep(1,nrow(data))/nrow(data))
>{tableR<-table(data[,1],data[,2])
> tableP<-tableR
> marg2<-apply(tableR,2,sum)
> for (i in 1:nrow(tableP))
>     {tableP[i,]<-100*(tableR[i,]/marg2)}
>juste.medp<-medpolish(tableP)
>median(c(juste.medp$residuals[dimnames(juste.medp$residuals)[[1]]=="e<60",1],
>         juste.medp$residuals[dimnames(juste.medp$residuals)[[1]]=="d60-79",2],
>         juste.medp$residuals[dimnames(juste.medp$residuals)[[1]]=="c80-94",3],
>         
> juste.medp$residuals[dimnames(juste.medp$residuals)[[1]]=="b95-99.9",4],
>         
> juste.medp$residuals[dimnames(juste.medp$residuals)[[1]]=="a>99.9",5]))
>}

When I call the boot function 
(>juste.boot<-boot(data=mydata,statistic=juste.polish,R=999)), it works but 
computes the same parameter at every boot sample, as if the resampling did not 
work and always provided a sample identical to the original sample.

If you have any ideas, I would be very grateful.

thanks,

delphine

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to