oneRateFit: Fit the one-rate model to reach deviations.

View source: R/twoRateModel.R

oneRateFitR Documentation

Fit the one-rate model to reach deviations.

Description

This function is part of a set of functions to fit and evaluate the two-rate model of motor learning.

Usage

oneRateFit(schedule, reaches, gridpoints = 6, gridfits = 6)

Arguments

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.

Details

?

Value

A named numeric vector with the optimal parameters that fit the two rate model to the data as best as possible, with these elements: - L: the learning rate - R: the retention rate

Examples

# 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 = oneRateFit(schedule, reaches)

# and plot that:
model <- oneRateModel(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$process,col='purple')
axis(1,c(1,32,132,144,164),las=2)
axis(2,c(-30,-15,0,15,30))


thartbm/SMCL documentation built on Oct. 23, 2022, 5:17 a.m.