Skip to content

Resampled Individual Reliability Function Code #39

@vittorio-g

Description

@vittorio-g

As previously discussed with @ryentes I'm also posting the code to compute the Resasmpled Individual Reliability Index. This should provide a more reliable way to assess the individual reliability compared to the evenodd index. In fact, as it is shown in the following graph (showing the value of the mean index value against the number of iterations involed in the computation), the variance of the mean is quite high when computng only one iteration (as it's the case for the "evenodd" function). The value becomes more stable around 10 iterations.

image

The following is the code I used to plot the graph:

library(abind)

rir <- function(x,factors,iterations){
  #objects
  df1_mean <- matrix(nrow = nrow(x),
                     ncol = length(factors)) %>% data.frame()
  
  df2_mean <- matrix(nrow = nrow(x),
                     ncol = length(factors)) %>% data.frame()
  
  ir <- matrix(nrow = nrow(x),
               ncol = iterations) %>% data.frame()
  
  for (l in 1:iterations){
   
    #Objects
    a <- 0
    j <- 1
    for (i in factors){
      
      #section selection
      a <- a+i
      sec <- x[,(a-i+1):a]
      
      #random sampling
      sel <- srswor(round(ncol(sec)/2),ncol(sec)) %>% as.logical()
      
      #mean calculation
      df1_mean[,j] <- apply(sec[sel],1,mean,na.rm=T)
      df2_mean[,j] <- apply(sec[!sel],1,mean,na.rm=T)
      
      j <- j+1  
    }
    
    #Correlation
    ir[,l] <- sapply(1:nrow(df1_mean), function(x){
      cor(
        as.numeric(df1_mean[x,]),
        as.numeric(df2_mean[x,]),
        use="complete.obs"
      )
    }
    )
  }
  
  meanIr <- apply(ir,1,mean)
  riri <- -2*meanIr/(1 + meanIr)
  riri
}

itMeans <- c()
totMeans <- c()

for (l in c(1,5,10,15,20,25)){
 
  for (i in 1:10){
    itMeans[i] <- mean(rir(careless_dataset2,rep(10,10),l))
  }

  totMeans <- rbind(totMeans,
                    cbind(rep(l,10),itMeans))

}

plot(totMeans, main="Distribution of the mean each number of iterations")

The following is the code I'm proposing for a "Resampled Individual Reliability" function:

rir <- function(x,factors){
 
iterations <- 20
  
#objects
  df1_mean <- data.frame(matrix(nrow = nrow(x),
                     ncol = length(factors)))
  
  df2_mean <- data.frame(matrix(nrow = nrow(x),
                     ncol = length(factors)))
  
  ir <- data.frame(matrix(nrow = nrow(x),
               ncol = iterations))
  
  for (l in 1:iterations){
    ##Cycle for mean calculation
    #Objects
    a <- 0
    j <- 1
    
     for (i in factors){
      
        #section selection
        a <- a+i
        sec <- x[,(a-i+1):a]
      
        #random sampling
        sel <- as.logical(srswor(round(ncol(sec)/2),ncol(sec))) 
      
        #means
        df1_mean[,j] <- apply(sec[sel],1,mean,na.rm=T)
        df2_mean[,j] <- apply(sec[!sel],1,mean,na.rm=T)
      
        j <- j+1  
    }
    
    #Correlation
    ir[,l] <- sapply(1:nrow(df1_mean), function(x){
      cor(
        as.numeric(df1_mean[x,]),
        as.numeric(df2_mean[x,]),
        use="complete.obs"
      )
    }
    )
  }
  
  meanIr <- apply(ir,1,mean)
  riri <- -2*meanIr/(1 + meanIr)
  riri
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions