twoRateFit | R Documentation |
This function is part of a set of functions to fit and evaluate the two-rate model of motor learning.
twoRateFit(
schedule,
reaches,
gridpoints = 6,
gridfits = 6,
checkStability = FALSE
)
schedule |
A vector of length N with the perturbation schedule. |
reaches |
A vector of length N with reach deviation data. |
gridpoints |
Number of values used for each parameters in a gridfit. |
gridfits |
Number of best gridfits to use in MSE fit. |
checkStability |
Only stable solutions will be allowed. |
?
A named numeric vector with the optimal parameters that fit the two rate model to the data as best as possible, with these elements: - Ls: the slow learning rate - Lf: the fast learning rate - Rs: the slow retention rate - Rf: the fast retention rate
# there is example data in this package:
data("tworatedata")
# first we baseline it, and get a median for every trial:
baseline <- function(reachvector,blidx) reachvector - mean(reachvector[blidx], na.rm=TRUE)
tworatedata[,4:ncol(tworatedata)] <- apply(tworatedata[,4:ncol(tworatedata)],
FUN=baseline,
MARGIN=c(2),
blidx=c(17:32))
reaches <- apply(tworatedata[4:ncol(tworatedata)], FUN=median, MARGIN=c(1), na.rm=TRUE)
# and we extract the schedule:
schedule <- tworatedata$schedule
# now we can fit the model to the reaches, given the schedule:
par = twoRateFit(schedule, reaches)
# and plot that:
model <- twoRateModel(par=par, schedule=schedule)
plot(reaches,
type='l', col='#333333',
xlab='trial', ylab='reach deviation [deg]',
xlim=c(0,165), ylim=c(-35,35),
bty='n', ax=FALSE)
lines(c(1,33,33,133,133,145,145),c(0,0,30,30,-30,-30,0),col='#AAAAAA')
lines(c(145,164),c(0,0),col='#AAAAAA',lty=2)
lines(model$slow,col='blue')
lines(model$fast,col='red')
lines(model$total,col='purple')
axis(1,c(1,32,132,144,164),las=2)
axis(2,c(-30,-15,0,15,30))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.