Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #sample size, number of covariates, number of true causative predictors, Distribution, Link
  2. n = 1000
  3. p = 10000
  4. k = 10
  5. d = Poisson
  6. l = LogLink()
  7.  
  8. #set random seed
  9. Random.seed!(2019)
  10.  
  11. #random normal design matrix
  12. X = randn(n, p)
  13.  
  14. #define true model with non-zero entries 0.1, 0.2, ..., 1.0
  15. true_b = zeros(p)
  16. true_b[1:10] .= collect(0.1:0.1:1.0)
  17. shuffle!(true_b)
  18. correct_position = findall(!iszero, true_b)
  19.  
  20. #simulate y
  21. μ = X * true_b
  22. prob = linkinv.(l, μ)
  23. clamp!(prob, -20, 20)
  24. y = [rand(d(i)) for i in prob]
  25. y = Float64.(y)
  26.  
  27. #now perform univariate tests to test for association
  28. data = DataFrame(X=zeros(n), Y=y)
  29. placeholder = zeros(n)
  30. pvalues = zeros(p)
  31. for i in 1:p
  32. copyto!(placeholder, @view(X[:, i]))
  33. data.X .= placeholder
  34. result = glm(@formula(Y ~ X), data, Poisson(), LogLink())
  35. pvalues[i] = coeftable(result).cols[4][2].v
  36. end
  37.  
  38. #significance = bonferonni correction
  39. significance = 0.05 / p
  40. passing_position = findall(pvalues .<= significance)
  41.  
  42. #determine whether the 10 causative predictors were found
  43. marginal_found = [correct_position[i] in passing_position for i in 1:k]
  44.  
  45. #compute some summary statistic
  46. true_positive = count(!iszero, true_b[passing_snps_position2])
  47. false_positive = length(passing_snps_position2) - juliaglm_tp
  48. false_negative = k - juliaglm_tp
  49.  
  50. @show true_positive
  51. @show false_positive
  52. @show false_negative
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement