Introductory Statistics with R for Educational Researchers
Full text
This is a self-archived version of an original article. This version may differ from the original in pagination and typographic details. Author(s): Title: Year: Version: Copyright: Rights: Rights url: Please cite the original version: CC BY 4.0 https://creativecommons.org/licenses/by/4.0/ Introductory Statistics with R for Educational Researchers © The Author(s) 2024 Published version Tikka, Santtu; Kopra, Juho; Heinäniemi, Merja; López-Pernas, Sonsoles; Saqr, Mohammed Tikka, S., Kopra, J., Heinäniemi, M., López-Pernas, S., & Saqr, M. (2024). Introductory Statistics with R for Educational Researchers. In M. Saqr, & S. López-Pernas (Eds.), Learning Analytics Methods and Tutorials : A Practical Guide Using R (pp. 121-150). Springer. https://doi.org/10.1007/978-3-031-54464-4_5 2024
Introductory Statistics with R for Educational Researchers Santtu Tikka, Juho Kopra, Merja Heinäniemi, Sonsoles López-Pernas, and Mohammed Saqr 1 Introduction Learning analytics involves the practical application of statistical methods to quantitative data, which can represent various aspects of the learning process such as student engagement, progress, and outcomes. Thus, knowledge about basic statistical methods is essential. Let’s start with how statistics connects with the research process and how it is also linked with philosophy of science. According to Niiniluoto [1], the research process can be described with the following eight steps: 1. Setting up a problem. 2. Disambiguation of the problem. Building a research strategy. 3. Collecting data. 4. Describing the data. 5. Analysis of data. 6. Interpreting the analyses. 7. Writing the report. 8. Publishing the results. Steps 1 and 2 require knowledge and skills related to the applied field, but also general scientific aptitude. Knowledge about statistics is central in steps 3, 4, 5, and S. Tikka () Department of Mathematics and Statistics, University of Jyväskylä, Jyväskylä, Finland e-mail: santtu.tikka@jyu.fi J. Kopra · S. López-Pernas · M. Saqr School of Computing, University of Eastern Finland, Joensuu, Finland M. Heinäniemi Institute of Biomedicine, University of Eastern Finland, Kuopio, Finland © The Author(s) 2024 M. Saqr, S. López-Pernas (eds.), Learning Analytics Methods and Tutorials, https://doi.org/10.1007/978-3-031-54464-4_5 121
122 S. Tikka et al. 6. Finally, steps 7 and 8 mostly require skills in writing and communication. Overall, it can be argued that a solid understanding of statistics and statistical methods is crucial for anyone conducting research with quantitative data. This chapter of the book concentrates on steps 4, 5, and 6 of the research process. We start with descriptive statistics, which are statistics that describe the overall features of the data. In contrast, inferential statistics are used to draw conclusions and make inferences about the population under study. Afterwards, we explain the basics of statistical hypothesis testing, which is the most common—although not the only—way to analyze data. The most common statistical tests, such as Student’s t-test, Chi-squared test, Analysis of variance, Levene’s test, and Shapiro-Wilk test are covered in this chapter. We also explain how to interpret the results of each test. We also present the linear regression model, which is not a statistical test but one of the most powerful statistical tools. Basic understanding of linear regression is essential for anyone interested in more advanced regression techniques, including logistic regression which is covered in the final section of this chapter. For a more in-depth view on the statistical tests covered in this chapter, we refer the reader to works such as [2, 3]. 2 Descriptive Statistics Descriptive statistics are used to provide a meaningful quantitative overview of data, and to summarize potentially vast amounts of information into more easily comprehensible and manageable quantities. In general, descriptive statistics are used as a first step in a data analysis workflow. In this section we will focus on numeric descriptors while visualizations are the topic of Chapter 6 [4]. For this chapter, we will use the combined Moodle data with students’ demographics, results, and summarized Moodle event activity. For more information about the dataset, please refer to Chapter 2 in this book [5]. We begin by installing all R packages that we will use in this chapter. install.packages( c("car", "rio", "see", "dplyr", "tidyr", "broom", "report", "correlation", "performance") ) We use the rio [6] package to read the data files into R via the import() function. The Events dataset contains log data on the student’s Moodle activity such as Moodle event types and names. The Demographics dataset contains background information on the students such as their gender and location of study (categorical variables). Finally, the Results data contains grades on various aspects of the Moodle course including the final course grade (numeric variables). We also create a new variable called AchievingGroup that categorizes the students
Introductory Statistics with R for Educational Researchers 123 into bottom and top 50% of achievers in terms of the final grade. We will leverage the dplyr [7] and tidyr [8] packages to wrangle the data into a single combined dataset. We begin by reading the data files and by constructing the AchievingGroup variable. library("rio") library("dplyr") library("tidyr") url <- "https://github.com/lamethods/data/raw/main/1_moodleLAcourse/" events <- import(paste0(url, "Events.xlsx"), setclass = "tibble") demographics <- import(paste0(url, "Demographics.xlsx"), setclass = "tibble") results <- import(paste0(url, "Results.xlsx"), setclass = "tibble") |> mutate( AchievingGroup = factor( case_when( ntile(Final_grade, 2) == 1 ~ "Low achiever", ntile(Final_grade, 2) == 2 ~ "High achiever" ) ) ) Next, we summarize the student’s engagement based on their Moodle activity into three groups: Low activity, Moderate activity and High Activity. events_summary <- events |> group_by(user) |> tally() |> rename(Frequency.Total = n) |> mutate( ActivityGroup = factor( case_when( ntile(Frequency.Total, 3) == 1 ~ "Low activity", ntile(Frequency.Total, 3) == 2 ~ "Moderate activity", ntile(Frequency.Total, 3) == 3 ~ "High activity" ) ) ) We also count the different types of Moodle events. events_types <- events |> group_by(user, Action) |> count(Action) |> pivot_wider( names_from = "Action",
124 S. Tikka et al. names_prefix = "Frequency.", values_from = "n", values_fill = 0 ) Finally, we combine the data. all_combined <- demographics |> left_join(events_types, by = "user") |> left_join(events_summary, by = "user") |> left_join(results, by = "user") The various steps of the combined data construction are discussed in greater detail in Chapter 4 [9]. 2.1 Measures of Central Tendency A typical way to summarize a univariate data sample is to describe its “middle point” using an appropriate statistic depending on the measurement scale of the data. The most common statistics to describe such a value are the mean,the median, and the mode. For data on the interval or ratio scales (and sometimes also on the ordinal scale), the most common option is to use the arithmetic mean, which is available via the base R function mean(). This function takes a vector of values as its input. all_combined |> summarise( mean_grade = mean(Final_grade), mean_total = mean(Frequency.Total) ) # A tibble: 1 x 2 mean_grade mean_total <dbl> <dbl> 1 7.25 736. The means are reported as a tibble with a single column for both variables. For data on the ordinal scale (or interval or ratio scales), the median can be used which is defined as the value that separates the lower half from the bottom half of the data sample, i.e., the 50% quantile. The median can be computed in R using the built-in median() function. Similarly to mean(), this function also takes a vector of values as its input.
Introductory Statistics with R for Educational Researchers 125 all_combined |> summarise( median_grade = median(Final_grade), median_total = median(Frequency.Total) ) # A tibble: 1 x 2 median_grade median_total <dbl> <dbl> 1 7.95 606 Just like before, the medians are reported as a tibble with each value in its own column. For data on the nominal or ordinal scale, the mode is a suitable choice as it describes the category with the highest number of observations. Unfortunately, there is no readily available function in R to compute the mode, and the reader should take care not to mistakenly use the mode() function, which is used to determine the internal storage mode of a variable (similar to the typeof() function). However, we can easily write our own function to compute the statistical mode as follows: stat_mode <- function(x) { u<-unique(x) u[which.max(tabulate(match(x, u)))] } Functions in R are written using the following syntax. First, we define the name of the function, just like we would define the name of a variable when assigning data into it, in this case the name is stat_mode. Next, we assign the function definition, which starts with the keyword function. Next, we describe the function arguments within the parentheses, in this case we call our argument x, which we assume contains the data vector we wish to compute the mode for. Next, we define the body of the function within the braces. The body determines what the function does and what its output should be. Within the body, we first determine the unique values in the data vector x, and assign the result to a variable u. Next, we need to count the number of occurrences of each unique value. To start, we first match each observed value in x to the unique values in u to get the corresponding indices, which we will then count using tabulate. We obtain the index of the value with the highest number of occurrences with the function which.max(), and finally the corresponding unique value by selecting it from u using the subset operator, i.e., the brackets. Our function will now work on all types of data. all_combined |> summarise( mode_gender = stat_mode(Gender),
126 S. Tikka et al. mode_location = stat_mode(Location) ) # A tibble: 1 x 2 mode_gender mode_location <chr> <chr> 1 FOn campus The output is now similar to the mean and median functions that we used earlier, showing the modes of Gender and Location as a two-column tibble. For nominal variables, it is common to also compute the frequencies of each category. This can easily be done with the base R function table() table(all_combined$Gender) FM 65 65 table(all_combined$Location) On campus Remote 106 24 The function outputs the names of the categories and the frequency of each category as an integer vector. 2.2 Measures of Dispersion For data on the interval and ratio scales (and sometimes also on the ordinal scale), it is also meaningful to describe how clustered or scattered the values in the sample are, i.e., how far apart the values are from one another. Commonly used measures of statistical dispersion include the variance, standard deviation, and the interquartile range. Typically, such measures have the value 0 when all values in the sample are identical, and the value increases as the dispersion in the data grows. All three measures can be readily computed with built-in R functions var(), sd(), and IQR() respectively. Like mean() and median(), these functions accept a vector or numeric values as input. all_combined |> summarise( var_grade = var(Final_grade),
Introductory Statistics with R for Educational Researchers 127 sd_grade = sd(Final_grade), iqr_grade = IQR(Final_grade) ) # A tibble: 1 x 3 var_grade sd_grade iqr_grade <dbl> <dbl> <dbl> 1 4.81 2.19 3.34 The variance, standard deviation and interquartile range of the final grade are returned as a tibble with three columns. 2.3 Covariance and Correlation Covariance and correlation measure the linear dependence between two variables. Correlation is a unitless measure between . −1 and 1, whereas covariance is not, and its scale depends on the scale of the variables. The sign of both measures indicates the tendency of the relationship. Positive sign means that as the value of one variable increases, the value of the other variable tends to increase as well. Conversely, a negative sign indicates that the value of the second variable tends to decrease as the value of the first variable increases. Both covariance and correlation and be computed directly in R using the functions cov() and cor(), respectively. all_combined |> summarise( cov_grade_total = cov(Final_grade, Frequency.Total), cor_grade_total = cor(Final_grade, Frequency.Total), ) # A tibble: 1 x 2 cov_grade_total cor_grade_total <dbl> <dbl> 1 504. 0.513 We obtain the covariance and correlation between the final grade and total number of Moodle events. We will familiarize ourselves with correlations in greater depth in Sect. 4. 2.4 Other Common Statistics The extreme values of a data sample can be found using the function range(), which computes the minimum and maximum values of the sample as a vector. These
128 S. Tikka et al. values can also be computed individually with the corresponding functions min() and max(). Because summarise() only allows a single value as output per row, we use the reframe() function instead when computing the range. all_combined |> reframe( range_grade = range(Final_grade) ) # A tibble: 2 x 1 range_grade <dbl> 10 210 all_combined |> summarise( min = min(Final_grade), max = max(Final_grade) ) # A tibble: 1 x 2 min max <dbl> <dbl> 1010 With reframe(), we obtain a tibble with two rows, the first containing the minimum value and the second the maximum value of the final grade. If we instead use summarise() like before, we can only obtain one value per computed variable. The summary() function can also be used to quickly compute several of the most common descriptive statistics for all variables of a dataset. results |> select(Grade.SNA_1:Grade.Group_self) |> summary() Grade.SNA_1 Grade.SNA_2 Grade.Review Grade.Group_self Min. : 0.000 Min. : 0.000 Min. : 0.000 Min. : 0.000 1st Qu.: 8.000 1st Qu.: 9.000 1st Qu.: 6.670 1st Qu.: 9.000 Median : 9.000 Median :10.000 Median : 8.000 Median :10.000 Mean : 8.346 Mean : 9.262 Mean : 7.724 Mean : 8.085 3rd Qu.:10.000 3rd Qu.:10.000 3rd Qu.: 9.670 3rd Qu.:10.000 Max. :10.000 Max. :10.000 Max. :10.000 Max. :10.000 The output shows the minimum and maximum values, the quartiles, and the mean of each variable that we selected.
Introductory Statistics with R for Educational Researchers 135 more active students are more likely to engage with the course content and perform better in terms of the learning outcomes. We can confirm that the assumptions of the test related to the expected values of the cells were not violated by using the test result object, which contains the expected values of the cells in the element expected. all(Xsq_test$expected >= 1) [1] TRUE mean(Xsq_test$expected >= 5) >= 0.80 [1] TRUE All expected values were greater than one, and over 80% of the expected values were greater than 5. This means that the assumptions are satisfied for our data and thus the results are reliable. Here, we used the function all() which takes a logical vector as input and returns TRUE if all elements of the vector were TRUE. Otherwise, the function returns FALSE. Unfortunately, the report() function does not support the chi-squared test. 3.3 Analysis of Variance Analysis of variance (ANOVA) [17] can be viewed as the generalization of Student’s t-test, where instead of one or two groups, the means of a variable are compared across multiple groups simultaneously. The name of the method comes from its test statistic, which is based on a decomposition of the total variance of the variable into variance within the groups and between the groups. ANOVA makes several assumptions: the observations are independent, the residuals of the underlying linear model follow a normal distribution, and that the variance of the variable is the same across groups (homoscedasticity). If these assumptions are violated, the results of the test may not be reliable. One alternative in such instances is to use the non-parametric Kruskal-Wallis test [18] instead, which is available in R via the function kruskal.test(). This test uses the ranks of the observations, and the null hypothesis is that the medians are the same for each group. We use our combined Moodle data to demonstrate ANOVA. Instead of comparing the total number of Moodle events between top and bottom 50% of achievers, this time we will compare the final grade of the students across three activity groups: low activity, moderate activity, and high activity, described by the variable ActivityGroup. Thus the null and alternative hypotheses are in this case: •. H0: The expected values of the final grade are the same across the three activity groups (.μ1=μ2=μ3),
136 S. Tikka et al. •. H1: At least one activity group has a different expected final grade (.μi= μjfor at least one pair .i= j). To carry out the analysis, we apply the aov function, which uses the same formula syntax to define the response variable and the groups as the t.test() function does. Next, we apply the summary() function to the aov() function return object fit, as the default output of aov() is not very informative. fit <- aov(Final_grade ~ ActivityGroup, data = all_combined) summary(fit) Df Sum Sq Mean Sq F value Pr(>F) ActivityGroup 2 175.7 87.87 25.11 6.47e-10 *** Residuals 127 444.4 3.50 --- Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 The summary contains the following columns: Df describes the degrees of freedom of the F-distribution associated with the test, Sum Sq reports the sum of squares related to the groups and the residuals, Mean Sq reports the corresponding mean sum of squares, F value is the value of the test statistic, and finally Pr(>F) is the p-value of the test. For this example, the p-value is very small, which means that the null hypothesis is rejected, and there are statistically significant differences in the final grade between the groups according to the test. In the following sections we will learn how to test for the assumptions related to normality and homoscedasticity. The report() function can be used for the output of aov() as well. report(fit) The ANOVA (formula: Final_grade ~ ActivityGroup) suggests that: - The main effect of ActivityGroup is statistically significant and large (F(2, 127) = 25.11, p < .001; Eta2 = 0.28, 95% CI [0.17, 1.00]) Effect sizes were labelled following Field’s (2013) recommendations. This output also reports the degrees of freedom, the test statistic value and the p-value but in a more easily readable format. Note that ANOVA simply measures if there are differences between the groups but does not provide information on how these differences emerge. For example, there could be a single group that is different from all the rest, or two subgroups where the means are similar within each group, but different between the subgroups. Visualizations can be a helpful tool for gaining more insight into the differences, and post-hoc pairwise tests can be carried out to compare the pairs of groups.
Introductory Statistics with R for Educational Researchers 137 3.4 Levene’s Test Levene’s test is used to investigate whether the variance of a variable is the same across two or more groups [19]. Compared to alternatives such as Bartlett’s test [20], Levene’s test is less sensitive to non-normal observations. The test is not available in base R, but it can be found in the car package as the function leveneTest().The function uses the same formula syntax as t.test() and aov(). We will investigate the homogeneity of the variance of the final grade between the activity groups. library("car") leveneTest(Final_grade ~ ActivityGroup, data = all_combined) Levene’s Test for Homogeneity of Variance (center = median) Df F value Pr(>F) group 2 5.7204 0.004181 ** 127 --- Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1 ’ ’ 1 The output of leveneTest() is analogous to the output of the ANOVA summary, and it contains the degrees of freedom (Df), the value of the test statistic (F value) and the p-value of the test (Pr(>F)). The p-value is very small, so we reject the null hypothesis meaning that the variance of the final grade is not the same across the groups according to the test. This means that the assumption of homoscedasticity is violated for the analysis of variance of the final grade, and thus the results may not be reliable. The report() function is not supported for leveneTest(). 3.5 Shapiro-Wilk Test Shapiro-Wilk test tests the null hypothesis that a data sample originated from a normal distribution [21]. The test is available in base R as the function shapiro.test(). Unfortunately, this function does not support the formula syntax unlike the other test functions we have used thus far. The function only accepts a single numeric vector as its argument. Therefore, to test the normality of multiple groups simultaneously, the data must first be split into the groups to be tested. We apply the test to the final grade in each achievement group. With the help of the broom package [22], we wrap the test results into a tidy format. library("broom") all_combined |> # Performs the computations in each activity group group_by(ActivityGroup) |>
138 S. Tikka et al. # Apply a function in each group group_modify(~{ # Apply the Shapiro test in each group and create tidy output shapiro.test(.$Final_grade) |> tidy() }) |> # Selection of variables to keep in the output select(ActivityGroup, statistic, p.value) # A tibble: 3 x 3 # Groups: ActivityGroup [3] ActivityGroup statistic p.value <fct> <dbl> <dbl> 1 High activity 0.918 0.00448 2 Low activity 0.909 0.00215 3 Moderate activity 0.862 0.000103 This is also a great example of the tidyverse paradigm. First, we group the data by ActivityGroup using group_by(), and then apply a function in each group using group_modify(). We apply the shapiro.test() function to the Final_grade variable, and then we convert the test results into a tidy tibble using the tidy() function from the broom package. We also use the special dot notation . to select the final grade variable from the data in each group. Finally, we select the grouping variable (ActivityGroup), the test statistic (statistic) and the p-value (p.value) of each test using select() and print the results. The resulting object is a tibble with three columns: ActivityGroup, statistic and p.value,thelast two of which give the test statistic and p-value of the test for the activity group of the first column. We can see that according to the test, the Final_grade variable is not normally distributed in any of the activity groups, as the p-values are very small. As a consequence, the results of the analysis of variance carried out earlier may not be reliable. 4 Correlation In Sect. 2.3, we briefly described covariance and correlation, and showcased the base R functions to compute them. However, there are several powerful and user-friendly packages for the analysis and reporting of correlations, such as the correlation [23] package which we will demonstrate in this section. library("correlation")
Introductory Statistics with R for Educational Researchers 139 For example, the package can easily compute all pairwise correlations between the numeric variables of the data with the function correlation(). The argument select can be used to compute the correlations only for a subset of the variables. corrs <- correlation( all_combined, select = c("Frequency.Total", "Grade.Theory", "Final_grade") ) corrs # Correlation Matrix (pearson-method) Parameter1 | Parameter2 |r |95% CI | t(128) |p ------------------------------------------------------------------------- Frequency.Total | Grade.Theory | 0.31 | [0.15, 0.46] | 3.75 | < .001*** Frequency.Total | Final_grade | 0.51 | [0.37, 0.63] | 6.76 | < .001*** Grade.Theory | Final_grade | 0.45 | [0.30, 0.58] | 5.69 | < .001*** p-value adjustment method: Holm (1979) Observations: 130 The columns Parameter1 and Parameter2 describe the variables that the correlation was computed for, r is the value of the sample correlation, and the remaining columns report the 95% confidence interval, the value of the test statistic, and the p-value of the test (a t-test for correlations) along with the statistical significance. By default, Pearson’s correlation coefficient is calculated, but the package also supports many alternative correlation measures. The correlation coefficient to be computed can be selected with the argument method that has the value "pearson" by default. Selecting for example method = "spearman" would compute the Spearman correlation coefficient instead. We can also obtain a correlation matrix by using summary() summary(corrs) # Correlation Matrix (pearson-method) Parameter | Final_grade | Grade.Theory -------------------------------------------- Frequency.Total | 0.51*** | 0.31*** Grade.Theory | 0.45*** | p-value adjustment method: Holm (1979) By default, redundant correlations are omitted, but they can be obtained by setting redundant = TRUE in the call to summary(). A plot of the correlation matrix can be produced with the help of the package see [24].
140 S. Tikka et al. library("see") corrs |> # Also include redundant correlations summary(redundant = TRUE) |> plot() 0.51*** 0.45*** 0.51***0.31*** 0.45***0.31*** Final_grade Grade.Theory Frequency.Total Frequency.Total Grade.Theory Final_grade Correlation 0.00 0.25 0.50 0.75 1.00 Correlation Matrix The plot shows the strength of the correlations where darker colors imply stronger correlations. Visualizations will be covered at greater length in Chapter 6[4]. 5 Linear Regression Linear regression is a statistical tool where one continuous variable is explained by the values of other variables. The variable of interest is said to be a dependent, while the other variables are called predictors. Predictors may also be called explanatory variables, independent variables or covariates depending on the context, applied field, and perspective. Consider a very simple case, where we only have one predictor, which happens to be a continuous variable. In this case, fitting a linear regression model is merely the same as fitting a straight line to a scatterplot. It is assumed that deviations from this line are simply a result of random variation. Now, let’s go through the formal definition of a linear regression model. Let Y be a dependent variable with measurements .y1...,y n, and let .X1,X 2,...,X kbe predictor variables with measurements .x1i,...,x ki for all .i=1,...,n where i refers to an individual measurement. Then, the regression equation is
Introductory Statistics with R for Educational Researchers 141 . yi=β0+β1x1i+β2x2i+···+βkxki +εi,ε i∼N(0,σ2), i =1,...,n where we have the regression coefficients .β0,β 1,...β kand the error variance . σ2. The first parameter . β0is called the intercept that models the conditional expectation of Y when all the predictors have the value 0. From the regression equation, several assumptions become apparent. First, as the name of the model suggests, a linear relationship is assumed between the response and the predictors. Next, the variance . σ2of the errors . εiis constant, and does not depend on the values of the predictors (homoscedasticity). The errors are also assumed independent. The predictor variables are assumed fixed and their values perfectly measured without error. Let’s fit a linear regression model that predicts the final grade with the number of Moodle events of different types. To simplify the exposition, we will only use three types of Moodle events as predictors. We use the lm() function which has the same formula interface that we are already familiar with. First, we must define the dependent variable on the left-hand side of the formula, followed by the predictors on the right-hand side separated by a + sign. We must also supply the data argument, which tells the function where the actual values of the variables can be accessed. fit <- lm( Final_grade ~ Frequency.Applications + Frequency.Assignment + Frequency.La_types, data = all_combined ) summary(fit) Call: lm(formula = Final_grade ~ Frequency.Applications + Frequency.Assignment + Frequency.La_types, data = all_combined) Residuals: Min 1Q Median 3Q Max -7.0382 -0.8872 0.3665 1.2372 3.4422 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 5.800211 0.405963 14.288 < 2e-16 *** Frequency.Applications 0.076516 0.022294 3.432 0.000811 *** Frequency.Assignment -0.005049 0.005734 -0.881 0.380225 Frequency.La_types 0.088252 0.027314 3.231 0.001574 ** --- Signif. codes: 0 ’***’ 0.001 ’**’ 0.01 ’*’ 0.05 ’.’ 0.1’’1 Residual standard error: 1.914 on 126 degrees of freedom
142 S. Tikka et al. Multiple R-squared: 0.2559, Adjusted R-squared: 0.2382 F-statistic: 14.45 on 3 and 126 DF, p-value: 3.798e-08 The summary() function provides a compact overview of the model fit for lm objects. First, a summary of the residuals (i.e., the differences between the observed and predicted values) is provided under Residuals. Next, a summary of the regression coefficients . βis provided under Coefficients, including their estimates (Estimate), standard errors (Std. Error), test statistics for t-tests that test whether the coefficients are significantly different from zero (t value), p-values of the tests (Pr(>|t|)) and statistical significance (indicated by the asterisks). For instance, we see that the number of group work events is statistically significant. The notation used for the significance levels of the tests is described following Signif. codes. Estimate of the square root of the error variance . σ2is reported following Residual standard error.Thetwo R-squared values are estimates of the proportion of variance of the data that is explained by the model. Finally, the F-statistic reports the results of ANOVA when applied with the same model formula that was used for the linear regression model. The report() function provides a more comprehensive summary of the model fit and the regression coefficients: report(fit) We fitted a linear model (estimated using OLS) to predict Final_grade with Frequency.Applications, Frequency.Assignment and Frequency.La_types (formula: Final_grade ~ Frequency.Applications + Frequency.Assignment + Frequency.La_types). The model explains a statistically significant and moderate proportion of variance (R2 = 0.26, F(3, 126) = 14.45, p < .001, adj. R2 = 0.24). The model’s intercept, corresponding to Frequency.Applications = 0, Frequency.Assignment = 0 and Frequency.La_types = 0, is at 5.80 (95% CI [5.00, 6.60], t(126) = 14.29, p < .001). Within this model: - The effect of Frequency Applications is statistically significant and positive (beta = 0.08, 95% CI [0.03, 0.12], t(126) = 3.43, p < .001; Std. beta = 0.32, 95% CI [0.13, 0.50]) - The effect of Frequency Assignment is statistically non-significant and negative (beta = -5.05e-03, 95% CI [-0.02, 6.30e-03], t(126) = -0.88, p = 0.380; Std. beta = -0.08, 95% CI [-0.26, 0.10]) - The effect of Frequency La types is statistically significant and positive (beta = 0.09, 95% CI [0.03, 0.14], t(126) = 3.23, p = 0.002; Std. beta = 0.31, 95% CI [0.12, 0.49]) Standardized parameters were obtained by fitting the model on a standardized version of the dataset. 95% Confidence Intervals (CIs) and p-values were computed using a Wald t-distribution approximation. Again, the report output has condensed the information about the model fit into a format that can be read in a straightforward manner.
Introductory Statistics with R for Educational Researchers 143 The assumption of normality of the residuals can be assessed with a quantilequantile plot, or q-q plot for short. The residuals of the model fit can be accessed with the function resid(). The function qqnorm() draws the quantiles of the residuals against the quantiles of the normal distribution. The function qqline() adds a straight line through the plot that passes through the second and third quantiles, by default. Ideally, the residuals should fall on this line, and large deviations indicate that the normality assumption may not hold. # Draw the quantiles of the residuals and the theoretical quantiles qqnorm(resid(fit)) # Add a line through the theoretical quantiles qqline(resid(fit)) −2 −1 0 1 2 −6 −4 −2 0 2 Normal Q−Q Plot Theoretical Quantiles Sample Quantiles The vast majority of residuals fall nicely onto the line for our model. Besides the q-q plot, we can obtain more model diagnostics with the help of the performance [25] package. This package provides a wide array of tools to assess how well models fit to the data. The general-purpose function check_model( provides a visual overview of the model fit using several metrics. library("performance") check_model(fit, theme = see::theme_lucid(base_size = 10))
144 S. Tikka et al. 0.00 0.05 0.10 0.15 0.20 0 5 10 15 Final_grade Density Observed data Model−predicted data Model−predicted lines should resemble observed data line Posterior Predictive Check −7.5 −5.0 −2.5 0.0 2.5 6 7 8 9 10 11 Fitted values Residuals Reference line should be flat and horizontal Linearity 0.5 1.0 1.5 2.0 6789 10 11 Fitted values |Std. residuals| Reference line should be flat and horizontal Homogeneity of Variance 4 89 38 11 52 0.8 0.8 −20 −10 0 10 20 0.00 0.05 0.10 Leverage (hii) Std. Residuals Points should be inside the contour lines Influential Observations 1 2 3 5 10 Frequency.ApplicationsFrequency.AssignmentFrequency.La_types Variance Inflation Factor (VIF, log−scaled) Low (< 5) High collinearity (VIF) may inflate parameter uncertainty Collinearity −4 −2 0 2 −2 −1 0 1 2 Standard Normal Distribution Quantiles Sample Quantiles Dots should fall along the line Normality of Residuals The functions performs various tests related to the assumptions of the linear regression model. For example, the bottom right panel contains the same q-q plot that we previously constructed using the qqnorm() and qqline() functions. We refer the reader to the documentation of the performance package for more information on the remaining tests.