Category: R
Fisher’s LSD (Least Significant Different) in R
This tutorial shows how to do the post hoc test using Fisher’s LSD (Least Significant Different) in R. When to use Fisher’s LSD Typically, it is when you are doing one-way ANOVA with more than 2 groups (e.g., 3 groups). Further,...
Read Full Article →
Can you use one-way ANOVA for three groups?
Can you use one-way ANOVA for three groups? Yes, you can use one-way ANOVA for three groups (or, three levels). Actually, one-way ANOVA can be used for 2 groups and more than 2 groups. Example of one-way ANOVA for three...
Read Full Article →
Setup Hayes PROCESS in R (4 Steps)
The following shows steps of setup Hayes Mediation PROCESS in R. After setting up the PROCESS in R, we can use Model 4 as a simple example. In the following R code, we first download the data from GitHub. Then,...
Read Full Article →
Meaning of Hessian Matrix from optim() in R
The inverse of the Hessian matrix from optim() can be used as the asymptotic covariance matrix for estimated parameters. The name “asymptotic” is due to the direct replace the σ2 in the variance of estimated parameters with the estimated one,...
Read Full Article →
Maximum Likelihood Estimation for Linear Regression in R
To use maximum likelihood estimation (MLE) in linear regression in R, you can use either optim() or mle() function. The following provides detailed R code examples. Data and Model Suppose we want to test the effect of teaching method (new vs. old)...
Read Full Article →
How to Export DataFrame to CSV in R
You can use the write.csv() from base R or write_csv() from “readr” package to export a dataframe to CSV in R. write.csv() write.csv(df_1,”csv_file_name.csv”, row.names=FALSE) write_csv() write_csv(df_2,”csv_file_name.csv”) Example 1: Use write.csv() The following is the output of the dataframe df_1. >...
Read Full Article →
Generate Vectors only Contains 0 And 1 in R
You can generate a vector only containing 0 and 1 in R using sample() and rbinom() functions. sample: sample(c(0, 1), size = 10, replace = TRUE) rbinom: rbinom(10, size = 1, prob = 0.5) In both sample() and rbinom(): Example...
Read Full Article →
Interaction in Linear Regression
This tutorial focuses on interaction between a categorial variable and a continuous variable in linear regression. Note that, in this tutorial, we limit the the categorical variable to be 2 levels. (For a categrocial variable with 3 levels, please refer...
Read Full Article →
Dummy and Contrast Codings in Linear Regression (IV has 3 levels)
This tutorial explains the differences between dummy coding and contrast coding in linear regression using R code examples. It is worth pointing out that, this tutorial focuses on the categorical independent variable has 3 levels. Short Note Note that, in...
Read Full Article →
Changing Reference Level in Dummy Coding in R
You can change the reference level in dummy coding in R by using the following R code. contr.treatment(total_levels, base = Number_reference_level) Step 1: Prepare Data The following R code generates a sample data. X Y 1 1 -0.56047565 2 2...
Read Full Article →