Skip to content

Commit

Permalink
createData() - unordered time column fixes #436
Browse files Browse the repository at this point in the history
  • Loading branch information
melina-leite committed Sep 25, 2024
1 parent 90e4c5f commit 5b875f7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Code/DHARMaIssues/436.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ createData2 <- function(sampleSize = 100, intercept = 0, fixedEffects = 1,

out = list()

time = sample(1:sampleSize, sampleSize) # change here
time = sample.int(sampleSizex) # change here
x = runif(sampleSize)
y = runif(sampleSize)

Expand Down Expand Up @@ -92,16 +92,16 @@ createData2 <- function(sampleSize = 100, intercept = 0, fixedEffects = 1,
# Autocorrelation

if(!(temporalAutocorrelation == 0)){
t = 1:sampleSize # INCLUDING CODE HERE
distMat <- as.matrix(dist(t))
# t = 1:sampleSize # INCLUDING CODE HERE
distMat <- as.matrix(dist(time))

invDistMat <- 1/distMat * 5000
diag(invDistMat) <- 0
invDistMat = sfsmisc::posdefify(invDistMat)

temporalError <- MASS::mvrnorm(n = 1, mu = rep(0,sampleSize), Sigma = invDistMat)

linearResponse = linearResponse + temporalAutocorrelation * temporalError[time] #
linearResponse = linearResponse + temporalAutocorrelation * temporalError #
}


Expand Down
2 changes: 1 addition & 1 deletion DHARMa/R/createData.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ createData <- function(sampleSize = 100, intercept = 0, fixedEffects = 1,

out = list()

time = 1:sampleSize
time = sample.int(sampleSize) #change to random order because of issue #436
x = runif(sampleSize)
y = runif(sampleSize)

Expand Down

0 comments on commit 5b875f7

Please sign in to comment.