0

1 つは p 値用、もう 1 つは勾配を表す 2 つの列があるとします。有意な p 値を持つ勾配データ ポイントのみをプロットする方法を見つけたいと考えています。これが私のコードです:

print("State the file name (include .csv)")
filename <- readline()
file <- read.csv(filename)

print ("Only include trials with p-value < .05? (enter yes or no)")
pval_filter <- readline()
if (pval_filter == "yes"){
   i <- 0
   count <- 0
   filtered <- NULL
   while (i > length(file$pval)){
      if (file$pval[i] < .05){
         filtered[count] <- i
         count <- count + 1
      }
      i <- i + 1
   }

   x <- 0
   while (x != -1){
      print("State the variable to be plotted")
      temp_var <- readline()
      counter <- 0
      var <- NULL
      while (counter > length(filtered)){
         var[counter] = file [, temp_var][filtered[counter]]
         counter <- counter + 1
         }

      print ("State the title of the histogram")
      title <- readline()
      hist(var, main = title, xlab = var)
      print("Enter -1 to exit or any other number to plot another variable")
      x <- readline()
    }
}
4

4 に答える 4

0

重要な p 値を持つ勾配データ ポイントのみをプロットするコードを次に示します。ファイルの列名が pval と勾配であると仮定します。

# Prompt a message on the Terminal
filename <- readline("Enter the file name that have p-value and slopes (include .csv)")
# Read the filename from the terminal
file     <- read.csv(filename, header = TRUE)

# Prompt a message again on the Terminal and read the acceptance from user
pval_filter <- readline("Only include trials with p-value < .05? (enter yes or no)")    

if (to-lower(pval_filter) == "yes"){
   # Create a filtered file that contain only rows with the p-val less than that of siginificatn p-val 0.05
   file.filtered <- file[file$pval < 0.05, ]    

   # Get the title of the Histogram to be drawn for the slopes (filtered)
   hist.title <- readline("State the title of the histogram")
   # Draw histogram for the slopes with the title
   #     las = 2 parameter in the histogram below makes the slopes to be written in parpendicular to the X-axis
   #     so that, the labels will not be overlapped, easily readable. 
   hist(file.filtered$slope, main = hist.title, xlab = Slope, ylab = frequency, las = 2)
}

これが役立つことを願っています。

于 2013-10-22T05:46:04.150 に答える