Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added testdata directory #6

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Imports: RCy3,
tidyr,
methods,
dplyr,
graphics
graphics,
matrixcalc
License: GPL-3
Encoding: UTF-8
LazyData: false
Expand Down
19 changes: 19 additions & 0 deletions R/DRAGON.R
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,25 @@ get_partial_correlation_dragon = function(X1,X2,lambdas)
# estimate_kappa = function(n, p, lambda0, seed)
# estimate_p_values(r, n, lambda0, kappa='estimate', seed=1):

log_lik_shrunken = function(kappa, p, lambda, rhos)
{
# kappa is to be optimized, so comes first in the arguments
# p is fixed (number of predictors)
# lambda is fixed (as estimated by DRAGON)
# rhos is fixed (observed partial correlations from the data)
mysum = 0

for(i in 1:p)
{
first_term = (kappa-3)/2*log((1-lambda)^2-rhos[i]^2)
second_term = lbeta(1/2, (kappa-1)/2)
third_term = (kappa-2)*log(1-lambda)
mysum = mysum + first_term - second_term - third_term
}

return(mysum)
}

# def estimate_kappa_dragon(n, p1, p2, lambdas, seed, simultaneous = False):
estimate_kappa_dragon = function(n, p1, n2, lambdas, seed, simultaneous = F)
{
Expand Down
15 changes: 14 additions & 1 deletion tests/testthat/test-dragon.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,23 @@ test_that("[DRAGON] get_shrunken_covariance_dragon() function returns the right
X2 = as.matrix(myX[,3])
lambdas = c(0.25,0.5)
res = get_shrunken_covariance_dragon(X1,X2,lambdas)
res_py = as.matrix(read.csv("dragon-test-files/dragon_test_get_shrunken_covariance.csv",row.names=1))
res_py = as.matrix(read.csv("./testdata/dragon-test-files/dragon_test_get_shrunken_covariance.csv",row.names=1))
expect_equal(as.vector(res),as.vector(res_py),tolerance = 1e-15)
}
)

# test log likelihood function
test_that("[DRAGON] Log likelihood function for estimation of kappa is correct",{
# log_lik_shrunken = function(kappa, p, lambda, rhos)
kappa = 10
p = 100
lambda = 0.1
rhos = runif(n = 100, min = -0.9, max = 0.9) # equation is valid for [-(1-lambda),(1-lambda)]
log_lik_shrunken(kappa = kappa,
p = p,
lambda = lambda,
rhos = rhos)
})

#testing format
#test_that(,{})