Advertisement
Guest User

Untitled

a guest
May 13th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.27 KB | None | 0 0
  1. library(XRJulia)
  2. library(MASS)
  3.  
  4. bb_fit <- juliaEval("
  5. function BB_est(x, sims)
  6. X = center_data(x)
  7. n = size(X, 1)
  8. p = size(X, 2)
  9.  
  10. offdiag = (p * (p - 1)) / 2
  11.  
  12. loop_max = convert(Int64, offdiag)
  13.  
  14. temp    = Exponential(1)
  15. exp_drw = rand(temp, n * sims)
  16.  
  17. rexp_mat = reshape(exp_drw, sims, n)
  18. dir_weights = rexp_mat ./sum(rexp_mat, 2)
  19.  
  20. A = zeros(sims, offdiag)
  21. B = zeros((1, offdiag))
  22. C = zeros(sims, p)
  23. mat_point = zeros(p,p)
  24. mat_sig = zeros(p, p)
  25. idx = tril(trues(size(mat_point)), -1);
  26.  
  27. for i = 1:sims
  28. t = dir_weights[i, 1:n]
  29. d = X .* sqrt.(t)
  30. bb_cov = (d' * d)
  31.    inv_cov =  inv(bb_cov)
  32.    d = diag(inv_cov)
  33.    inv_cov[diagind(inv_cov)] = 0
  34.  
  35.    test = inv_cov[idx]
  36.    rmv_0 = filter!(x->x≠ 0,test)
  37.    A[i,:] = rmv_0
  38.    C[i,:] = d
  39.    end
  40.  
  41.   for i in 1:loop_max
  42.    temp1 =  quantile(A[:,i], 0.025)
  43.    temp2 =  quantile(A[:,i], 0.975)
  44.    B[1,i] = ifelse(temp1 < 0 && temp2 > 0, 0, 1)
  45. end
  46.  
  47.    mat_sig[idx] = B
  48.    mat_point[idx] = mean(A, 1)
  49.    mat_point[diagind(mat_point)] = mean(C, 1)
  50.    force_sym(mat_sig), force_sym(mat_point)
  51.     mat_sig, mat_point
  52. end")
  53.  
  54. n<- 200
  55. p <- 20
  56. X <- mvrnorm(n, rep(0, p), Sigma = diag(p))
  57.  
  58.  
  59. bb_fit_function=JuliaFunction(bb_fit)
  60.  
  61.  
  62. test <-bb_fit_function(main$data, 5000)
  63.  
  64.  
  65. JLreg=juliaGet(test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement