{"id":694,"date":"2015-08-12T13:02:50","date_gmt":"2015-08-12T17:02:50","guid":{"rendered":"http:\/\/zhanxw.com\/blog\/?p=694"},"modified":"2015-08-12T13:02:50","modified_gmt":"2015-08-12T17:02:50","slug":"r%e7%9a%84%e8%af%a1%e5%bc%82%e9%94%99%e8%af%af3","status":"publish","type":"post","link":"https:\/\/zhanxw.com\/blog\/2015\/08\/r%e7%9a%84%e8%af%a1%e5%bc%82%e9%94%99%e8%af%af3\/","title":{"rendered":"R\u7684\u8be1\u5f02\u9519\u8bef(3)"},"content":{"rendered":"<p>R\u7684\u8be1\u5f02\u9519\u8bef (3)<br \/>\nA pitfall in R (3)<\/p>\n<p>\u4e0b\u9762\u7684\u4ee3\u7801\u6709\u4e24\u884c\uff0c\u7b2c\u4e00\u884c\u8ba1\u7b97Genotype\u7684Minor Allele Frequency\uff0c\u7b2c\u4e8c\u884c\u8ba1\u7b97Weight matrix \uff08\u7528SKAT paper\u5efa\u8bae\u7684Beta\u5206\u5e03\u7684weight\uff09\u3002<br \/>\n\u4e0b\u9762\u7684\u4ee3\u7801\u6709\u95ee\u9898\u5417\uff1f<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# G is a sample by marker matrix\r\nmaf &lt;- colMeans(G) \/ 2\r\nw &lt;- diag(dbeta(maf, 1, 25))\r\n<\/pre>\n<p>\u7c97\u7c97\u4e00\u770b\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u7684\u601d\u8def\u662f\u6b63\u786e\u7684\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u6709\u4e24\u4e2a\u5751\u3002<br \/>\n\u7b2c\u4e00\u4e2a\u5751\u662f\u7f3a\u5931\u6570\u636e\uff08Missing data\uff09\uff0c\u5982\u679cGenotype\u77e9\u9635G\u6709\u7f3a\u5931\u6570\u636e\uff0c\u90a3\u4e48maf\u548cw\u90fd\u4f1a\u6709\u7f3a\u5931\u7684\u6570\u636e\uff1b<br \/>\n\u7b2c\u4e8c\u4e2a\u5751\u6bd4\u8f83\u96be\u770b\u51fa\u6765\uff1a\u5f53G\u53ea\u6709\u4e00\u5217\u7684\u65f6\u5019\uff0cmaf\u4e5f\u4f1a\u662f\u4e00\u4e2a\u6807\u91cf\uff08Scalar\uff09\uff0c\u540c\u6837dbeta\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u6807\u91cf\u3002<br \/>\n\u4f60\u53ef\u80fd\u60f3diag\u51fd\u6570\u4f5c\u7528\u5728\u4e00\u4e2a\u6807\u91cf\u4e0a\uff0c\u5176\u8fd4\u56de\u503c\u662f\u4e00\u4e2a1&#215;1\u7684\u77e9\u9635\u3002<br \/>\n\u4f46\u662f\uff0cdiag()\u7684\u8fd4\u56de\u7684\u662f\u4e00\u4e2a&#8230;.\u4e0d\u786e\u5b9a\u7684\u7ed3\u679c\uff0c\u770b\u4e2a\u4f8b\u5b50\u5427\uff1a<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\ndiag(3)            =&gt; 3x3 \u5355\u4f4d\u77e9\u9635\r\ndiag(3.9)          =&gt; \u8fd8\u662f3x3 \u5355\u4f4d\u77e9\u9635\r\ndiag(0)            =&gt; \u662f0x0 \u77e9\u9635\r\ndiag(-1)           =&gt; \u62a5\u9519\r\ndiag(c(1, 2, 3)    =&gt; 3x3 \u77e9\u9635\uff0c \u5bf9\u89d2\u7ebf\u662f1\uff0c2\uff0c3\r\n<\/pre>\n<p>\u603b\u4e4b\uff0c\u7b2c\u4e8c\u4e2a\u5751\u544a\u8bc9\u6211\u4eec\uff0c\u5982\u679cdbeta\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u957f\u5ea6\u4e3a1\u7684\u6570\u503c\uff0c\u522b\u6307\u671bw\u4e00\u5b9a\u662f1&#215;1\u7684\u77e9\u9635\u3002<\/p>\n<p>\u7ee7\u7eed\u5410\u69fd\uff1a<br \/>\ndiag()\u8fd9\u4e2a\u51fd\u6570\u8bbe\u8ba1\u7684\u4e0d\u597d\u7528\u3002\u5728R\u5185\u90e8\uff0c\u6807\u91cf\u5c31\u662f\u88ab\u5b9e\u73b0\u4e3a\u957f\u5ea6\u4e3a1\u7684\u5411\u91cf\u3002<br \/>\n\u5728\u73b0\u5728\u7684\u8bbe\u8ba1\u4e0b\uff0cdiag\u8981\u6c42\u4f7f\u7528\u8005\u540c\u65f6\u8003\u8651\u53d8\u91cf\u7684\u7c7b\u578b\uff08\u77e9\u9635\uff0c\u5411\u91cf\uff0c\u7f3a\u5931\uff09\u4ee5\u53ca\u53d8\u91cf\u7684\u957f\u5ea6\u548c\u503c\uff08\u5411\u91cf\u957f\u5ea6\u4e3a1\u4e14\u5927\u4e8e\u7b49\u4e8e0\uff0c\u5411\u91cf\u957f\u5ea6\u4e3a1\u4e14\u5c0f\u4e8e0\uff0c\u5411\u91cf\u957f\u5ea6\u5927\u4e8e1\uff09\u3002<br \/>\n\u5bf9\u4e8e\u4e00\u4e2a\u9002\u5e94\u4e86\u4f7f\u7528\u6709\u7c7b\u578b\u7cfb\u7edf\u7684\u7f16\u7a0b\u8bed\u8a00\u7684\u7a0b\u5e8f\u5458\uff0c\u8fd9\u79cd\u8981\u6c42\u4f1a\u589e\u52a0\u4f7f\u7528\u8005\u7684\u8111\u529b\u8d1f\u62c5\uff0c\u540c\u65f6\u9605\u8bfb\u8005\u5728\u8bed\u4e49\u4e0a\u4e5f\u5f88\u5bb9\u6613\u51fa\u73b0\u6df7\u6dc6\u3002<br \/>\n\u6211\u5efa\u8bae\u7684\u89e3\u51b3\u65b9\u6848\u662f\uff1adiag(\u5411\u91cf)\u6c38\u8fdc\u8f93\u51fa\u4e00\u4e2a\u5bf9\u89d2\u7ebf\u662f\u8be5\u5411\u91cf\u7684\u77e9\u9635\uff0c\u540c\u65f6\u5b9a\u4e49\u4e00\u4e2a\u65b0\u51fd\u6570(\u53ef\u4ee5\u53ebdiag_len,\u7c7b\u6bd4seq_len\uff1b\u6216\u8005\u53ebeye\uff0c\u7c7b\u6bd4Matlab\u91cc\u7684eye\u51fd\u6570\uff09\u4e13\u95e8\u7528\u6765\u751f\u6210\u5355\u4f4d\u77e9\u9635\u3002<\/p>\n<p>\u6700\u540e\u603b\u7ed3\u4e00\u4e0b\uff0c\u6211\u89c9\u5f97\u8fd9\u6837\u5199\u6bd4\u8f83<\/p>\n<pre class=\"brush: r; title: ; notranslate\" title=\"\">\r\n# G is a sample by marker matrix\r\nmaf &lt;- colMeans(G, na.rm = TRUE) \/ 2\r\nm &lt;- length(maf)\r\nw &lt;- matrix(0, nr = m, nc = m) \r\ndiag(w) &lt;- dbeta(maf, 1, 25) \r\n# \u6216\u8005\uff1aw &lt;- diag(dbeta(maf, 1, 25), nrow = m, ncol = m)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>R\u7684\u8be1\u5f02\u9519\u8bef (3) A pitfall in R (3) \u4e0b\u9762\u7684\u4ee3\u7801\u6709\u4e24\u884c\uff0c\u7b2c\u4e00\u884c\u8ba1\u7b97Genotype\u7684Minor Allele Frequency\uff0c\u7b2c\u4e8c\u884c\u8ba1\u7b97Weight matrix \uff08\u7528SKAT paper\u5efa\u8bae\u7684Beta\u5206\u5e03\u7684weight\uff09\u3002 \u4e0b\u9762\u7684\u4ee3\u7801\u6709\u95ee\u9898\u5417\uff1f # G is a sample by marker matrix maf &lt;- colMeans(G) \/ 2 w &lt;- diag(dbeta(maf, 1, 25)) \u7c97\u7c97\u4e00\u770b\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u7684\u601d\u8def\u662f\u6b63\u786e\u7684\uff0c\u4e0d\u8fc7\u8fd9\u91cc\u6709\u4e24\u4e2a\u5751\u3002 \u7b2c\u4e00\u4e2a\u5751\u662f\u7f3a\u5931\u6570\u636e\uff08Missing data\uff09\uff0c\u5982\u679cGenotype\u77e9\u9635G\u6709\u7f3a\u5931\u6570\u636e\uff0c\u90a3\u4e48maf\u548cw\u90fd\u4f1a\u6709\u7f3a\u5931\u7684\u6570\u636e\uff1b \u7b2c\u4e8c\u4e2a\u5751\u6bd4\u8f83\u96be\u770b\u51fa\u6765\uff1a\u5f53G\u53ea\u6709\u4e00\u5217\u7684\u65f6\u5019\uff0cmaf\u4e5f\u4f1a\u662f\u4e00\u4e2a\u6807\u91cf\uff08Scalar\uff09\uff0c\u540c\u6837dbeta\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u6807\u91cf\u3002 \u4f60\u53ef\u80fd\u60f3diag\u51fd\u6570\u4f5c\u7528\u5728\u4e00\u4e2a\u6807\u91cf\u4e0a\uff0c\u5176\u8fd4\u56de\u503c\u662f\u4e00\u4e2a1&#215;1\u7684\u77e9\u9635\u3002 \u4f46\u662f\uff0cdiag()\u7684\u8fd4\u56de\u7684\u662f\u4e00\u4e2a&#8230;.\u4e0d\u786e\u5b9a\u7684\u7ed3\u679c\uff0c\u770b\u4e2a\u4f8b\u5b50\u5427\uff1a diag(3) =&gt; 3&#215;3 \u5355\u4f4d\u77e9\u9635 diag(3.9) =&gt; \u8fd8\u662f3&#215;3 \u5355\u4f4d\u77e9\u9635 diag(0) =&gt; \u662f0x0 \u77e9\u9635 diag(-1) =&gt; \u62a5\u9519 diag(c(1, 2, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,15],"tags":[45],"class_list":["post-694","post","type-post","status-publish","format-standard","hentry","category-code","category-statistics","tag-r"],"_links":{"self":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/comments?post=694"}],"version-history":[{"count":0,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/posts\/694\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/media?parent=694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/categories?post=694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhanxw.com\/blog\/wp-json\/wp\/v2\/tags?post=694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}