Kubke Lab:Research/ABR/Notebook/2013/10/28

From OpenWetWare

Jump to: navigation, search
Hearing development in barn owls Main project page
Previous entry      Next entry

Contents


General Entries

  • Tried a couple of methods for smoothing the V(t) data to use for analysis. Data is noisy, but setting spar on smooth.spline seems to do the job - need to apply smooth.spline on the raw data and calculate the first derviative through diffV/difft. However, I am uncertain as to how to justify the actual value of spar. Seems that something around 0.25 does a pretty good job - but would like to have some way or rationalising what that value should be. One way might be to look at the noise on the spont trace, and extract from there some value of noise that I can then use to determine spar? Mmmm... MF Kubke 19:42, 27 October 2013 (EDT)


Personal Entries

Fabiana

  • From file 2013-10-28-MFK.Rmd

Trying to get case name from user

List the available folders and prompt user to choose case:

dir()
##  [1] "2013-10-27-MFK.Rmd"  "2013-10-27.html"     "2013-10-27.R"       
##  [4] "2013-10-27.txt"      "2013-10-28-MFK.html" "2013-10-28-MFK.md"  
##  [7] "2013-10-28-MFK.Rmd"  "Copy189L0A.ABR"      "Copy224l0a.txt"     
## [10] "Copy233L0B.ABR.log"  "Copy233L0B.ABR.txt"  "figure"             
## [13] "knitr-testr.html"    "knitr-testr.md"      "knitr-testr.Rmd"    
## [16] "kntR2.html"          "kntR2.md"            "kntR2.Rmd"          
## [19] "my first knitr.html" "my first knitr.md"   "my first knitr.Rmd" 
## [22] "mydata_new"          "mydata_new.txt"      "readrawabr.R"       
## [25] "Sandbox1.R"          "Sandbox1.txt"        "texput.log"
newdir <- readline("enter case number: ")
## enter case number:
print(newdir)
## [1] ""

I can use this then to change the wd() to where the new cases are.

basedir <- getwd()
casedir <- paste(basedir, newdir, sep = "/")
setwd(casedir)
dir()  #test
##  [1] "2013-10-27-MFK.Rmd"  "2013-10-27.html"     "2013-10-27.R"       
##  [4] "2013-10-27.txt"      "2013-10-28-MFK.html" "2013-10-28-MFK.md"  
##  [7] "2013-10-28-MFK.Rmd"  "Copy189L0A.ABR"      "Copy224l0a.txt"     
## [10] "Copy233L0B.ABR.log"  "Copy233L0B.ABR.txt"  "figure"             
## [13] "knitr-testr.html"    "knitr-testr.md"      "knitr-testr.Rmd"    
## [16] "kntR2.html"          "kntR2.md"            "kntR2.Rmd"          
## [19] "my first knitr.html" "my first knitr.md"   "my first knitr.Rmd" 
## [22] "mydata_new"          "mydata_new.txt"      "readrawabr.R"       
## [25] "Sandbox1.R"          "Sandbox1.txt"        "texput.log"

I should then read the files in and go back to base dir so that I can call the functions. Another way of going about this

dir.create(file.path(basedir, casedir), showWarnings = FALSE)
setwd(file.path(basedir, casedir))
## Error: cannot change working directory

Try to smooth the ABR trace and calculate local max and min

mydatanew <- read.table("mydata_new")
head(mydatanew)
##   msec left right spont  bin
## 1 0.00 1000  1000  1000 1000
## 2 0.02 1000  1000  1000 1000
## 3 0.04 1000  1000  1000 1000
## 4 0.06 1000  1000  1000 1000
## 5 0.08 1000  1000  1000 1000
## 6 0.10 1000  1000  1000 1000

Realised that after adding the bincomp column to the datafile, I forgot to overwrite the data file - so mydata_new still had the original variables but not the new one - fixing that.

mydata <- read.table("Copy233L0B.ABR.txt", header = T)
head(mydata)  #passed test
##   msec left right spont  bin
## 1 0.00 1000  1000  1000 1000
## 2 0.02 1000  1000  1000 1000
## 3 0.04 1000  1000  1000 1000
## 4 0.06 1000  1000  1000 1000
## 5 0.08 1000  1000  1000 1000
## 6 0.10 1000  1000  1000 1000
write.table(mydata, "mydata_new")
mydata_new <- read.table("mydata_new", header = T)
head(mydata_new)  #passed test
##   msec left right spont  bin
## 1 0.00 1000  1000  1000 1000
## 2 0.02 1000  1000  1000 1000
## 3 0.04 1000  1000  1000 1000
## 4 0.06 1000  1000  1000 1000
## 5 0.08 1000  1000  1000 1000
## 6 0.10 1000  1000  1000 1000
mydata_new$bincomp[1:1000] <- (mydata_new$bin[1:1000] - (mydata_new$left[1:1000] + 
    mydata_new$right[1:1000]))
head(mydata_new)
##   msec left right spont  bin bincomp
## 1 0.00 1000  1000  1000 1000   -1000
## 2 0.02 1000  1000  1000 1000   -1000
## 3 0.04 1000  1000  1000 1000   -1000
## 4 0.06 1000  1000  1000 1000   -1000
## 5 0.08 1000  1000  1000 1000   -1000
## 6 0.10 1000  1000  1000 1000   -1000
write.table(mydata_new, "mydata_new.txt")  #passed test

Now I have a working file that is separate from the original one which I can put in the analysis folder (not sure I really want that in the end, but ok for now)

Options:

diff function

Tried the diff function - but (unsurprisingly) I get heaps of noise

mydata_new$diffleft[2:1000] <- diff(mydata_new$left)/diff(mydata_new$msec)
par(mfrow = c(1, 2))
plot(mydata_new[c(1, 2)], type = "l", main = "original left")
plot(mydata_new[c(1, 7)], ylim = c(-3000, 3000), type = "l", main = "firs diff of left")

plot of chunk unnamed-chunk-6

(Need to bound to [2:1000] because the diff function returns N-1 values. )

smooth.spline

Trying smooth.spline. Trying to smooth on the diff doesnt work probably because of infinite values.

The smooth.spline gives me a rather noisy plot

test <- smooth.spline(mydata_new$msec, mydata_new$left)
par(mfrow = c(1, 3))
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "splined left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-7

but can smoot by setting spar to some value other than NULL

test <- smooth.spline(mydata_new$msec, mydata_new$left, spar = 0.5)
par(mfrow = c(1, 3))
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-8

Comparisons of different spar values:


par(mfrow = c(1, 3))
test <- smooth.spline(mydata_new$msec, mydata_new$left)
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "spar = NULL on left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-9


par(mfrow = c(1, 3))
test <- smooth.spline(mydata_new$msec, mydata_new$left, spar = 0.25)
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "spar = 0.25 on left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-9


par(mfrow = c(1, 3))
test <- smooth.spline(mydata_new$msec, mydata_new$left, spar = 0.5)
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "spar = 0.5 on left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-9


par(mfrow = c(1, 3))
test <- smooth.spline(mydata_new$msec, mydata_new$left, spar = 0.75)
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "spar = 0.75 on left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-9


par(mfrow = c(1, 3))
test <- smooth.spline(mydata_new$msec, mydata_new$left, spar = 1)
plot(mydata_new$msec, mydata_new$left, type = "l", main = "original left")
plot(test$x, test$y, type = "l", main = "spar = 1 on left")
mydata_new$diffleft2[2:1000] <- diff(test$y)/diff(test$x)
plot(mydata_new$msec, mydata_new$diffleft2, ylim = c(-3000, 3000), type = "l", 
    main = "first diff of splined left")

plot of chunk unnamed-chunk-9

Package ppc from http://www-stat.stanford.edu/~tibs/PPC/Rdist/index.html => seem to be unable to install package - get an error that it is not an OS X binary package

http://finzi.psych.upenn.edu/R/library/ppc/html/ppc.peaks.html

Trying package zoo

Andy

  • Enter content here

Oris

  • Enter content here


Personal tools