1 load package

pacman::p_load(lattice, tidyverse, nlme, nlstools)

2 input data

dta1 <-  read.table("freeRecall.asc.txt", header = T)

names(dta1) <- c("Group","Trial","CorrectN")

str(dta1)
## 'data.frame':    20 obs. of  3 variables:
##  $ Group   : chr  "C" "C" "C" "C" ...
##  $ Trial   : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ CorrectN: num  7.9 10.9 11.9 13 14.2 14.2 14.7 15.1 14.8 15.2 ...
ot <- theme_set(theme_bw())

3 descriptive

ggplot(dta1, aes(Trial, CorrectN, color = Group)) +
 geom_point(size = rel(2)) +
 geom_line() +
 labs(x = "Trial on list B", y = "Mean number of correct responses")+
 scale_x_continuous(limits = c(0, 10), breaks = seq(0, 10, by = 2)) +
 scale_y_continuous(limits = c(5, 20), breaks = seq(5, 20, by = 5)) +
 guides(color = guide_legend(reverse = T)) +
 theme(legend.position = c(.9,.2))  

4 model

#  guess the initial values for parameters
summary(lm(CorrectN  ~ sqrt(Trial), data = dta1))
## 
## Call:
## lm(formula = CorrectN ~ sqrt(Trial), data = dta1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.5212 -0.3627  0.2132  0.3667  1.2788 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   8.0441     0.6416  12.538 2.48e-10 ***
## sqrt(Trial)   2.3771     0.2736   8.689 7.41e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8223 on 18 degrees of freedom
## Multiple R-squared:  0.8075, Adjusted R-squared:  0.7968 
## F-statistic: 75.51 on 1 and 18 DF,  p-value: 7.405e-08

CorrectN = 8.04 + 2.3sqrt(Trial),套在這個公式aexp(bsqrt(Trial)應該是8*1.3倍左右的一個曲線。所以,a猜8,b應該=1/exp(2.3)

# fit the model
library(stats)
summary(m0 <- nls(CorrectN ~ a*exp(b*sqrt(Trial)), data = dta1,
                  start = list(a=8, b=0.1)))
## 
## Formula: CorrectN ~ a * exp(b * sqrt(Trial))
## 
## Parameters:
##   Estimate Std. Error t value Pr(>|t|)    
## a  8.92938    0.50253  17.769 7.34e-13 ***
## b  0.17715    0.02269   7.806 3.47e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.864 on 18 degrees of freedom
## 
## Number of iterations to convergence: 4 
## Achieved convergence tolerance: 2.604e-06

5 Fitted plot

ggplot(dta1, aes(Trial, CorrectN, color = Group)) +
  geom_smooth(method="nls", 
              formula = y ~ a*exp(b*sqrt(x)), 
              method.args=list(start=c(a=8, b=0.1)), 
              se=FALSE, size=rel(.5)) +
  geom_point(pch = 1, size = rel(2)) +
  scale_x_continuous(limits = c(0, 10), breaks = seq(0, 10, by = 2)) +
  scale_y_continuous(limits = c(5, 20), breaks = seq(5, 20, by = 5)) +
  labs(x = "Trial on list B", 
       y = "Mean number of correct responses")