Category: R
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...
Read Full Article →
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...
Read Full Article →
Bootstrapping Mediation Analysis in R from Scratch
This tutorial explains how to write code for boostrapping mediation analysis in R from scratch. Mediation analysis is often used in academic research to understand the underlying mechanism. Often, you also need to report a bootstrapping confidence interval for the...
Read Full Article →
Logistic Regression in R
This tutorial is to show how to do logistic regression in R with examples. The following is the key syntax for logistic regression in R. glm(Y~ X1 + X2, data = data_frame_name, family = "binomial") Steps of logistic regression in...
Read Full Article →
Convert Dataframe Columns to Vectors in R (2 Examples)
This tutorial shows how you can convert dataframe columns to vectors in R with examples. The following shows the two methods to do it. Method 1: vector<-df$column Method 2: vector<-df[ , ‘column’] Examples of Convert Dataframe columns to Vectors in...
Read Full Article →
Two Sample t-test in R (2 Examples)
This tutorial shows how you can two sample t-test in R. Note that, Two sample t-test is also called independent sample t-test or unpaired sample t-test. Method 1: Vector format t.test(vector_1, vector_2, var.equal = TRUE) Method 2: Data frame format...
Read Full Article →
One Sample t-test in R
The following is the core R syntax to do one sample t-test in R. In particular, Method 1 uses built-in R function, whereas method 2 writes the function to test one sample t-test in R from scratch. Method 1: t.test(vector_name,...
Read Full Article →
Johnson Neyman in R (2 detailed examples)
This tutorial explains how you can do Johnson Neyman in R. You can use the package of “interactions” in R do Johnson Neyman in R. The following is the key R syntax. library(interactions) model <- lm(Y ~ X * M,...
Read Full Article →
lower.tail in qnorm() and pnorm() (4 Examples)
This tutorial explains how to set and understand lower.tail in qnorm() and pnorm(). qnorm(p, mean, sd, lower.tail = TRUE, log.p = FALSE) pnorm(q, mean, sd, lower.tail = TRUE, log.p = FALSE) For both qnorm and pnorm, the meaning of lower.tail...
Read Full Article →
qnorm() in R: Definition and 5 Examples
This tutorial explains how you can use qnorm() in R with examples. qnorm(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE) p: the probability. mean: The mean of the normal distribution sample data. The default value is 0. sd: The...
Read Full Article →