Function base

1. InfoEn.R

#load sample data
#setwd("~/Desktop/R/samplefile")
#library(readr)
#In <- read_csv("InEn_J.csv", col_names = F) #local download
In <-read.csv("https://raw.githubusercontent.com/andychuangkl/sample_file/master/InEn_J.csv",header = F)
names(In) = c("T1","S1","T2","S2","T3","S3")

#load function
devtools::source_gist("8a66656e57f5a0019dedf5b764f04d99" ,filename ="InfoEn.R" )

#information join entropy
InfoEn(datavector = cbind(In$T1,In$S1),
       bin = 20,
       scale_size = 0.8,
       normal_range1 = c(In$T1,In$T2,In$T3),
       normal_range2 = c(In$S1,In$S2,In$S3),
       xlab = "tempol_error(ms)",
       ylab = "spatial_error(mm)",
       Join = 2)

## [1] 5.674515
## <environment: 0x7fc62ea6c028>
#information entropy
InfoEn(datavector = In$T1,
       bin = 20,
       scale_size = 0.8,
       normal_range1 = c(In$T1,In$T2,In$T3),
       normal_range2 = c(In$S1,In$S2,In$S3), 
       Join = 1)

## [1] 3.641596
## <environment: 0x7fc630752c08>

2. Two_variables_test.R

#load sample data
sdata= read.csv("https://raw.githubusercontent.com/andychuangkl/sample_file/master/Two_variables_test.csv",header = T)

#load Two_variables_test function
devtools::source_gist(id = "8825c62d09f702d020f68359cfe3dba5",filename = "Two_variables_test.R")
devtools::source_gist("a17c23e19554049be0d455560014e0c4" ,
                      filename ="theme_apa.R" )

#select the two variables 
variable1 <- sdata[sdata$Fgroup == "creeping" & sdata$phase == 2 & sdata$group == "15",]$slope
variable2 <- sdata[sdata$Fgroup == "creeping" & sdata$phase == 2 & sdata$group == "20",]$slope

#nonparametric wilcoxon test 
  Two_variables_test( 
  variable1 = variable1,
  variable2 = variable2,
  xlab = "",
  ylab = "slope",
  name1 = "success_15",
  name2 = "success_20",
  paired = F,   #paired or not 
  normal_distribution = F #parametric or nonparametric
  )
## 
##  Wilcoxon rank sum test
## 
## data:  a and b
## W = 33, p-value = 0.06527
## alternative hypothesis: true location shift is not equal to 0

## <environment: 0x7fc63384afc8>
 #parametric t test 
  t1 = Two_variables_test( 
  variable1 = variable1,
  variable2 = variable2,
  xlab = "",
  ylab = "slope",
  name1 = "success_15",
  name2 = "success_20",
  paired = F,   #paired or not 
  normal_distribution = T #parametric or nonparametric
  )
## [1] "success_15 ( mean:-0.3, sd:0.73 ) - success_20 ( mean:-1.34, sd:0.8 ): t(11) = 2.42, p = .034, d = 1.34"

devtools::source_gist("09d796e017dfb2e8fcdc324234514feb" ,
                      filename ="significant_plot.R" )
#significant plot 
significant_plot(
    gdata = t1$plot,
    h = -2.5, #sign" * "height
    v1 = 1,
    v2 = 2,
    v1h = -1.5, #fist variable height
    v2h = -2.3) #second height

3. multiple_way_statistic.R

#names("fill","facet","x","N","DV","sd") 3way_plot
  #names(c("fill","x","N","DV","sd")) 2way_plot
  #need to change the dependent_varialbe name to "d"
  #data form should be reguler that likes this sample
  #form: c(factors, participant_numer, trial_n, Dv, sd) 
  #check the factors and particiapnt need to be a "factor" in r
#load samle data
anova_data_sample = read.csv("https://raw.githubusercontent.com/andychuangkl/sample_file/master/anova_data_sample.csv",header = T)[,-c(1)]
names(anova_data_sample)[which(names(anova_data_sample)=="slope")] = "d"
head(anova_data_sample,5)
##     Fgroup head_tail participant N           d        sd
## 1 creeping      head           1 7  0.03090655 0.3473885
## 2 creeping      head           2 7 -1.81504006 0.4102210
## 3 creeping      head           3 7  0.07919867 0.9589423
## 4 creeping      head           4 7 -0.63334370 0.9925303
## 5 creeping      head           5 7 -0.82213941 0.2450437
#load multiple_way_statistic.R function
devtools::source_gist(id = "f3da90d0ceee72c8126cec418938b01c", filename = "multiple_way_statistic.R")
#shows how to use this function for mixed desgin 2 way ANOVA
g1 = multiple_way_statistic(data = anova_data_sample,
                     dv = d,
                     wid = participant, 
                     within = c(head_tail), #depandent variable
                     between = Fgroup, #indepandent variable    
                     ylabs<-"slope", 
                     xlabs<-"",
                     fill_color<-c("gray","gray30"),
                     detailed = TRUE)
##             Effect                                            
## 1      (Intercept) F(1, 17) = 5.85, p = .027, petasq = .26 *  
## 2           Fgroup F(1, 17) = 0.27, p = .610, petasq = .02    
## 3        head_tail F(1, 17) = 8.19, p = .011, petasq = .33 *  
## 4 Fgroup:head_tail F(1, 17) = 2.82, p = .111, petasq = .14

4. plot_FFT.R

#load sample data
rm(list = ls())
pistol = read.csv("https://raw.githubusercontent.com/andychuangkl/sample_file/master/plotFFT.csv",header = T)[,-c(1)]
#load multiple_way_statistic.R function
devtools::source_gist(id = "2c8fe35bab19ece40f74c68e1ae672ce", filename = "plotFFT.R")
devtools::source_gist("a17c23e19554049be0d455560014e0c4" ,
                      filename ="theme_apa.R" )
#create data
p = which(diff(diff(pistol$acc_x.1))>0.1)[1]-4999
pistol = pistol[p:(p+4999),]
ffa_time = pistol$Time
ffa_data = pistol$acc_x.1
plot(ffa_data)

#use plotFFT() function now !! 
d = plotFFT(ffa_time, #data time scale
            ffa_data, #data
            1500, #sampling frequence
            plotFreqs = 200, #plot frequence 
            dominant_frequency_order = 1, #choose number 1 of dominant frequency
            PSD = T) #use