2.Identify the study design of the ergoStool example and replicate the results of analysis reported.

require(nlme)
## Loading required package: nlme
require(lme4)
## Loading required package: lme4
## Loading required package: Matrix
## 
## Attaching package: 'lme4'
## The following object is masked from 'package:nlme':
## 
##     lmList
require(ggplot2)
## Loading required package: ggplot2
dta<-ergoStool
str(dta)
  Classes 'nffGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame':    36 obs. of  3 variables:
   $ effort : num  12 15 12 10 10 14 13 12 7 14 ...
   $ Type   : Factor w/ 4 levels "T1","T2","T3",..: 1 2 3 4 1 2 3 4 1 2 ...
   $ Subject: Ord.factor w/ 9 levels "8"<"5"<"4"<"9"<..: 8 8 8 8 9 9 9 9 6 6 ...
   - attr(*, "formula")=Class 'formula'  language effort ~ Type | Subject
    .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
   - attr(*, "labels")=List of 2
    ..$ x: chr "Type of stool"
    ..$ y: chr "Effort required to arise"
   - attr(*, "units")=List of 1
    ..$ y: chr "(Borg scale)"
   - attr(*, "FUN")=function (x)  
    ..- attr(*, "source")= chr "function (x) mean(x, na.rm = TRUE)"
   - attr(*, "order.groups")= logi TRUE
#plot_Type
ggplot(data = dta, aes(x = Type, y = effort, color = Type)) +
  stat_summary(fun.y = mean, geom = "point", size = 2) +
  stat_summary(fun.data = mean_se, geom = "errorbar",
               linetype = "solid", width = .2) +
  coord_flip()+
  theme_bw()

#plot_Subject
ggplot(data = dta, aes(x = Subject, y = effort, color = Subject)) +
  stat_summary(fun.y = mean, geom = "point", size = 2) +
  stat_summary(fun.data = mean_se, geom = "errorbar",
               linetype = "solid", width = .2) +
  coord_flip()+
  theme_bw()

# Means
tapply(dta$effort, dta$Type, mean)
         T1        T2        T3        T4 
   8.555556 12.444444 10.777778  9.222222
tapply(dta$effort, dta$Subject, mean)
      8     5     4     9     6     3     7     1     2 
   8.25  8.50  9.25 10.00 10.25 10.75 10.75 12.25 12.25
#One within-subjects design 
summary(m0 <- lmer(effort ~ Type + (1 | Subject), data = dta))
  Linear mixed model fit by REML ['lmerMod']
  Formula: effort ~ Type + (1 | Subject)
     Data: dta
  
  REML criterion at convergence: 121.1
  
  Scaled residuals: 
       Min       1Q   Median       3Q      Max 
  -1.80200 -0.64317  0.05783  0.70100  1.63142 
  
  Random effects:
   Groups   Name        Variance Std.Dev.
   Subject  (Intercept) 1.775    1.332   
   Residual             1.211    1.100   
  Number of obs: 36, groups:  Subject, 9
  
  Fixed effects:
              Estimate Std. Error t value
  (Intercept)   8.5556     0.5760  14.853
  TypeT2        3.8889     0.5187   7.498
  TypeT3        2.2222     0.5187   4.284
  TypeT4        0.6667     0.5187   1.285
  
  Correlation of Fixed Effects:
         (Intr) TypeT2 TypeT3
  TypeT2 -0.450              
  TypeT3 -0.450  0.500       
  TypeT4 -0.450  0.500  0.500
#95% CI
confint(m0, oldNames = FALSE)
  Computing profile confidence intervals ...
                              2.5 %   97.5 %
  sd_(Intercept)|Subject  0.7342354 2.287261
  sigma                   0.8119798 1.390104
  (Intercept)             7.4238425 9.687269
  TypeT2                  2.8953043 4.882473
  TypeT3                  1.2286377 3.215807
  TypeT4                 -0.3269179 1.660251