# fitTwoRateReachModel: Fit the Two-Rate Model To a Dataset. In thartbm/RateRate: Evaluate and Fit the Two-Rate Model of Motor Learning

## Description

Fit Smith et al's (2006) Two-Rate Model to a set of reach deviations and a perturbation schedule.

## Usage

 ```1 2 3``` ```fitTwoRateReachModel(reaches, schedule, oneTwoRates = 2, verbose = FALSE, grid = "uniform", gridsteps = 7, checkStability = TRUE, method = "NM", fnscale = 1) ```

## Arguments

 `reaches` A sequence of reach deviations. `schedule` A sequence of feedback manipulations. `oneTwoRates` How many processes to fit? (1 or 2) `verbose` Should detailed information be outputted during the fitting? `grid` How are parameters values for grid search distributed in [0,1]? One of 'uniform' (default), 'restricted' or 'skewed'. `gridsteps` How many values of each parameter are used in grid search? `checkStability` Use additional stability constraints? (default=TRUE) `method` Fitting method, currently one of "Nelder-Mead" (default and very robust, also 'NM', a linear optimization method) or "BFGS" (a quasi-Newton, non-linear method, also 'QN' or 'Quasi-Newton'). See `optim` for details. `fnscale` Fitting is done on function/fnscale, where fnscale is already multiplied by -1 to make it an optimization where appropriate. By default it is set to 1. To make different schedules more comparable, use the largest deviation from zero in the schedule; fnscale=max(abs(schedule), na.rm=T). See `optim` for details.

## Details

This function runs a grid search first, and picks the best 5 are fit with least square optimization after which the best fit is returned. Mean squared error, as given by `twoRateReachModelErrors` is used to determine quality of fit.

The sequences of `reaches` and the `schedule` should have the same length. NAs in the `reaches` will be ignored, but in the `schedule` they indicate error-clamp trials.

The model prediction base on the parameters can be retrieved by evaluating them, based on the perturbation schedule, with `twoRateReachModel`.

In the Two-Rate Model of motor learning, the motor output X on a trial t, is the sum of the output of a slow and fast process:

X(t) = Xs(t) + Xf(t)

And each of these two processes retain part of their previous learning and learn from previous errors:

Xs(t) = Rs . Xs(t-1) + Ls . E(t-1)

Xf(t) = Rf . Xf(t-1) + Lf . E(t-1)

The four parameters Rs, Ls, Rf and Lf are returned, except when a one-process fit is requested, in which case only Rs and Ls are fit.

## Value

The set of parameters that minimizes the difference between model output and the `reaches` given the perturbation `schedule`.

## See Also

`twoRateReachModelErrors` and `twoRateReachModel`

Smith MA, Ghazizadeh A, Shadmehr R (2006). Interacting Adaptive Processes with Different Timescales Underlie Short-Term Motor Learning. PLoS Biol. 2006 Jun;4(6):e179. https://doi.org/10.1371/journal.pbio.0040179

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11``` ```data("RotAdapt") param <- fitTwoRateReachModel(RotAdapt\$reaches,RotAdapt\$schedule, method='BFGS') param tworatemodel <- twoRateReachModel(param, RotAdapt\$schedule) str(tworatemodel) plot(RotAdapt\$reaches, ylim=c(-35,35), col='gray') lines(tworatemodel\$total) lines(tworatemodel\$slow, col='blue') lines(tworatemodel\$fast, col='red') ```

thartbm/RateRate documentation built on Oct. 15, 2018, 3:10 p.m.