## score1 score2 change active
## Min. : 7.00 Min. : 0.00 Min. : 0.0 "1":29
## 1st Qu.: 9.25 1st Qu.: 4.00 1st Qu.: 0.0 "2":21
## Median :10.00 Median : 6.00 Median : 3.5
## Mean : 9.58 Mean : 6.08 Mean : 3.5
## 3rd Qu.:10.00 3rd Qu.: 9.75 3rd Qu.: 6.0
## Max. :10.00 Max. :10.00 Max. :10.0
The variable βchange" contains the difference between the patientβs rating before the application of the device and the rating after the application. The sample average of this variable is reported as the βMean" for this variable and is equal to 3.5.
The variable βactive" is a factor. Observe that the summary of this variable lists the two levels of the variable and the frequency of each level. Indeed, the levels are coded with numbers but, nonetheless, the variable is a factor[^12].
Based on the hint we know that the expressions βchange[1:29]" and βchange[30:50]" produce the values of the variable βchange" for the patients that were treated with active magnets and by inactive placebo, respectively. We apply the function βmean" to these sub-sequences:
The sample average for the patients that were treated with active magnets is 5.241379 and sample average for the patients that were treated with inactive placebo is 1.095238.
The sample standard deviation for the patients that were treated with active magnets is 3.236568 and sample standard deviation for the patients that were treated with inactive placebo is 1.578124.
The first box-plot corresponds to the sub-sequence of the patients that received an active magnet. There are no outliers in this plot. The second box-plot corresponds to the sub-sequence of the patients that received an inactive placebo. Three values, the values β3", β4", and β5" are associated with outliers. Let us see what is the total number of observations that receive these values:
One may see that a single observation obtained the value β3", another one obtained the value β5" and 2 observations obtained the value β4", a total of 4 outliers[^13]. Notice that the single point that is associated with the value β4" actually represents 2 observations and not one.
Observe that each iteration of the simulation involves the generation of two samples. One sample is of size 29 and it is generated from the \(\mathrm{Normal}(3.5,3^2)\) distribution and the other sample is of size 21 and it is generated from the \(\mathrm{Normal}(3.5,1.5^2)\) distribution. The sample average and the sample variance are computed for each sample. The test statistic is computed based on these averages and variances and it is stored in the appropriate position of the sequence βtest.stat".
The values of the sequence βtest.stat" at the end of all the iterations represent the sampling distribution of the static. The application of the function βquantile" to the sequence gives the 0.025-percentiles and the 0.975-percentiles of the sampling distribution, which are -2.014838 and 2.018435. It follows that the interval \([-2.014838, 2.018435]\) contains about 95% of the sampling distribution of the statistic.
In order to evaluate the statistic for the given data set we apply the same steps that were used in the simulation for the computation of the statistic:
In the first line we compute the sample average for the first 29 patients and in the second line we compute it for the last 21 patients. In the third and fourth lines we do the same for the sample variances of the two types of patients. Finally, in the fifth line we evaluate the statistic. The computed value of the statistic turns out to be 5.985601, a value that does not belong to the interval \([-2.014838, 2.018435]\text{.}\)