Skip to content

Commit

Permalink
add testing script; fixed problem with parameter nesting for rmaMvModel
Browse files Browse the repository at this point in the history
  • Loading branch information
Rostu committed Sep 4, 2024
1 parent 73e0076 commit 6b91053
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export(checkIntegrity)
export(checkData)
export(checkParameter)
export(createData)
export(testListParameter)
18 changes: 11 additions & 7 deletions R/rmaMVModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ rmaMVModel <- function(yi,vi,measure,d,pred1=NULL,pred2=NULL,nesting=NULL) {

#load the in variable d defined dataset from the package
dat <- d
#checkParameter(dat,c(yi,vi))
if(nesting != NULL){
nesting <- fromJSON(nesting)
}
summary(dat)
checkParameter(dat,c(yi,vi))

pred1<-unlist(pred1)
pred2<-unlist(pred2)
Expand All @@ -38,13 +42,13 @@ rmaMVModel <- function(yi,vi,measure,d,pred1=NULL,pred2=NULL,nesting=NULL) {
if(is.null(nesting)){
nest<-list(~1 | outcome_ID ,~1 | sample_ID ,~1 | report_ID)
}else{
nest<-list()
i=1
for(p in nesting){
nest[i] <-paste("~1 |", p)
i=i+1
# Initialize an empty list to store the formulas
nest <- list()
# Iterate over the parsed JSON array and create formulas
for (i in seq_along(nesting)) {
# Create a formula and assign it to the nest list
nest[[i]] <- as.formula(paste("~1 |", nesting[[i]]))
}
nest<-lapply(nest, as.formula)
}
# there is no moderator defined
if( is.null(pred1) && is.null(pred2)){
Expand Down
22 changes: 22 additions & 0 deletions R/testFunctions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
library(jsonlite)

testListParameter <- function(nesting = NULL) {
# Parse the JSON input string
nesting <- fromJSON(nesting)

# Initialize an empty list to store the formulas
nest <- list()

# Iterate over the parsed JSON array and create formulas
for (i in seq_along(nesting)) {
# Create a formula and assign it to the nest list
nest[[i]] <- as.formula(paste("~1 |", nesting[[i]]))
}

# Print the resulting nest list
print(nest)

# Original nest2 for comparison
nest2 <- list(~1 | outcome_ID, ~1 | sample_ID, ~1 | report_ID)
print(nest2)
}

0 comments on commit 6b91053

Please sign in to comment.