twoRateFit: Fit the two-rate model to reach deviations.

View source: R/models.R

twoRateFitR Documentation

Fit the two-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

twoRateFit(
  schedule,
  reaches,
  gridpoints = 6,
  gridfits = 6,
  checkStability = FALSE
)

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.

checkStability

Only stable solutions will be allowed.

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: - Ls: the slow learning rate - Lf: the fast learning rate - Rs: the slow retention rate - Rf: the fast 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 = 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))


thartbm/handlocs documentation built on Feb. 18, 2025, 10:53 p.m.