Test Homogeneity of Variance in R

This tutorial shows methods test Homogeneity of Variance (or, Equality of Variance) in R. The methods include F-test, Bartlett’s test, Levene’s test, and Fligner-Killeen’s test. F-test: Compare variances of 2 groups. Need assumption of normality. Bartlett’s test: Compare variances of 2 or more groups. Need assumption of normality. Levene’s test: An alternative to Bartlett’s test, … Read more

How to Add Density Line on Histogram in R

This tutorial shows how to add density line on histogram in R. The following is the key part of the syntax, which sets freq=FALSE and add line() on the top of the histogram. hist(data_name, freq =FALSE) lines(density(data_name)) Example 1 We are going to use the New Haven temperature data to plot the histogram and the … Read more

Categories R

How to Increase Bin Density in Histogram in R

This tutorial shows how to increase bin density in histogram in R. You can use breaks in hist() to do so. Below is the basic R syntax of doing so. hist(dataset_name,breaks = 50) Example 1 We are going to use the “Average Yearly Temperatures in New Haven” for the first example to show how to … Read more

Categories R

Test Normality Assumption for ANOVA in R

This tutorial shows how to test normality assumption for ANOVA in R. I will also highlight mistakes that people tend to make when testing normality. Math of Normality assumption for ANOVA Before going to details of how to do that test normality, it is necessary to understand the simple math of testing normality assumption for … Read more

R Code for Serial Mediation

This tutorial shows how you can write R code for serial mediation. Unless you use Hayes’ R code, I am not aware how you can do serial mediation in R. Thus, I am providing this R code here for your convenience. Note that, the current tutorial is for both mediators and the dependent measure Y … Read more

Categories R

Serial Mediation for Count Data (with R code)

Warning: Introduction This tutorial shows how to do serial mediation for count data. Complete R code is provided. The following are the theoretical models and conceptual framework, assuming IV, M1, M2 are close to normally distributed, and DV is the count data. Step 1 (Optional): Data Simulation The following is the code to generate the … Read more

Mediation Analysis for Count Data (with R code)

Warning: Introduction This tutorial shows how to do mediation analysis for count data in R. Complete R code and examples are provided. There are two possible ways to consider count data. (1) You can just assume that the residuals are normally distributed. Then, you can just use the commonly used linear regression model. You can … Read more

Simulate Data for Poisson Regression in R

This tutorial shows how to simulate a dataset for Poisson regression in R. Step 1: Determine the model Suppose that the following is the model with known population parameters, namely known regression coefficients of 0.2 and 0.08. Of course, in reality, the most likely result is that we do not know such parameters and we … Read more

Mediation Analysis in R from Scratch (with R code)

This tutorial shows you how to do mediation analysis in R from scratch. As we know, quantitatively, mediation analysis is about if the product of a*b is statistically significant (see figure below). If you assume that a*b is normally distributed, you can just directly test the level of significance. If you do not assume normal … Read more

ANOVA Assumptions

There are 3 assumption for ANOVA: Normality – The responses for each factor level have a normal population distribution. Equal variances (Homogeneity of Variance) – These distributions have the same variance. Independence – The data are independent. You can use R to test the assumptions of normality and equality variances (The following are the two tutorials). In contrast, … Read more