Skip to content

Instantly share code, notes, and snippets.

@audhiaprilliant
Last active December 18, 2020 17:10
Show Gist options
  • Select an option

  • Save audhiaprilliant/7dcd7d65292fd87367f48aa6f22b99ac to your computer and use it in GitHub Desktop.

Select an option

Save audhiaprilliant/7dcd7d65292fd87367f48aa6f22b99ac to your computer and use it in GitHub Desktop.
Simulation of Autocorrelation in Linear Regression Model
# Install package
install.packages('dplyr')
# Load the package
library(dplyr)
# Create a data aggregation
statDf = df %>%
group_by(Rho) %>%
summarize(
# Without autocorrelation
mean_InterceptNonAutocorrelation = mean(interceptNonAutocorrelation),
mean_InterceptNonAutocorrelation = sd(interceptNonAutocorrelation),
mean_SlopeNonAutocorrelation = mean(slopeNonAutocorrelation),
sd_SlopeNonAutocorrelation = sd(slopeNonAutocorrelation),
# With autocorrelation
mean_InterceptAutocorrelation = mean(interceptAutocorrelation),
mean_InterceptAutocorrelation = sd(interceptAutocorrelation),
mean_SlopeAutocorrelation = mean(slopeAutocorrelation),
sd_SlopeAutocorrelation = sd(slopeAutocorrelation)
) %>%
arrange(desc(Rho))
# View the result
View(statDf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment