Description Usage Arguments Value Note Author(s) References Examples
Smooths single- or multi-channel electroencephalography (EEG) with respect to space and/or time. Uses the bigspline
, bigtps
, and bigssa
functions (from bigsplines
package) for smoothing.
1 2 3 |
voltage |
Vector of recorded EEG voltage at each row in |
space |
Matrix of electrode coordinates (in three-dimensions) at which EEG was recorded. If |
time |
Vector of time points at which EEG was recorded. If |
nknots |
Number of knots to sample for smoothing. Positive integer. |
rparm |
Rounding parameter(s) to use for smoothing. See Notes and Examples. |
lambdas |
Smoothing parameter(s) to use for smoothing. |
skip.iter |
If |
se.fit |
If |
rseed |
Random seed to use for knot selection. Set |
For temporal smoothing only: an object of class "bigspline" (see bigspline
).
For spatial smoothing only: an object of class "bigtps" (see bigtps
).
For spatial-temporal smoothing: an object of class "bigssa" (see bigssa
).
For temporal smoothing only (i.e., space=NULL
), the input rparm
should be a positive scalar less than 1. Larger values produce faster (but less accurate) approximations. Default is 0.01, which I recommend for temporal smoothing; rparm=0.005
may be needed for particuarly rough signals, and rparm=0.02
could work for smoother signals.
For spatial smoothing only (i.e., time=NULL
), the input rparm
should be a positive scalar giving the rounding unit for the spatial coordinates. For example, rparm=0.1
rounds each coordinate to the nearest 0.1 (same as round(space,1)
).
For spatial-temporal smoothing (i.e., both space
and time
are non-null), the input rparm
should be a list of the form rparm=list(space=0.1,time=0.01)
, where the 0.1 and 0.01 can be replaced by your desired rounding parameters.
Setting rparm=NA
will use the full data solution; this is more computationally expensive, and typically produces a solution very similar to using rparm=0.01
(see references).
Nathaniel E. Helwig <helwig@umn.edu>
Helwig, N. E. (2013). Fast and stable smoothing spline analysis of variance models for large samples with applications to electroencephalography data analysis. Unpublished doctoral dissertation. University of Illinois at Urbana-Champaign.
Helwig, N.E. (2015). bigsplines: Smoothing Splines for Large Samples. http://CRAN.R-project.org/package=bigsplines
Helwig, N. E. & Ma, P. (2015). Fast and stable multiple smoothing parameter selection in smoothing spline analysis of variance models with large samples. Journal of Computational and Graphical Statistics, 24(3), 715-732.
Helwig, N. E. & Ma, P. (2016). Smoothing spline ANOVA for super large samples: Scalable computation via rounding parameters. Statistics and Its Interface, 9(4), 433-444.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | ########## EXAMPLE 1: Temporal ##########
# get "PZ" electrode of "c" subjects in "eegdata" data
data(eegdata)
idx <- which(eegdata$channel=="PZ" & eegdata$group=="c")
eegdata <- eegdata[idx,]
# temporal smoothing
eegmod <- eegsmooth(eegdata$voltage,time=eegdata$time)
# define data for prediction
time <- seq(min(eegdata$time),max(eegdata$time),length.out=100)
yhat <- predict(eegmod,newdata=time,se.fit=TRUE)
# plot results using eegtime
eegtime(time*1000/255,yhat$fit,voltageSE=yhat$se.fit,ylim=c(-4,4),main="Pz")
########## EXAMPLE 2: Spatial ##########
# get time point 65 (approx 250 ms) of "c" subjects in "eegdata" data
data(eegdata)
idx <- which(eegdata$time==65L & eegdata$group=="c")
eegdata <- eegdata[idx,]
# remove ears, nose, and reference (Cz)
idx <- c(which(eegdata$channel=="X"),which(eegdata$channel=="Y"),
which(eegdata$channel=="nd"),which(eegdata$channel=="Cz"))
eegdata <- eegdata[-idx,]
# match to eeg coordinates
data(eegcoord)
cidx <- match(eegdata$channel,rownames(eegcoord))
# spatial smoothing
eegmod <- eegsmooth(eegdata$voltage,space=eegcoord[cidx,1:3])
# use dense cap for prediction
mycap <- levels(factor(eegdata$channel))
ix <- eegcapdense(mycap,type="2d",index=TRUE)
data(eegdense)
space <- eegdense[ix,1:3]
yhat <- predict(eegmod,newdata=space)
# plot results using eegspace
#eegspace(space,yhat)
eegspace(eegdense[ix,4:5],yhat)
########## EXAMPLE 3: Spatial-Temporal (not run) ##########
# # get "c" subjects of "eegdata" data
# data(eegdata)
# idx <- which(eegdata$group=="c")
# eegdata <- eegdata[idx,]
# # remove ears, nose, and reference (Cz)
# idx <- c(which(eegdata$channel=="X"),which(eegdata$channel=="Y"),
# which(eegdata$channel=="nd"),which(eegdata$channel=="Cz"))
# eegdata <- eegdata[-idx,]
# # match to eeg coordinates
# data(eegcoord)
# cidx <- match(eegdata$channel,rownames(eegcoord))
# # spatial-temporal smoothing
# eegmod <- eegsmooth(eegdata$voltage,space=eegcoord[cidx,1:3],time=eegdata$time)
# # time main effect
# newdata <- list(time=seq(min(eegdata$time),max(eegdata$time),length.out=100))
# yhat <- predict(eegmod,newdata=newdata,se.fit=TRUE,include="time")
# eegtime(newdata$time,yhat$fit,voltageSE=yhat$se.fit,ylim=c(-2,4),main="Time Main Effect")
# # space main effect
# mycap <- levels(factor(eegdata$channel))
# ix <- eegcapdense(mycap,type="2d",index=TRUE)
# data(eegdense)
# newdata <- list(space=eegdense[ix,1:3])
# yhat <- predict(eegmod,newdata=newdata,include="space")
# eegspace(newdata$space,yhat)
# # interaction effect (spatial map at time point 65)
# newdata <- list(space=eegdense[ix,1:3],time=rep(65,nrow(eegdense[ix,])))
# yhat <- predict(eegmod,newdata=newdata,include="space:time")
# eegspace(newdata$space,yhat)
# # full prediction (spatial map at time point 65)
# newdata <- list(space=eegdense[ix,1:3],time=rep(65,nrow(eegdense[ix,])))
# yhat <- predict(eegmod,newdata=newdata)
# eegspace(newdata$space,yhat)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.