Upgrade to Pro — share decks privately, control downloads, hide ads and more …

rmarkdown楽しい!:研究の再現性のために/NagoyaR16

95d5cfc0ce395d0bfedeeb92d34261ce?s=47 Yu Tamura
July 23, 2016

 rmarkdown楽しい!:研究の再現性のために/NagoyaR16

研究の透明性と再現性を確保するために,Rのコードと分析結果をRMarkdownを使ってドキュメンテーションする方法を紹介します。

95d5cfc0ce395d0bfedeeb92d34261ce?s=128

Yu Tamura

July 23, 2016
Tweet

More Decks by Yu Tamura

Other Decks in Research

Transcript

  1. rmarkdownָ͍͠ʂ —ݚڀͷ࠶ݱੑͷͨΊʹ— 2016.07.23 Nagoya.R #16 ໊ݹ԰େֶେֶӃࠃࡍ։ൃݚڀՊ D3 ాଜ༞ 1

  2. ֓ཁ • ର৅ • RͰॻ͍ͨίʔυ΍ͦͷ݁ՌΛอଘͨ͠ΓγΣΞ͠ ͨΓ͍ͨ͠ํʢ૝ఆ͍ͯ͠Δͷ͸ओʹݚڀ໨తʣ • ಺༰ • Nagoya.R

    #14ͷʮςΩετΤσΟλΛ࢖͓͏ʯͷ্ Ґޓ׵൛ʢhttps://speakerdeck.com/tam07pb915/ nagoyar15ʣ 2
  3. ͓அΓ • RStudioલఏͷ࿩ʹͳΓ·͢ • RStudio࢖ͬͨ΄͏͕͍͍Ͱ͢ʢ࢖Θͳ͍ཧ༝͕ ͋·Γͳ͍ʣ • ࢀߟɿSapporoR#6 ॳ৺ऀηογϣϯʢhttp:// www.slideshare.net/simizu706/sapporor6ʣ

    • ͱ͘ʹϋϯζΦϯతͳ͜ͱ͸͠·ͤΜ 3
  4. ҰݴͰݴ͏ͱ • rmarkdownָ͕͍͠ • rmarkdownͰ෼ੳίʔυͱ݁ՌΛγΣΞ͠Α͏ • rmarkdown͕͍͍ • ͱʹ͔͘rmarkdown͍͢͝ 4

  5. ͜͏͍͏ͷ࡞Γ͔ͨͬͨ 5 Murakami (2016)

  6. ͜͏͍͏ͷ࡞Γ͔ͨͬͨ 6 Mizumoto, Ikeda, & Takeuchi (2016)

  7. ͳʹ͜ΕHTMLͰશ෦ॻ ͘ͷʁ͑ʁͲ͏͢Δͷʁ 7

  8. R Markdown 8

  9. R Markdownͱ͸ • kazutanઌੜͷࢿྉΛݟ·͠ΐ͏ 9 https://kazutan.github.io/SappoRoR6/rmd_slide.html#/ http://kazutan.github.io/KandaiR1/rmd_intro.html#/

  10. R Markdownͱ͸ • RͰ࢖͑Δmarkdownܗࣜͷݴޠ • ෼ੳʴυΩϡϝϯτ࡞੒͕؆୯ʹͰ͖Δ • ίʔυ+#ίϝϯτΞ΢τΈ͍ͨͳ΋ͷΛ΋ͬͱ៉ྷʹ Ͱ͖Δ •

    ਤ΋Ұॹʹग़ྗՄೳʂ • ෼ੳʹ࢖ͬͨίʔυͱͦͷ݁ՌΛ·ͱΊͨϑΝΠϧΛ ࡞ΕΔ 10
  11. ͳͥR Markdown? • ݚڀͷ෼ੳʹRΛ༻͍Δ͜ͱ͕ͲΜͲΜ૿͖͑ͯ ͍ͯΔ • RΛݚڀʹ༻͍Δେ͖ͳཧ༝͸࠶ݱੑ ʢMizumoto & Plosnky,

    2016) • σʔλͱίʔυ͕͋Ε͹୭Ͱ΋෼ੳ݁ՌΛ࠶ݱ Ͱ͖Δ 11
  12. ͳͥR Markdown? • ͨͩ͠… • Rͷίʔυ͕ެ։͞ΕΔ͜ͱ΋গͳ͚Ε͹ੜσʔλ ͕ެ։͞ΕΔ͜ͱ͸΋ͬͱগͳ͍ • ࿦จΛಡΜ͚ͩͩͰ͸ɼͲ͏͍͏աఔΛܦͯ෼ੳ ͨ͠ͷ͔Θ͔Βͳ͍͜ͱ΋ଟ͍

    • RͷίʔυΛͲΜͲΜެ։͠Α͏ʂ෼ੳͷ݁Ռ΋ؚΊ ͯެ։͠Α͏ʂ 12
  13. R Markdown͸Ͳ͏࢖͏ʁ • RStudio͕ඞཁʢRStudio։ൃνʔϜ͕ RMarkdownΛ࡞͍ͬͯΔʣ • جຊతͳ࡞ۀ͸νʔτγʔτݟΕ͹Ͱ͖Δʂ 13

  14. 14

  15. R Markdown͸Ͳ͏࢖͏ʁ • खॱ1 • File -> New File ->

    R Markdown ·ͨ͸ࠨ্ͷ ΞΠίϯΛΫϦοΫͯ͠R MarkdownΛબ୒ 15
  16. R Markdown͸Ͳ͏࢖͏ʁ • खॱ2 • Document, Presentation, Shiny, From Template

    ͷத͔ΒDocumentΛબ୒ʢεϥΠυ࡞Δͱ͖ ͸Presentationʣ • λΠτϧͱ໊લͷೖྗ • ग़ྗͷબ୒ 16
  17. R Markdown͸Ͳ͏࢖͏ʁ • खॱ3 • ͢ΔͱউखʹϑΝΠϧͷϝλσʔλ৘ใΛ YAMLϑΥʔϚοτͰ࡞ͬͯ͘Ε·͢ • ͜͜Ͱ௚ͯ͠΋OK 17

  18. R Markdown͸Ͳ͏࢖͏ʁ • खॱ3 • ͋ͱ͸markdownܗࣜͰจॻΛॻ͖ͭͭɼνϟ ϯΫͱ͍͏۠੾ΓͰίʔυΛॻ͘ 18 νϟϯΫ։࢝ͷϚʔΫ νϟϯΫͷऴΘΓͷϚʔΫ

  19. R Markdown͸Ͳ͏࢖͏ʁ • खॱ3 • ϑΥʔϚοτ͸νʔτγʔτݟΕ͹Α͍ • # Header1, ##

    Header2 etc. • > block quote, **bold** etc. 19
  20. R Markdown͸Ͳ͏࢖͏ʁ • ```{r }ͷதͰΦϓγϣϯͷࢦఆ΋Մೳ • ίʔυ͸ग़ྗ͢Δ͚Ͳ࣮ߦ͸͠ͳ͍ • ίʔυ͸Ӆͯ݁͠Ռ͚ͩग़ྗ •

    ίʔυ΋݁Ռ΋ग़ྗ͢Δ • ܯࠂϝοηʔδ΍ΤϥʔϝοηʔδΛදࣔ͢Δ 20 etc.
  21. R Markdown͸Ͳ͏࢖͏ʁ • खॱ4 • R MarkdownͰॻ͍ͨ΋ͷʢ֦ுࢠ.rmdʣΛ HTML౳ʹॻ͖ग़͢ • KnitϘλϯԡ͚ͩ͢

    21
  22. ͓͓͓͓͓͓͓͓͓ 22 ͜ͷग़ྗ͞Ε͕ͨ࣌ΊͬͪΌؾ ͍͍࣋ͪͰ͢ͷͰ͓ࢼ͍ͩ͘͠͞

  23. R Markdown͸Ͳ͏࢖͏ʁ • ग़ྗܗࣜ͸HTML͕͍͍ʢσϑΥϧτʣ • Officeͳͯ͘΋Wordग़ྗՄೳ • ͨͩ͠ɼ͋·Γඒ͘͠ͳ͍ • PDFग़ྗ͸৭ʑ໽հ

    • ೔ຊޠͷจࣈίʔυ • Tex؀ڥͰͳ͍ͱͰ͖ͳ͍ 23
  24. ग़ྗͨ͋͠ͱ͸Ͳ͏͢Δʁ • ւ֎ͷJournalͳΒ͍͍ͨͯ͸Supplementary FilesΛఏग़͢Δ ͜ͱ͕Ͱ͖ΔͷͰɼhtmlϑΝΠϧΛ࿦จͱҰॹʹग़ͤ͹Α͍ • ࠷ॳʹ঺հͨ͠Murakami (2016)͸͜ͷλΠϓ • ࠃ಺ͷJournalͳΒɼϦϯΫΛ࿦จதʹॻ͘

    • ࣗ෼ͷ΢ΣϒαΠτɼresearchmapɼΦϯϥΠϯετϨʔ δαʔϏε౳ʑʹΞοϓϩʔυͯ͠ެ։ • Mizumoto, Ikeda, and Takeuchi (2016)͸͜ͷλΠϓ 24
  25. ͓·͚ • ݚڀͷ࠶ݱੑҎ֎ͷ໘Ͱ΋ྑ͍ͱ͜Ζ • ڞಉݚڀʹ͓͚Δ෼ੳ݁Ռͷڞ༗ • ෼ੳ݁Ռ͚ͩͰ͸ͳ͘ɼͲͷΑ͏ͳաఔΛܦͯಘΒ Εͨ݁Ռͳͷ͔΋ڞ༗͢Δ͜ͱ͸ॏཁ • ޙഐɾֶੜͷࢦಋ

    • ࣍ʹಉ͡Α͏ͳ෼ੳΛ͢Δػձ͕͋ͬͨΒͦΕΛݩ ʹRͰ෼ੳ͢Ε͹ྑ͍ 25
  26. ͓ΘΓʹ • ·ͣ͸ɼίϯιʔϧ্Ͱ͸ͳ͘R ScriptϑΝΠϧʹ ίʔυΛॻ͘ΫηΛ͚ͭΔʢࣗ෼ࣗ਎͕͋ͱͰ෼ ੳ΍Γ௚͢ࡍʹ΋ָʣ • ࿦จΛॻ͍ͯ౤ߘ͢Δ͜ͱΛ໨ࢦ͢ͳΒɼ࠷ॳ͔ ΒR MarkdownͰॻ͍͓͍ͯͯଛ͸ͳ͍

    • ͳΜͳΒεϥΠυͩͬͯR MarkdownͰ࡞ΕͪΌ͏ ͔Βޱ಄ൃදͩͬͯR MarkdownͰͰ͖Δ 26
  27. ࢀߟจݙ લా࿨׮ (2015). ʮRͰυΩϡϝϯτੜ੒Λ͠Α͏ʯ Kandai.R #1 Retrieved from http://kazutan.github.io/KandaiR1/rmd_intro.html#/ લా࿨׮

    (2016).ɹʮR MarkdownʹΑΔεϥΠυੜ੒ʯ SappoRo.R #6 Retrieved from https://kazutan.github.io/SappoRoR6/rmd_slide.html#/ Mizumoto, A., Ikeda, M., & Takeuchi, O. (2016). A comparison of cognitive processing during cloze and multiple-choice reading tests using brain activation. ARELE (Annual Review of English Language Education in Japan), 27, 65–80. Murakami, A. (2016). Modeling systematicity and individuality in nonlinear second language development: The case of English grammatical morphemes. Language Learning. Advance Online Publication. doi:10.1111/lang.12166 ਗ਼ਫ༟࢜ (2016).ɹʮSapporoR#6 ॳ৺ऀηογϣϯʯSappoRo.R #6 Retrieved from http://www.slideshare.net/simizu706/sapporor6 27
  28. rmarkdownָ͍͠ʂ ݚڀͷ࠶ݱੑͷͨΊʹ contact info ాଜ ༞ ໊ݹ԰େֶେֶӃੜ yutamura@nagoya-u.jp http://www.tamurayu.wordpress.com/ 28

    • R Markdown ίʔυͱ݁ՌΛυΩϡϝ ϯςʔγϣϯ • HTML • νʔτγʔτݟΕ͹୭Ͱ ΋Ͱ͖Δ • ࠔͬͨΒάάΕ͹