The Importance of Client–Canine Contact in Canine-Assisted Interventions: A Randomized Controlled Trial

This document provides the R code and output for all analyses, as well as code for reproducing tables and figures in the manuscript. In addition to allowing for reviewing of the code, it also provides additional information that would not fit in the manuscript, such as figures and analyses conducted to evaluate test assumptions.

Analyses were conducted in R using Jupyter Hub.


Load Packages

User-defined Functions


This function has no impact on the analyses. I used it to format the numbers before putting them in a table.


This function does a paired samples t test and returns the result as a data.frame. Compares t2 to t1 and performs a directional test for the well-being measures and a two-sided test for the other measures.


This function conducts parallel analysis, which is generally considered the gold standard for determining the number of factors to retain in exploratory factor analysis. Used in the exploratory analyses.

ctt and multi_ctt

These stand for Classical Test Theory. They just give pretty output of classical test theory reliability analysis.

Data Import and Wrangling

The dataset being imported includes composite scores for all scales measures at pre-intervention, post-intervention, and at two-week follow-up.

Reshape the Data

This is just rearranging the data frame so that each measure is a column. This simplifies the code later by allowing us to apply a function to the data at each level of the measure column. The analyses are conducted using the dta_diff.

Scale Descriptives

These are descriptive values for each scale.

Note that the analyses were conducted on either change scores (H1 and H2) or the residual post-intervention score, after controlling for pre-test score. As such, the tests do not make any assumptions about the distributions of these measures. Values such as skew and kurtosis are provided for descriptive purposes.

Test Hypothesis 1

Research question: Does the intervention improve subjective well-being?

Hypothesis: Participants in each of the three conditions will report significant improvements in subjective well-being from pre-to-post intervention.

This was tested by conducting a paired samples t test comparing pre-to-post-intervention changes on each of the outcome measures. Directional tests were used for measures of well-being (flourishing, positive affect, social connectedness, happiness, and integration with campus community), and ill-being (stress, homesickness, loneliness, negative affect).

Descriptive Statistics

The paired samples t test is just a one-sample t test conducted on the change scores. So, the assumptions of the test are about the change scores. Below are descriptive statistics for the change scores.


Histograms of the difference scores.

Create a Pretty Table of the Results for H1

The code below simply formats the results so that they look nice and can be copied and pasted into MS Word to create a table, without having to manually enter the table data (which is time consuming and prone to human error).

Copy and paste this output into MS Word, and then use Insert > Table > Convert Text to Table. There is still some formatting that needs to be done, but not much!

Figure for H1

The code below creates the figure used in the manuscript (although using a different font).


Q–Q Plots

These plots show the relationship between the theoretical quantiles (i.e., normally distributed residuals) and the sample quantiles. If the sample residuals are normally distributed, the theoretical and sample quantiles should fall along the line.

Results of the ANCOVAs and Planned Contrasts

Exploratory Analyses

Controlling for Pet Ownership

Pet ownership was imbalanced between groups and could affect the outcome of the intervention. Are the results different if we control for pet ownership?

Composite Measure

Can we treat the ill-being and well-being items as measuring the same construct?

Exploratory Factor Analysis

With all Variables

This is an EFA with all 9 variables, including the variables which the reliability analysis indicated were not well represented by the other variables (i.e., homesickness, stress, integration, and positive affect).

Parallel Analysis

The number of factors according to parallel analysis is found by comparing the observed principal component eigenvalues to principal component eigenvalues of a sample random normal deviates with the same number of variables and observations.

The results below indicate that the first component explains more variance than random data eigenvalues, but the remaining components do not. As such, one factor should be retained.

Below shows the result of common factor analysis using maximum likelihood factor analysis.

ML1 is the loadings standardized loadings on the first (and only) factor (i.e., it is the correlation between the item and the factor). h2 is the communality. That is, the proportion of variance in the variable that is explained by the entire solution. Because it is a 1-factor solution, this is the same as the squared loading on the factor. u2 is just 1 - h2, or the unexplained variance.

Note that the soluation explains very little variance in homesickness, stress, integration, and positive affect.

With a Subset of Well-being Indicators

The reliability analysis and EFA both suggest that homesickness, stress, integration, and positive affect are not well represented by this common factor. Below shows an EFA with those items excluded.

Parallel Analysis

Parallel analysis shows even stronger evidence for a unidimensional solution. The observed eigenvalue for the second component is 0.58 (i.e., the second component explains 58% of the variance explained by one variable), which is much less than either the mean or 95th percentile random data eigenvalues.

EFA Results

The results of a maximum likelihood factor analysis with only flourishing, social connectedness, happiness, loneliness, and negative affect.

The loadings are all fairly large and the factor explains 60% of the variance in the 5 items.

Factor Scores

The factor scores are computed using regression with the standardized loadings.

Below is just wrangling the data to add each participants' factor score at each measurement occasion.

Hypothesis Tests with Factor Scores

We conducted the four null hypothesis significance tests using factor scores.

H1: Effect of the Intervention

Factor scores significantly increased pre-to-post intervention in all three conditions.

H3 and H4: Effect of the Canines

Both contrasts were significant, indicating a significant effect of both the dog's presence, and direct physical contact with the canine.