Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simulateDCE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dj44vuri
simulateDCE
Commits
0c1de67f
Commit
0c1de67f
authored
1 year ago
by
samuelsmock
Browse files
Options
Downloads
Patches
Plain Diff
divergence fix
parent
6be6c256
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
R/sim_all.R
+7
-7
7 additions, 7 deletions
R/sim_all.R
tests/testthat/Rplots.pdf
+0
-0
0 additions, 0 deletions
tests/testthat/Rplots.pdf
tests/testthat/test-sim_all.R
+8
-8
8 additions, 8 deletions
tests/testthat/test-sim_all.R
with
15 additions
and
15 deletions
R/sim_all.R
+
7
−
7
View file @
0c1de67f
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
sim_all
<-
function
(
nosim
=
2
,
resps
,
destype
=
"ngene"
,
designpath
,
u
,
bcoeff
){
sim_all
<-
function
(
nosim
=
2
,
resps
,
destype
=
"ngene"
,
designpath
,
u
,
bcoeff
){
#################################################
#################################################
########## Input Validation Test
s
###############
########## Input Validation Test ###############
#################################################
#################################################
########### validate the utility function ########
########### validate the utility function ########
...
@@ -41,17 +41,17 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
...
@@ -41,17 +41,17 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
if
(
missing
(
bcoeff
))
{
if
(
missing
(
bcoeff
))
{
stop
(
"Argument 'bcoeff' is required."
)
stop
(
"Argument 'bcoeff' is required."
)
}
}
# Check if bcoeff is a list
# Check if bcoeff is a list
if
(
!
is.list
(
bcoeff
))
{
if
(
!
is.list
(
bcoeff
))
{
stop
(
"Argument 'bcoeff' must be a list."
)
stop
(
"Argument 'bcoeff' must be a list."
)
}
}
# Check if values in bcoeff are numeric
# Check if values in bcoeff are numeric
if
(
!
all
(
sapply
(
bcoeff
,
is.numeric
)))
{
if
(
!
all
(
sapply
(
bcoeff
,
is.numeric
)))
{
stop
(
"Values in 'bcoeff' must be numeric."
)
stop
(
"Values in 'bcoeff' must be numeric."
)
}
}
#### check that all the coefficients in utility function have a cooresponding value in bcoeff ####
#### check that all the coefficients in utility function have a cooresponding value in bcoeff ####
# Extract coefficients from utility function starting with "b"
# Extract coefficients from utility function starting with "b"
coeff_names_ul
<-
unique
(
unlist
(
lapply
(
u
,
function
(
u
)
{
coeff_names_ul
<-
unique
(
unlist
(
lapply
(
u
,
function
(
u
)
{
...
@@ -64,7 +64,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
...
@@ -64,7 +64,7 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
})))
})))
return
(
coef_names
)
return
(
coef_names
)
})))
})))
# Check if all utility function coefficients starting with "b" are covered in bcoeff list
# Check if all utility function coefficients starting with "b" are covered in bcoeff list
missing_coeffs
<-
coeff_names_ul
[
!
(
coeff_names_ul
%in%
names
(
bcoeff
))]
missing_coeffs
<-
coeff_names_ul
[
!
(
coeff_names_ul
%in%
names
(
bcoeff
))]
if
(
length
(
missing_coeffs
)
>
0
)
{
if
(
length
(
missing_coeffs
)
>
0
)
{
...
@@ -78,11 +78,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
...
@@ -78,11 +78,11 @@ sim_all <- function(nosim=2, resps, destype="ngene", designpath, u, bcoeff){
if
(
!
dir.exists
(
designpath
))
{
if
(
!
dir.exists
(
designpath
))
{
stop
(
" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified"
)
stop
(
" The folder where your designs are stored does not exist. \n Check if designpath is correctly specified"
)
}
}
#################################################
#################################################
########## End Validation Tests #################
########## End Validation Tests #################
#################################################
#################################################
designfile
<-
list.files
(
designpath
,
full.names
=
T
)
designfile
<-
list.files
(
designpath
,
full.names
=
T
)
designname
<-
stringr
::
str_remove_all
(
list.files
(
designpath
,
full.names
=
F
),
designname
<-
stringr
::
str_remove_all
(
list.files
(
designpath
,
full.names
=
F
),
"(.ngd|_|.RDS)"
)
## Make sure designnames to not contain file ending and "_", as the may cause issues when replace
"(.ngd|_|.RDS)"
)
## Make sure designnames to not contain file ending and "_", as the may cause issues when replace
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/Rplots.pdf
+
0
−
0
View file @
0c1de67f
No preview for this file type
This diff is collapsed.
Click to expand it.
tests/testthat/test-sim_all.R
+
8
−
8
View file @
0c1de67f
...
@@ -124,10 +124,10 @@ test_that("Utility functions are valid", {
...
@@ -124,10 +124,10 @@ test_that("Utility functions are valid", {
test_that
(
"Design path must be a valid directory"
,
{
test_that
(
"Design path must be a valid directory"
,
{
# Test case: designpath is not a character string
# Test case: designpath is not a character string
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
123
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
123
,
u
=
ul
,
bcoeff
=
bcoeff
))
# Test case: designpath does not exist
# Test case: designpath does not exist
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
'/nonexistent/path'
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
'/nonexistent/path'
,
u
=
ul
,
bcoeff
=
bcoeff
))
# Test case: designpath is not a directory
# Test case: designpath is not a directory
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
'path/to/a/file.txt'
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
'path/to/a/file.txt'
,
u
=
ul
,
bcoeff
=
bcoeff
))
})
})
...
@@ -135,13 +135,13 @@ test_that("Design path must be a valid directory", {
...
@@ -135,13 +135,13 @@ test_that("Design path must be a valid directory", {
test_that
(
"Resps must be an integer"
,
{
test_that
(
"Resps must be an integer"
,
{
# Test case: resps is missing
# Test case: resps is missing
expect_error
(
sim_all
(
nosim
=
nosim
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
# Test case: resps is not an integer
# Test case: resps is not an integer
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
"abc"
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
"abc"
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
# Test case: resps is a numeric but not an integer
# Test case: resps is a numeric but not an integer
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
1.5
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
expect_error
(
sim_all
(
nosim
=
nosim
,
resps
=
1.5
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
))
})
})
test_that
(
"Function exists in simulateDCE"
,
{
test_that
(
"Function exists in simulateDCE"
,
{
...
@@ -149,10 +149,10 @@ test_that("Function exists in simulateDCE", {
...
@@ -149,10 +149,10 @@ test_that("Function exists in simulateDCE", {
})
})
test_that
(
"Simulation results are reasonable"
,
{
test_that
(
"Simulation results are reasonable"
,
{
result1
<-
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
)
result1
<-
sim_all
(
nosim
=
nosim
,
resps
=
resps
,
destype
=
destype
,
designpath
=
designpath
,
u
=
ul
,
bcoeff
=
bcoeff
)
expect_gt
(
result1
$
est_bsq
,
-1
)
expect_gt
(
result1
$
est_bsq
,
-1
)
expect_lt
(
result1
$
est_bsq
,
1
)
expect_lt
(
result1
$
est_bsq
,
1
)
})
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment