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

(Difference between revisions)
 Revision as of 18:37, 27 October 2013 (view source) (→Fabiana: tests on smoothing and first differentials for local mins maxs)← Previous diff Current revision (19:54, 25 November 2013) (view source)m (→General Entries: fixed embedded tweet) (6 intermediate revisions not shown.) Line 6: Line 6: | colspan="2"| | colspan="2"| + + __TOC__ + + =General Entries= =General Entries= - * Insert content here... + * 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... [[User:M Fabiana Kubke|MF Kubke]] 19:42, 27 October 2013 (EDT) + + + + + + + =Personal Entries= =Personal Entries= ==Fabiana== ==Fabiana== - *Enter content here + *From file 2013-10-28-MFK.Rmd - + - + - +

Current revision

Hearing development in barn owls Main project page
Previous entry      Next entry

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"
## [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"
## [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")
``````
``````##   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)
``````
``````##   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")
``````
``````##   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]))
``````
``````##   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")
``````

(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")
``````

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")
``````

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")
``````

``````
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")
``````

``````
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")
``````

``````
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")
``````

``````
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")
``````

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