Proliminaries

install.packages(c("MASS", "psychTools"), repos = "https://cloud.r-project.org")
## Installing packages into 'C:/Users/bbonillabart/AppData/Local/R/win-library/4.4'
## (as 'lib' is unspecified)
## package 'MASS' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'MASS'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\bbonillabart\AppData\Local\R\win-library\4.4\00LOCK\MASS\libs\x64\MASS.dll
## to
## C:\Users\bbonillabart\AppData\Local\R\win-library\4.4\MASS\libs\x64\MASS.dll:
## Permission denied
## Warning: restored 'MASS'
## package 'psychTools' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\bbonillabart\AppData\Local\Temp\RtmpI3PPBE\downloaded_packages
library(MASS)
## Warning: package 'MASS' was built under R version 4.4.3
library(psychTools)
## Warning: package 'psychTools' was built under R version 4.4.3
library(lsr)
## Warning: package 'lsr' was built under R version 4.4.3
library(sciplot)
help(anorexia)
## starting httpd help server ... done
head(anorexia)
##   Treat Prewt Postwt
## 1  Cont  80.7   80.2
## 2  Cont  89.4   80.1
## 3  Cont  91.8   86.4
## 4  Cont  74.0   86.3
## 5  Cont  78.1   76.1
## 6  Cont  88.3   78.1

Question 1

head(anorexia)
##   Treat Prewt Postwt
## 1  Cont  80.7   80.2
## 2  Cont  89.4   80.1
## 3  Cont  91.8   86.4
## 4  Cont  74.0   86.3
## 5  Cont  78.1   76.1
## 6  Cont  88.3   78.1
t.test(anorexia$Prewt, anorexia$Postwt)
## 
##  Welch Two Sample t-test
## 
## data:  anorexia$Prewt and anorexia$Postwt
## t = -2.4528, df = 121.36, p-value = 0.0156
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.9946831 -0.5330947
## sample estimates:
## mean of x mean of y 
##  82.40833  85.17222

By doing a Two Sample T-Test we can see that t-value is about -2.5, the df is 121.4, and the p-value is small being 0.02. There is also a confidence of 95 percent meaning the means should lie (-4.9946831 -0.5330947). Furthermore we see the means are about 82.4 and 85.2. The direction of change is an increase and we see this since the magnitude of change is 2.8 (85.2-82.4).

Question 2

anorexia$diff <- anorexia$Postwt - anorexia$Prewt
head(anorexia)
##   Treat Prewt Postwt  diff
## 1  Cont  80.7   80.2  -0.5
## 2  Cont  89.4   80.1  -9.3
## 3  Cont  91.8   86.4  -5.4
## 4  Cont  74.0   86.3  12.3
## 5  Cont  78.1   76.1  -2.0
## 6  Cont  88.3   78.1 -10.2
rt.anova.1 <-aov(anorexia$diff ~ anorexia$Treat)
TukeyHSD(rt.anova.1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = anorexia$diff ~ anorexia$Treat)
## 
## $`anorexia$Treat`
##               diff       lwr       upr     p adj
## Cont-CBT -3.456897 -8.327276  1.413483 0.2124428
## FT-CBT    4.257809 -1.250554  9.766173 0.1607461
## FT-Cont   7.714706  2.090124 13.339288 0.0045127

I used ANOVA and Tukey from unit 7 because it would show every treatment.The results showed no significant difference in weight change between the Cont-CBT (p = 0.212) or with FT-CBT (p = 0.1607). However, there was a statistically significant difference with FT-Cont (p = 0.0045), which shows that that FT-Cont led to a difference in weight.

Question 3

head(anorexia)
##   Treat Prewt Postwt  diff
## 1  Cont  80.7   80.2  -0.5
## 2  Cont  89.4   80.1  -9.3
## 3  Cont  91.8   86.4  -5.4
## 4  Cont  74.0   86.3  12.3
## 5  Cont  78.1   76.1  -2.0
## 6  Cont  88.3   78.1 -10.2
bargraph.CI(x.factor = anorexia$Treat,
response = anorexia$diff,
ci.fun = ciMean, ylim = c(0,25),
legend = T, conf.level = .95)
## Warning in plot.window(xlim, ylim, log = log, ...): "conf.level" is not a
## graphical parameter
## Warning in axis(if (horiz) 2 else 1, at = at.l, labels = names.arg, lty =
## axis.lty, : "conf.level" is not a graphical parameter
## Warning in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...):
## "conf.level" is not a graphical parameter
## Warning in axis(if (horiz) 1 else 2, cex.axis = cex.axis, ...): "conf.level" is
## not a graphical parameter

results<-bargraph.CI(x.factor = anorexia$Treat,
response = anorexia$diff,
ci.fun = ciMean, ylim = c(0,25),
legend = T, conf.level = .95)
## Warning in plot.window(xlim, ylim, log = log, ...): "conf.level" is not a
## graphical parameter
## Warning in axis(if (horiz) 2 else 1, at = at.l, labels = names.arg, lty =
## axis.lty, : "conf.level" is not a graphical parameter
## Warning in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...):
## "conf.level" is not a graphical parameter
## Warning in axis(if (horiz) 1 else 2, cex.axis = cex.axis, ...): "conf.level" is
## not a graphical parameter

rt.anova.1 <-aov(anorexia$diff ~ anorexia$Treat)
TukeyHSD(rt.anova.1)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = anorexia$diff ~ anorexia$Treat)
## 
## $`anorexia$Treat`
##               diff       lwr       upr     p adj
## Cont-CBT -3.456897 -8.327276  1.413483 0.2124428
## FT-CBT    4.257809 -1.250554  9.766173 0.1607461
## FT-Cont   7.714706  2.090124 13.339288 0.0045127

It honestly depends, I say that CBT is good since the MOE is more narrow compared to FT but FT is bigger so it could compensate for the MOE I think it depends on what the person would specifically prefer.

Question 4

help(epi.bfi)
head(epi.bfi)
##   epiE epiS epiImp epilie epiNeur bfagree bfcon bfext bfneur bfopen bdi
## 1   18   10      7      3       9     138    96   141     51    138   1
## 2   16    8      5      1      12     101    99   107    116    132   7
## 3    6    1      3      2       5     143   118    38     68     90   4
## 4   12    6      4      3      15     104   106    64    114    101   8
## 5   14    6      5      3       2     115   102   103     86    118   8
## 6    6    4      2      5      15     110   113    61     54    149   5
##   traitanx stateanx
## 1       24       22
## 2       41       40
## 3       37       44
## 4       54       40
## 5       39       67
## 6       51       38
head(epi.bfi)
##   epiE epiS epiImp epilie epiNeur bfagree bfcon bfext bfneur bfopen bdi
## 1   18   10      7      3       9     138    96   141     51    138   1
## 2   16    8      5      1      12     101    99   107    116    132   7
## 3    6    1      3      2       5     143   118    38     68     90   4
## 4   12    6      4      3      15     104   106    64    114    101   8
## 5   14    6      5      3       2     115   102   103     86    118   8
## 6    6    4      2      5      15     110   113    61     54    149   5
##   traitanx stateanx
## 1       24       22
## 2       41       40
## 3       37       44
## 4       54       40
## 5       39       67
## 6       51       38
boxplot(epi.bfi$traitanx~epi.bfi$bfext,ylim=c(20,70))

head(anorexia)
##   Treat Prewt Postwt  diff
## 1  Cont  80.7   80.2  -0.5
## 2  Cont  89.4   80.1  -9.3
## 3  Cont  91.8   86.4  -5.4
## 4  Cont  74.0   86.3  12.3
## 5  Cont  78.1   76.1  -2.0
## 6  Cont  88.3   78.1 -10.2
t.test(epi.bfi$traitanx, epi.bfi$bfext)                   
## 
##  Welch Two Sample t-test
## 
## data:  epi.bfi$traitanx and epi.bfi$bfext
## t = -34.152, df = 288.62, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -66.80931 -59.52835
## sample estimates:
## mean of x mean of y 
##  39.00866 102.17749