├── .gitignore ├── baseplot1.png ├── baseplot2.png ├── baseplot3.png ├── book ├── assets │ └── assessments │ │ ├── accessingDatainRAssessment.html │ │ ├── assessTemplate.html │ │ ├── dataPandasAssessment.html │ │ ├── emacsBeginningAssessment.html │ │ ├── finalProjectAssessment.html │ │ ├── firstRmdAssessment.html │ │ ├── forLoopPythonAssessment.html │ │ ├── githubIDAssessment.html │ │ ├── githubPullRequestAssmnt.html │ │ ├── hangmanPython.html │ │ ├── hangmanRAssessment.html │ │ ├── installEmacs.html │ │ ├── installXubuntuAssessment.html │ │ ├── plottingRandPyAssessment.html │ │ ├── psychopyAssessment.html │ │ ├── rStudioInstallationWinMacAssessment.html │ │ ├── reportGenAssessment.html │ │ ├── rmd2htmlRstudio.html │ │ └── terminal.html ├── baseplot1.png ├── baseplot2.png ├── baseplot3.png ├── basic-plotting.html ├── beginning-python.html ├── beginning-r.html ├── codeExamples │ ├── brainsInR │ │ ├── brains_in_R_kaitlin.html │ │ └── readme.org │ ├── emacsInit │ │ └── readme.org │ ├── plottingExample │ │ ├── baseplot1.png │ │ ├── baseplot2.png │ │ ├── baseplot3.png │ │ ├── ggplot1.png │ │ ├── plotExampleJuly2022 │ │ │ ├── mypyplot.png │ │ │ ├── myrplot.png │ │ │ ├── readme.org │ │ │ ├── test.html │ │ │ └── test.org │ │ ├── plottingRandPy.html │ │ ├── plottingRandPy.org │ │ ├── py-inter-fit-plt.png │ │ ├── py-inter-plt.png │ │ └── simplePlot.png │ ├── presents │ │ ├── test.png │ │ ├── testBeamer.html │ │ └── testBeamer.org │ ├── reportGen │ │ ├── simplePlot.png │ │ ├── testLatex.html │ │ ├── testLatex.org │ │ ├── testRBabel.html │ │ ├── testRBabel.org │ │ ├── testRBabelBib.html │ │ └── testRBabelBib.org │ ├── simpOrgDemoFile.html │ ├── simpOrgDemoFile.org │ ├── simpleOrgExamples │ │ ├── minimalPython.html │ │ └── minimalPython.org │ └── simplePlot.png ├── contents.html ├── emacs.html ├── example-os.png ├── ggplot1.png ├── index.html ├── linux.html ├── myrplot.png ├── programming-psychology-experiments.html ├── py-inter-fit-plt.png ├── report-writing.html ├── rstudio.html ├── simplePlot.png ├── terminal.html ├── test.png ├── version-control.html └── working-with-data-in-python.html ├── chapters ├── HSQ.zip ├── HSQ │ ├── codebook.txt │ └── data.csv ├── assets │ ├── assessments │ │ ├── accessingDatainRAssessment.org │ │ ├── assessTemplate.org │ │ ├── dataPandasAssessment.org │ │ ├── emacsBeginningAssessment.org │ │ ├── finalProjectAssessment.org │ │ ├── firstRmdAssessment.org │ │ ├── forLoopPythonAssessment.org │ │ ├── githubIDAssessment.org │ │ ├── githubPullRequestAssmnt.org │ │ ├── hangmanPython.org │ │ ├── hangmanRAssessment.org │ │ ├── installEmacs.org │ │ ├── installXubuntuAssessment.org │ │ ├── plottingRandPyAssessment.org │ │ ├── psychopyAssessment.org │ │ ├── rStudioInstallationWinMacAssessment.org │ │ ├── reportGenAssessment.org │ │ ├── rmd2htmlRstudio.org │ │ └── terminal.org │ └── chicago-note-bibliography-16th-edition.csl ├── backup.txt ├── baseplot1.png ├── baseplot2.png ├── baseplot3.png ├── basic-plotting.org ├── beginning-python.org ├── beginning-r.org ├── codeExamples │ ├── brainsInR │ │ ├── brains_in_R_kaitlin.Rmd │ │ ├── brains_in_R_kaitlin.html │ │ └── readme.org │ ├── emacsInit │ │ ├── init.el │ │ └── readme.org │ ├── pandas │ │ └── getDataPandasExample.py │ ├── plottingExample │ │ ├── baseplot1.png │ │ ├── baseplot2.png │ │ ├── baseplot3.png │ │ ├── ggplot1.png │ │ ├── plotExampleJuly2022 │ │ │ ├── mypyplot.png │ │ │ ├── myrplot.png │ │ │ ├── readme.org │ │ │ ├── test.html │ │ │ └── test.org │ │ ├── plottingRandPy.html │ │ ├── plottingRandPy.org │ │ ├── py-inter-fit-plt.png │ │ ├── py-inter-plt.png │ │ └── simplePlot.png │ ├── presents │ │ ├── test.png │ │ └── testBeamer.org │ ├── reportGen │ │ ├── simplePlot.png │ │ ├── test.bib │ │ ├── testLatex.org │ │ ├── testRBabel.org │ │ └── testRBabelBib.org │ ├── simpOrgDemoFile.org │ ├── simplePlot.png │ └── term │ │ └── simpleTermEx.sh ├── contents.org ├── emacs.org ├── example-os.png ├── ggplot1.png ├── i2c4p.bib ├── index.org ├── linux.org ├── myrplot.png ├── programming-psychology-experiments.org ├── py-inter-fit-plt.png ├── report-writing.org ├── rstudio.org ├── simplePlot.png ├── terminal.org ├── version-control.org └── working-with-data-in-python.org ├── ggplot1.png ├── index.html ├── index.org ├── myrplot.png ├── notes4nexttime.org ├── readme.org ├── simplePlot.png └── topics ├── beginningPython.org ├── beginningR.org ├── emacs.org ├── emacsPythonIdeInstructions.org ├── githubIDBasics.org ├── githubPullRequest.org ├── installTestPsychopy.org ├── installUbuntu.org ├── installingR.org ├── installingUbuntu_MacVersion.org ├── intro2TheTerminal.html ├── intro2TheTerminal.org ├── plottingRandPy.org ├── pythonData.org ├── rStudioWinMacFirstSteps.html ├── rStudioWinMacFirstSteps.org ├── readme.org └── reportWriting.org /.gitignore: -------------------------------------------------------------------------------- 1 | auto/ 2 | *.*~ 3 | venv/ 4 | __pycache__/ 5 | *.synctex 6 | .Rhistory 7 | *.aux 8 | *.toc 9 | *.out 10 | *.blg 11 | *.bbl 12 | *.log 13 | *.*# 14 | *.#* 15 | .RData 16 | code/*.pyc 17 | -------------------------------------------------------------------------------- /baseplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/baseplot1.png -------------------------------------------------------------------------------- /baseplot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/baseplot2.png -------------------------------------------------------------------------------- /baseplot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/baseplot3.png -------------------------------------------------------------------------------- /book/assets/assessments/githubIDAssessment.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | GithubID - Assessment 10 | 11 | 12 | 196 | 197 | 198 |
199 |

GithubID - Assessment

200 |
201 |

Table of Contents

202 |
203 | 207 |
208 |
209 | 210 |
211 |

1. Task

212 |
213 |
    214 |
  1. Create a github account.
  2. 215 |
  3. Fork the two course related repositories. 216 |
      217 |
    1. Intro2Computing4Psychology
    2. 218 |
    3. psych363Practice
    4. 219 |
  4. 220 |
  5. Submit a screen short of your github account with appropriate respositories created to the Dropbox on Learn.
  6. 221 |
222 |
223 |
224 | 225 |
226 |

2. Comment

227 |
228 |

229 | This course makes use of github for practicing how to use the version control program git. To do that we will use a popular, public hosting site for sharing code. 230 |

231 |
232 |
233 |
234 |
235 |

Author: Britt Anderson

236 |

Created: 2023-04-23 Sun 11:52

237 |

Validate

238 |
239 | 240 | -------------------------------------------------------------------------------- /book/assets/assessments/installXubuntuAssessment.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | Install Ubuntu - Assessment 10 | 11 | 12 | 196 | 197 | 198 |
199 |

Install Ubuntu - Assessment

200 |
201 |

Table of Contents

202 |
203 | 207 |
208 |
209 | 210 |
211 |

1. Task

212 |
213 |

214 | Demonstrate that you have installed Ubuntu to your computer. If you are one of my uwaterloo students you will do this by uploading a screen shot of your Ubuntu desktop to the Learn Dropbox. Have something open where you can type in your name and student id so that I can verify who is who. 215 |

216 |
217 |
218 | 219 |
220 |

2. Comments

221 |
222 |

223 | There are screen capture tools available for your Ubuntu installation. 224 |

225 |
226 |
227 |
228 |
229 |

Author: Britt Anderson

230 |

Created: 2023-04-23 Sun 11:52

231 |

Validate

232 |
233 | 234 | -------------------------------------------------------------------------------- /book/baseplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/baseplot1.png -------------------------------------------------------------------------------- /book/baseplot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/baseplot2.png -------------------------------------------------------------------------------- /book/baseplot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/baseplot3.png -------------------------------------------------------------------------------- /book/codeExamples/brainsInR/brains_in_R_kaitlin.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 |

fsbrain examples

67 |

Kaitlin Gaerlan

68 |

01/10/2020

69 | 70 |
71 | 72 | 73 |
74 |

Installing fsbrain

75 |

The fsbrain package exists on CRAN To install the package on rstudio, use the following code:

76 |
install.packages("fsbrain");
77 |

You might get a warning message that prompts you to install Rtools, but this package seems to work without it so you can just continue.

78 |
79 |
80 |

Annotated Brain

81 |

Use the following code to load the fsbrain library and download the data needed for the visualizations:

82 |
library("fsbrain");
 83 | fsbrain::download_optional_data();
 84 | subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
 85 | subjects_list = c("subject1", "subject2");
 86 | subject_id = 'subject1';
87 |

You can now use this code to generate a visualization of the brain that divides it into different sections:

88 |
vis.subject.annot(subjects_dir, 'subject1', 'aparc', 'both', views=c('si'));
89 |

A window should open with a brain like the one pictured below, but you should be able to grab it with your mouse and move it around.

90 |
91 |
92 | 93 |

Annotation Style

94 |
95 |
96 |
97 |
98 |

Adding a colourbar

99 |

Using the same data from the first example, you can use this code to create an image that includes a colourbar. This graph is showing the range of thickness in the brain, but you can change the measure to something else like volume. You can also rotate this image once it’s generated.

100 |
rgloptions=list("windowRect"=c(50, 50, 1000, 1000));     # larger plot
101 | surface = 'white';
102 | measure = 'thickness';
103 | vis.subject.morph.native(subjects_dir, subject_id, measure, 'both', views=c('si'), rgloptions=rgloptions, draw_colorbar = TRUE);
104 |
105 |
106 | 107 |

Colourbar Example

108 |
109 |
110 |
111 |
112 |

Lightbox Slices

113 |

If you install and load the “magick” package, you can look at brain volume, which is visualized by brain slices using the code below.

114 |
install.packages("magick")
115 | library("magick")
116 | brain = subject.volume(subjects_dir, subject_id, 'brain') / 255;
117 | bounded_brain = vol.boundary.box(brain, apply=TRUE);
118 | volvis.lightbox(bounded_brain);
119 |
120 |
121 | 122 |

Volume Slices

123 |
124 |
125 |
126 |
127 |

Masks

128 |

You can mask certain areas to isolate others. Use the code below and then compare to the image generated from the very first example. You’ll notice that it’s the same image but with the green area isolated.

129 |
surface = 'white';
130 | hemi = 'both';
131 | atlas = 'aparc';
132 | region = 'bankssts';
133 | 
134 | # Create a mask from a region of an annotation:
135 | lh_annot = subject.annot(subjects_dir, subject_id, 'lh', atlas);
136 | rh_annot = subject.annot(subjects_dir, subject_id, 'rh', atlas);
137 | lh_label = label.from.annotdata(lh_annot, region);
138 | rh_label = label.from.annotdata(rh_annot, region);
139 | lh_mask = mask.from.labeldata.for.hemi(lh_label, length(lh_annot$vertices));
140 | rh_mask = mask.from.labeldata.for.hemi(rh_label, length(rh_annot$vertices));
141 | 
142 | # visualize it
143 | vis.mask.on.subject(subjects_dir, subject_id, lh_mask, rh_mask);
144 |
145 |
146 | 147 |

Masks with Annotations

148 |
149 |
150 |
151 |
152 |

Surface Options

153 |

For any visualization, you can add and change the “surface” parameter to change the texture of the brain. The past examples use “white” as default, but you can also use “pial” or “inflated”. The code below generates three different images of the same brain, with the three different surfaces.

154 |
vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'))
155 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='pial')
156 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='inflated')
157 |
158 | 159 | 160 | 161 | 162 |
163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /book/codeExamples/brainsInR/readme.org: -------------------------------------------------------------------------------- 1 | * Read-me 2 | 3 | A student in the Fall 2020 offering did a Rmd file on using the Brains in R toolbox. The Rmd file and exported HTML are saved here as an example. 4 | 5 | -------------------------------------------------------------------------------- /book/codeExamples/emacsInit/readme.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+Title: Readme for Emacs Init 3 | 4 | * Purpose 5 | To provide a minimal emacs init example. 6 | 7 | * Emacs initialization 8 | This is the process emacs follows when it starts. All computers and all programs have something similar. Emacs reads a file to see what to do when it starts. It has coded into it where to look for those files and what they are called. Most contemporary advice is to use =~/.emacs.d/init.el= as the initialization file. For that to work you may have to get rid of =~/.emacs= first. 9 | 10 | * The init file 11 | A [[file:init.el][minimal version]] of an emacs init file is found in this same directory. 12 | 13 | 14 | * Testing (requires an internet connection) 15 | 1. Copy the init file as instructed in the commented points numbered 1 to 5 in the init file. 16 | 2. *If* you get no errors then delete those commented lines and save the file. Close emacs. Restart. 17 | 3. *If* you still have no errors run, 18 | =M-x package-list-packages= 19 | 20 | This should refresh the list of packages. Now you can search for (=C-s=) "use-package". When you find it mark it with an "i" for installation, and then an "x" for execute. You should see stuff happening that is the installation. 21 | 4. If that worked without errors open up your init file and uncomment (delete the two semi-colons) the lines for the magit package. Save. Now when you close and restart emacs it should install the magit package. You should see no errors. 22 | ** Orgmode and Org Babel 23 | If you have the above working then you will want to be able to have the right functions set up for using orgmode that the course requires. That will involve some additional elisp code to be cut and pasted into your init.el file. Here is the code you need (the stuff between the begin and end lines): 24 | 25 | #+begin_src elisp :eval never 26 | (setq org-confirm-babel-evaluate nil) 27 | (setq org-babel-python-command "python3") 28 | (org-babel-do-load-languages 29 | 'org-babel-load-languages 30 | '((emacs-lisp . t) 31 | (R . t) 32 | (python . t))) 33 | #+end_src 34 | 35 | You may need to save, and restart emacs for this to take effect. 36 | ** Using Emacs and Org for Running R and Python 37 | In addition to what you do in emacs you need to have installed R and python to your computer first. Then, if you want some nice syntax highlighting for python install the =elpy= package. And to be able to run =R= inside emacs install the ess package. Below are the two "use-package" snippets you will need to add to your init.el file to get them downloaded and installed the next time you start emacs[fn:1]. 38 | 39 | #+begin_src elisp :eval never 40 | (use-package elpy 41 | :ensure t 42 | :init (elpy-enable)) 43 | 44 | (use-package ess 45 | :ensure t 46 | ) 47 | #+end_src 48 | 49 | * Footnotes 50 | 51 | [fn:1] There are ways to trigger this installation without restarting emacs all the time, but that is a safe way to start and helps you see when you have made an error. Then when you start emacs it will warn you if there is a syntax error in your start-up (init) script. 52 | -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/baseplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/baseplot1.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/baseplot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/baseplot2.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/baseplot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/baseplot3.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/ggplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/ggplot1.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/plotExampleJuly2022/mypyplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/plotExampleJuly2022/mypyplot.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/plotExampleJuly2022/myrplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/plotExampleJuly2022/myrplot.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/plotExampleJuly2022/readme.org: -------------------------------------------------------------------------------- 1 | A simple org file for testing plotting in python and R that worked in July 2022 on xubuntu. 2 | -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/plotExampleJuly2022/test.org: -------------------------------------------------------------------------------- 1 | #+Title: New test file for plotting 2 | 3 | * Python 4 | 5 | 6 | #+begin_src python :session *tst* :results silent :exports code 7 | import random as r 8 | import matplotlib 9 | from matplotlib import pyplot as plt 10 | #+end_src 11 | 12 | #+begin_src python :session *tst* :results file replace :exports both 13 | x = [r.random() for _ in range(10)] 14 | y = [r.random() for _ in range(10)] 15 | plt.plot(x,y,'bo') 16 | plt.savefig('./mypyplot.png') 17 | './mypyplot.png' 18 | #+end_src 19 | 20 | #+RESULTS: 21 | [[file:./mypyplot.png]] 22 | 23 | * R 24 | 25 | 26 | #+begin_src R :session *rtst* 27 | x = rnorm(10) 28 | y = rnorm(10) 29 | x 30 | #+end_src 31 | 32 | #+RESULTS: 33 | | -1.02260337386554 | 34 | | -0.970579796288701 | 35 | | 0.590838748829838 | 36 | | -1.24564293974992 | 37 | | 0.57971124057528 | 38 | | 0.0368641706338224 | 39 | | 1.09273067999275 | 40 | | 1.16276136392997 | 41 | | 0.720597366358001 | 42 | | 0.170190446483275 | 43 | 44 | #+begin_src R :session *rtst* :results output graphics file :file ./myrplot.png :exports both 45 | plot(x,y) 46 | #+end_src 47 | 48 | #+RESULTS: 49 | [[file:./myrplot.png]] 50 | -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/py-inter-fit-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/py-inter-fit-plt.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/py-inter-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/py-inter-plt.png -------------------------------------------------------------------------------- /book/codeExamples/plottingExample/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/plottingExample/simplePlot.png -------------------------------------------------------------------------------- /book/codeExamples/presents/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/presents/test.png -------------------------------------------------------------------------------- /book/codeExamples/presents/testBeamer.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:2 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testBeamer 7 | #+date: <2019-12-03 Tue> 8 | #+author: Britt Anderson 9 | #+email: britt@uwaterloo.ca 10 | #+language: en 11 | #+select_tags: export 12 | #+exclude_tags: noexport 13 | #+creator: Emacs 26.3 (Org mode 9.2.6) 14 | #+latex_class: article 15 | #+latex_class_options: 16 | #+latex_header: 17 | #+latex_header_extra: 18 | #+description: 19 | #+keywords: 20 | #+subtitle: 21 | #+latex_compiler: pdflatex 22 | #+date: \today 23 | #+startup: beamer 24 | #+Latex_Class: beamer 25 | #+Latex_Class_Options: [bigger] 26 | #+Beamer_Frame_Level: 2 27 | 28 | * This is the title of my slide show 29 | 30 | ** This is a slide 31 | Here is some important text. 32 | 33 | ** Another side with some math 34 | $\Sigma_{i=1}^n i$ 35 | 36 | 37 | ** Let's look at some code 38 | 39 | What is the correlation between height and weight in women? We can use the built in dataset =women= in R. 40 | 41 | #+Begin_src R :exports both :results output 42 | print(with(women,cor(height,weight))) 43 | #+End_src 44 | 45 | #+RESULTS: 46 | : [1] 0.9954948 47 | 48 | ** Including a plot 49 | 50 | #+Begin_src R :exports both :results value graphics :file test.png :height 200 :width 300 51 | print(with(women,plot(height,weight))) 52 | #+End_src 53 | 54 | #+Caption: Scatterplot of Women's Heights and Weights 55 | #+RESULTS: 56 | [[file:test.png]] 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /book/codeExamples/reportGen/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/reportGen/simplePlot.png -------------------------------------------------------------------------------- /book/codeExamples/reportGen/testLatex.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | testLatex 10 | 11 | 12 | 196 | 197 | 198 |
199 |

testLatex

200 |

201 | This is a test of latex compiliation. 202 |

203 | 204 |

205 | If you type C-c C-e l p you should create a pdf version of this document. Test that it works by changing the title and author above and seeing the new names in your output. 206 |

207 |
208 |
209 |

Date: \today

210 |

Author: Britt Anderson

211 |

Created: 2023-04-23 Sun 11:52

212 |

Validate

213 |
214 | 215 | -------------------------------------------------------------------------------- /book/codeExamples/reportGen/testLatex.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testLatex 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | This is a test of latex compiliation. 24 | 25 | If you type ~C-c C-e l p~ you should create a pdf version of this document. Test that it works by changing the title and author above and seeing the new names in your output. 26 | 27 | -------------------------------------------------------------------------------- /book/codeExamples/reportGen/testRBabel.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | testRBabel 10 | 11 | 12 | 196 | 197 | 198 |
199 |

testRBabel

200 |

201 | This is to test your installation of the files and programs needed to make a simple report. To compile to pdf use C-c C-e l p. 202 |

203 | 204 |

205 | This loads an R library 206 |

207 |
208 |
library(random)
209 | 
210 |
211 | 212 | 213 |

214 | Now we will see if we can some source code and a simple plot for our export. 215 |

216 | 217 |
218 |
x = 1:10
219 | y = rnorm(10)
220 | print(mean(y))
221 | 
222 |
223 | 224 |
225 | 0.288291754111168
226 | 
227 | 228 | 229 |
230 |
plot(x,y,type = 'b')
231 | 
232 |
233 |
234 |
235 |

Date: \today

236 |

Author: Britt Anderson

237 |

Created: 2023-04-23 Sun 11:52

238 |

Validate

239 |
240 | 241 | -------------------------------------------------------------------------------- /book/codeExamples/reportGen/testRBabel.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testRBabel 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | This is to test your installation of the files and programs needed to make a simple report. To compile to pdf use ~C-c C-e l p~. 24 | 25 | This loads an R library 26 | #+Begin_src R :session *testR* 27 | library(random) 28 | #+End_src 29 | 30 | #+RESULTS: 31 | | random | 32 | | stats | 33 | | graphics | 34 | | grDevices | 35 | | utils | 36 | | datasets | 37 | | methods | 38 | | base | 39 | 40 | 41 | Now we will see if we can some source code and a simple plot for our export. 42 | 43 | #+begin_src R :session *testR* :exports both 44 | x = 1:10 45 | y = rnorm(10) 46 | print(mean(y)) 47 | #+end_src 48 | 49 | #+RESULTS: 50 | : 0.149571258953334 51 | 52 | #+begin_src R :session *testR* :exports both :results graphics :file "simplePlot.png" 53 | plot(x,y,type = 'b') 54 | #+end_src 55 | 56 | #+RESULTS: 57 | [[file:simplePlot.png]] 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /book/codeExamples/reportGen/testRBabelBib.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testRBabel 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: \bibliographystyle{plain} 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | 24 | 25 | 26 | This is to test your installation of the files and programs needed to make a simple report. To compile to pdf use ~C-c C-e l p~. 27 | 28 | This loads an R library 29 | #+Begin_src R :session *testR* 30 | library(random) 31 | #+End_src 32 | 33 | 34 | Now we will see if we can some source code and a simple plot for our export. 35 | 36 | #+begin_src R :session *testR* :exports both 37 | x = 1:10 38 | y = rnorm(10) 39 | print(mean(y)) 40 | #+end_src 41 | 42 | #+RESULTS: 43 | : 0.18479671870621 44 | 45 | #+begin_src R :session *testR* :exports both :results graphics :file "simplePlot.png" 46 | plot(x,y,type = 'b') 47 | #+end_src 48 | 49 | ** Testing Citations 50 | 51 | This stackexchange [[https://tex.stackexchange.com/questions/114864/how-to-get-bibtex-to-work-with-org-mode-latex-export][question]] may be useful if you have trouble getting things to work. 52 | 53 | And the ta in the class wrote this article \cite{turpin2019bullshit} 54 | 55 | 56 | I wrote a book about using computers in psychology \cite{anderson2014computational}. 57 | 58 | 59 | 60 | 61 | #+latex: \bibliography{test} 62 | 63 | -------------------------------------------------------------------------------- /book/codeExamples/simpOrgDemoFile.org: -------------------------------------------------------------------------------- 1 | #+Title: This is a title 2 | 3 | * This is a heading 4 | * This is a subheading 5 | 6 | 1. this is a list item 7 | 2. this should be second 8 | 3. this is another list item 9 | 10 | ** Let's make a link 11 | 12 | [[https://uwaterloo.ca][University of Waterloo]] 13 | 14 | ** Let's try R 15 | 16 | #+Begin_src R :exports both 17 | a <- 2 18 | b <- 2 19 | print(a+b) 20 | #+end_src 21 | 22 | #+RESULTS: 23 | : 4 24 | 25 | 26 | -------------------------------------------------------------------------------- /book/codeExamples/simpleOrgExamples/minimalPython.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 196 | 197 | 198 |
199 |
200 |
return(2+2)
201 | 
202 |
203 | 204 |
205 | 4
206 | 
207 |
208 |
209 |

Author: Britt Anderson

210 |

Created: 2023-06-21 Wed 17:18

211 |

Validate

212 |
213 | 214 | -------------------------------------------------------------------------------- /book/codeExamples/simpleOrgExamples/minimalPython.org: -------------------------------------------------------------------------------- 1 | #+begin_src python :results function :exports both 2 | return(2+2) 3 | #+end_src 4 | 5 | #+RESULTS: 6 | : 4 7 | -------------------------------------------------------------------------------- /book/codeExamples/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/codeExamples/simplePlot.png -------------------------------------------------------------------------------- /book/example-os.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/example-os.png -------------------------------------------------------------------------------- /book/ggplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/ggplot1.png -------------------------------------------------------------------------------- /book/myrplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/myrplot.png -------------------------------------------------------------------------------- /book/py-inter-fit-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/py-inter-fit-plt.png -------------------------------------------------------------------------------- /book/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/simplePlot.png -------------------------------------------------------------------------------- /book/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/book/test.png -------------------------------------------------------------------------------- /chapters/HSQ.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/HSQ.zip -------------------------------------------------------------------------------- /chapters/HSQ/codebook.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/HSQ/codebook.txt -------------------------------------------------------------------------------- /chapters/assets/assessments/accessingDatainRAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Accessing Data in R - Assessment 2 | 3 | * Task 4 | Provide an org or Rmd file that demonstrates the following functions with the *cars* data set in R. 5 | * Goal/Purpose 6 | Demonstrate some of the basic data processing tasks in R. 7 | * Instructions 8 | ** General 9 | Using the built in data set *cars* demonstrate sorting and selection. 10 | ** Detailed 11 | Produce a Rmd or org file that executes each of the following processes or provides as a result the answer to the listed questions. 12 | - Sort (or ~order~) cars by the ~dist~ variable. 13 | - Find the =mean= and =standard deviation= of the speed of the cars. 14 | - Print the name of the other built-in data sets (this code may help) 15 | #+begin_src R :export code :results hidden :eval never 16 | for (i in data()$results[,3]) { 17 | print(i) 18 | } 19 | #+end_src 20 | - Using any other data set find: 21 | 1. Print the column names? 22 | 2. Print how many rows? 23 | 3. Tell me what the /comment/ designator is for R? 24 | 4. Tell me what the ending extension is for an R script? 25 | 26 | * Comments 27 | ** Hints 28 | - To find the names of /columns/ in a data.frame try the =names= function (~names(cars)~). 29 | - To get help you can type a *?* at the command line of the R interpreter. 30 | - You may need to find an online resource you like for R help, for example to find out what the name of the function is for standard deviation. It is not "standard deviation", but something much shorter. 31 | - Extensions: For instance "docx" is the extension for a word file and "py" is the extension for a python script. 32 | 33 | -------------------------------------------------------------------------------- /chapters/assets/assessments/assessTemplate.org: -------------------------------------------------------------------------------- 1 | #+Title: Title - Assessment 2 | 3 | * Task 4 | 5 | * Goal/Purpose 6 | 7 | * Instructions 8 | 9 | ** General 10 | 11 | ** Detailed 12 | 13 | * Comments 14 | -------------------------------------------------------------------------------- /chapters/assets/assessments/dataPandasAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Practicing Pandas for Data Analysis 2 | 3 | * Task 4 | You will 5 | 1. Download a data set in python 6 | 2. Unzip the data set 7 | 3. Tell me the names of all the columns 8 | 4. Tell me the length of one of the rows 9 | 5. And tell me the mean[fn:1] of one of the columns subset by rows[fn:2]. 10 | 11 | * Requirements 12 | Your submission will be either an org[fn:3] file with code blocks that let me execute each of these steps by myself interactively one at a time. Or a python script that I can run from the command line and that will perform each of these functions displaying its output to ~stdout~. Stdout is the linux name for printing to the screen in the terminal. For example, when you do ~ls~ to list the names of files in a directory you are directing to stdout. 13 | 14 | * Comments 15 | Don't start by writing this as a script. That will almost certainly be too hard. Begin by doing this interactively, perhaps at a python interpreter until you get the code for a particular step done corrrectly. Then copy that code to your file and and test that it still works; that something did not get messed up in the copying and pasting. 16 | Once you have the data in your interpreter, don't just rush through. Take some time to play with various pandas commands or exercises such as examples you can find [[https://www.w3resource.com/python-exercises/pandas/index-data-series.php][here]] to generally grow more familiar with the package. 17 | * Footnotes 18 | 19 | [fn:1] Or some other simple statistic appropriate to the data, e.g. if your data was /categorical/ you might give me the number of rows for each type of category. 20 | [fn:2] An example of this is that if you had columns for heights and genders you could output the average height of men, women, and other. 21 | [fn:3] To make some nicer formatting and help available when using python from within emacs checkout the ~elpy~ [[https://elpy.readthedocs.io/en/latest/introduction.html#installation][package]]. 22 | 23 | 24 | -------------------------------------------------------------------------------- /chapters/assets/assessments/emacsBeginningAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Beginning With Emacs Assessment 2 | * Task 3 | Create and submit an .org file edited in emacs. We will recreat the original [[file:firstRmdAssessment.org][Rmd exercise]] using this alternative markup syntax. 4 | * General Instructions 5 | 1. Create an org file in emacs using your name as the file name. 6 | 2. Create a major heading for you identifying information and put your name in bold and your student id in italics. 7 | 3. Create a functioning link to a favorite website relevant to science or research. 8 | 4. Create an inline link to an image from the web that will appear in your exported version. 9 | 5. Verify that when you export your org file =C-c C-e h h= to html that you can open your html output and that it shows the properly configured output. 10 | 11 | 12 | -------------------------------------------------------------------------------- /chapters/assets/assessments/finalProjectAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Final Project 2 | 3 | * Task 4 | Deliver a reproducible research report. 5 | 6 | * Objective 7 | Show that you have the coding and computer skills to implement an experiment in code, collect some (toy)data, analyze that data and produce a report that compiles all that material into a single pdf output, /and/ in a way that would allow another scientist to repeat your analysis and recompile your report. 8 | 9 | * Details 10 | 1. I will get an org file that I can compile to produce the final report. 11 | 2. You will also upload the pdf file that you compiled to demonstrate your ability to compile the raw file. 12 | 3. You will also upload the .py file that executed the task you used for collecting data. 13 | 4. You will have collected data and saved that data in a /csv/ format and you will upload the csv data file. 14 | 5. Your org file will include: 15 | 1. Title 16 | 2. Date 17 | 3. Authors 18 | 4. Sections for each of the standard research report sections.[fn:1] 19 | 5. Your /methods/ section should include computational tools you used. 20 | 6. Your /results/ section must include the code for the analyses in the body of the org file so that I can recompile and reproduce the analyses. As a minimum you should include: 21 | - some descriptive statistics (e.g. how many participants or total trials). 22 | - at least one statistical test (e.g. a t-test comparing the means of two groups or conditions). This will depend on the data you collect and the experiment you run. 23 | - at least one plot (again, the code generating this plot must be in the research report org file; don't create it in photoshop or something and simply insert it). 24 | 7. Minimal /introduction/ and /discussion/ sections that must include at least one citation each. 25 | 8. The citations must appear in a /Reference/ section. I don't care about whether it is APA style or not. 26 | 27 | ** Experiments You Can Pick From 28 | Each team will conduct a different experiment. If you want to suggest something not on this list get my approval first. Even if you do select something from the list make sure some other group is not already doing it by writing to me first. 29 | 30 | 1. [[https://en.wikipedia.org/wiki/Stroop_effect][Stroop Test]] 31 | 2. [[https://en.wikipedia.org/wiki/Pair_by_association][Paired Associate]] 32 | 3. [[https://en.wikipedia.org/wiki/Implicit-association_test][Implicit Association]] 33 | 4. [[https://en.wikipedia.org/wiki/Eriksen_flanker_task][Eriksen Flanker]] 34 | 5. [[https://en.wikipedia.org/wiki/Contextual_cueing_effect#/media/File:Contextual_cueing_example.png][Contextual Cuing]] 35 | 6. [[https://en.wikipedia.org/wiki/Deese%E2%80%93Roediger%E2%80%93McDermott_paradigm][False Memories]] 36 | 7. [[https://en.wikipedia.org/wiki/Sequence_learning][Sequence Learning]] 37 | 38 | * Footnotes 39 | 40 | [fn:1] Don't go overboard with the text in each of these sections. This final project is more about showing you have the skills to program an experiment, analyze the data, and combine it into a report, then it is the actual content of your data or the motivations for the experiment. 41 | -------------------------------------------------------------------------------- /chapters/assets/assessments/firstRmdAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Your First Rmd File - Assessment 2 | 3 | * Tasks 4 | Create and save an Rmd file making use of basic markdown conventions. 5 | 1. Put your name in *bold*. 6 | 2. Put your student ID or other value in /italic/. 7 | 3. A functioning link to a page on the web like [[https://brittlab.uwaterloo.ca][brittlab]] 8 | 4. An image link that will inline on export. For example: 9 | 10 | [[https://imgs.xkcd.com/comics/linux_user_at_best_buy.png]] 11 | 12 | * Comments 13 | We will be using various markdown dialects to combine text, references, code, data, and analyses in making reproducible research reports. The goal of this assignment is to get you started on discovering and using some of the markdown conventions that will enable you to do so. RStudio has a built in cheat sheet for markdown, but you can easily find [[https://en.wikipedia.org/wiki/Markdown][others]] on line. There are several different dialects of markdown. 14 | -------------------------------------------------------------------------------- /chapters/assets/assessments/forLoopPythonAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: For Loop with Python 2 | 3 | * Task 4 | Write a function that will print a list of characters unsorted, sorted, and combined. To complete this task you will need to be familiar with how to write a *for loop*, use python's *indexing*, and also how to use the [[https://realpython.com/python-formatted-output/][print format command]] [fn:1] 5 | 6 | * What it should look like 7 | I run your function with "trib". It prints t, r, i, b, then prints b, i, r, t, and then prints something like "The first letter of list one is 't', but it is 'b' in the sorted list... and so on through all the letters. 8 | 9 | * Detailed Instructions 10 | 1. Create a list of at least 8 individual characters. 11 | 2. Make sure they are **not** in alphabetical order 12 | 3. Print the letters one at a time. 13 | 4. Print the letters sorted alphabetically one at a time, but /do not/ overwrite your original list. 14 | 5. Print the letters from both lists with a format command that says which position the letter is in. 15 | 16 | * Comments 17 | ** Hints 18 | Remember not to re-invent the wheel. For example, does python have a function for sorting lists? Can you turn a "string" into a python list that would allow you to use indices? Lastly, note that a for loop can use more than one variable at a time. For my version I have a line that reads, 19 | 20 | #+begin_src python :exports code :results never 21 | for i,l in enumerate(zip(myList,sorted(myList))): 22 | #+end_src 23 | 24 | ** How I Will Grade 25 | I will run your program from the command line e.g. =python firstLast2LstsSorted.py=. It will either spit out the correct lists or it won't. If it does you get full credit, and if not I will give partial credit and you can try to fix it for more points. 26 | 27 | * Footnotes 28 | 29 | [fn:1] Not shown in lecture, but explained in many [[https://realpython.com/python-formatted-output/][places]]. Look for the =string.format()= method. 30 | -------------------------------------------------------------------------------- /chapters/assets/assessments/githubIDAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: GithubID - Assessment 2 | 3 | * Task 4 | 1. Create a [[https://github.com/][github account]]. 5 | 2. *Fork* the two course related repositories. 6 | A. [[https://github.com/brittAnderson/Intro2Computing4Psychology][Intro2Computing4Psychology]] 7 | B. [[https://github.com/brittAnderson/psych363Practice][psych363Practice]] 8 | 3. Submit a screen short of your github account with appropriate respositories created to the Dropbox on Learn. 9 | 10 | * Comment 11 | This course makes use of [[https://github.com][github]] for practicing how to use the version control program git. To do that we will use a popular, public hosting site for sharing code. 12 | -------------------------------------------------------------------------------- /chapters/assets/assessments/githubPullRequestAssmnt.org: -------------------------------------------------------------------------------- 1 | #+Title: Git Pull Request and Issues Assessment 2 | 3 | * Task 4 | 1. Generate a pull request for the [[https://github.com/brittAnderson/psych363Practice][psych363Practice]] repository on Github. 5 | 2. Generate an issue for the psych363Practice repository. 6 | 7 | * Comment 8 | This course makes use of [[https://github.com][github]] for practicing how to use the version control program git. An important part of collaborating on code (or other material hosted on github, which might include text files) is to be able to give back or to alert the owner to a problem. This requires that you can both generate a *pull request* and that you can *open an issue.* 9 | 10 | * Steps ([[https://vimeo.com/channels/i2c4p/456349516][video: steps illustrated]]) 11 | 1. Previously you should have /forked/ the psych363Practice repository. 12 | 2. Next you will need to clone your fork to your laptop. 13 | 3. Check that you have your fork as a /remote./ 14 | 4. Add *my original* version of the repository as a second remote. 15 | 5. To make sure you have the latest code, including all the other pulls generated by other students in the course you will want to: 16 | 1. /Pull/ from *my original* repo. 17 | 2. Accept and merge the changes if necessary. 18 | 3. /Push/ these new changes to *your fork* on github. 19 | 4. Verify the new changes made it there by looking at your fork in your browser. You may have to refresh your browser to see the changes. 20 | 5. Now, in the =gitnames= subdirectory add a file with .txt. Put some simple sentence in it. 21 | 6. *Add* this file. 22 | 7. *Commit* this change. 23 | 8. /Push/ to your fork. 24 | 9. In your web browser initiate a *pull request.* 25 | 6. When I receive your pull request I will accept it and give you half credit for this assignment (if you are a UWloo student). 26 | 7. Next, open an /issue./ Just give it a simple title and make a simple statement. Our goal is to practice the process. Note the number of your issue and upload this number to the dropbox with your github name so I can match issues and pull requests to students. 27 | 28 | Important Note: To help each other learn how to use git, github, and 29 | the material of this course, whether or not you are a UWaterloo 30 | student, use the [[https://github.com/brittAnderson/Intro2Computing4Psychology/issues][issue function in the Intro2Computing4Psychology]] 31 | repository to report your problems and confusions. That issue record 32 | will persist for future visitors to the repo who have the same 33 | question see how we dealt with it. 34 | -------------------------------------------------------------------------------- /chapters/assets/assessments/hangmanPython.org: -------------------------------------------------------------------------------- 1 | #+Title: Hangman in Python (starter kit) 2 | 3 | * Words of Encouragement 4 | This is the first non-trivial thing we will have done in the programming line. Do not get too frustrated if it takes you several submissions to get things right. 5 | 6 | Remember our goal is to learn some programming basics, not to write a production quality game of hangman. It is better to spend your time perfecting your ability to get the basic pieces 7 | 8 | We all start as beginners. Be patient with yourself. 9 | 10 | It is *fine* to collaborate, but don't just turn in a working piece of code you got from someone, because while that will give you points, it will not provide you an education. Make sure you can write it yourself from scratch even if that is only after you have worked on it together with someone. 11 | 12 | How to work. I like the idea of having a console open on one side for testing and another editor window where I can write code. I write in one window. Test in the other, and go back and forth to get something I can use. Ask me to demo in class if you are not clear on what this is supposed to look like. 13 | 14 | * Task 15 | To write the beginning pieces of a hangman game in python. This version will [[https://en.wikipedia.org/wiki/Hard_coding][hard code]] the word to be guessed. It will not produce any sort of graphic, You will ask the user for letters and report if the player spells out the word or not. Depending on how fast you master that, I may suggest further improvements when you submit. 16 | 17 | * Detail - tackle this in steps. 18 | 1. Look up how to get user input from python on the command line. 19 | Write a script[fn:1] that when run from the terminal (command line) asks for a word, and prints it out. 20 | 2. Write a ~function~ that takes as input a word. The function asks the user to guess a letter and returns *a list of* indices of the positions where the letter exists in the word. An empty list means the letter is not to be found in the word. Otherwise, the elements of this list are the indices where that letter is found. For example, if the word were "tree" and the letter "e" was guessed you would get back =[2,3]= from this function, but you would get back =[]= if the user supplied the letter were "s".[fn:2] 21 | 3. Write a function that accepts as input a number, which we will interpret as the maximum number of guesses a player is allowed (call it ~max_times~). This function will use a word that you have hard coded as a constant and will loop through the guessing function above for max_times or until all the letter in the word have been guessed. 22 | 4. If the number of user guesses is greater than ~max_times~ your program should print "You lose." If the user guesses all the letters print "You win". And exit the program. 23 | 24 | * Comments 25 | ** How I Will Grade 26 | I will run your program from the terminal, and it will work as above or it will not. If it does, I will give you full marks, if not, I will give partial credit and allow you to try and fix the mistakes. 27 | ** Hints 28 | You might find it useful to learn about python's =in= operator, and to think about how you might use the =enumerate= function we used in the [[file:forLoopPythonAssessment.org][for loop in python assessment]]. 29 | Remember to eliminate the letters from your word as they are guessed. For example if the word is tree, and I guess "e", your word should become "tr". That means you may find it easier to keep track of the indices that are *not* equal to the guessed letters. 30 | If a brute force solution comes quickly think about re-writing your answer using a [[https://www.programiz.com/python-programming/list-comprehension][list comprehension]]. 31 | If you have more of a programming background try adding in some additional features of the game. Can you get a random word from the internet? Can you let the player give the word and the computer guess letters? Could you output where the guessed characters appear in the word before the player has to make their next guess. Could you generate some [[https://codegolf.stackexchange.com/questions/135936/ascii-hangman-in-progress][simple ascii art of the hangman character]]? 32 | 33 | * Footnotes 34 | [fn:2] Why is it 2,3 and not 3,4? 35 | 36 | [fn:1] A script is a file that ends with .py and that I can call from the terminal. If your script is named hangman.py then things should work when I do ~python hangman.py~ in my terminal window. 37 | 38 | -------------------------------------------------------------------------------- /chapters/assets/assessments/hangmanRAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Hangman in R 2 | 3 | * Words of Encouragement 4 | This was hard in Python, and won't be trivial in R, but having done it once, the translation should be easier. But R is not as nice when processing text as is Python to text process as Python. So, I will be expecting less full featured functions. Just demonstrate you understand the concepts of what we are trying to achieve. 5 | * Task 6 | To write the beginning pieces of a hangman game in R. This version will [[https://en.wikipedia.org/wiki/Hard_coding][hard code]] the word to be guessed. It will not produce any sort of graphic, but merely ask for letters and report if the player spells out the word or not. Note that as R is harder to run as a program from the command line I will test your code by loading it into my R interpreter. The command for this is =source=. I will download your =filename.R= and then I will =source(filename.R)=. Next, I will execute whatever function you tell me to. Remember, your script can contain comments so I should be able to tell what you want me to do just by reading your .R file. 7 | * Detail (basically the same as before, with minor adaptations) 8 | 1. Get input from me, the user. 9 | 2. Write a function that takes that input and and returns *a list of* indices of the positions where the input letter exists in your hard-coded word. An empty list means the letter is never in the word. Otherwise the elements of this list are the indices where that letter is found. For example, if the word were tree and the letter "e" you would get back =[1] 3 4= from this function. Remember that R starts counting from 1, not zero. , but would get back =integer(0)= if the letter were 's'. This weirdness tells you why R might be nicer for statistics, but not for text processing. Different task require different tools. 10 | 3. Write a function that loops through the above process a certain number of times. 11 | 4. Make the function terminate when all the letters are guessed or max number of guesses is exceeded. 12 | 13 | * Comments 14 | ** How I Will Grade 15 | I will load (source) your file and try to test the functions. If they basically work then you will get the credits. 16 | ** Hints 17 | You might find the following R functions helpful: 18 | 1. which 19 | 2. strsplit 20 | 3. unlist 21 | 4. != 22 | 5. Using a variable more than once, e.g. al[al != "e"] 23 | 24 | -------------------------------------------------------------------------------- /chapters/assets/assessments/installEmacs.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Install Package - Emacs Assessment 2 | 3 | * Task 4 | 5 | Demonstrate that you have a functioning Linux installation and that you can use the package management system. 6 | 7 | * Details 8 | 1. Open up a terminal. In Xubuntu go to the upper left of your desktop and click the icon. Type terminal in the search bar and select the top option. 9 | 2. When the terminal opens type ~sudo apt update~ to update your list of currently available packages. This package manager works for Xubuntu, but will not be found on all Linux distributions. 10 | 3. Type ~sudo apt install emacs~ 11 | 4. Follow the on screen instructions. When installation is complete type, in the same terminal window, ~emacs &~. 12 | 5. Emacs will open. Use the ~File~ menu to create a new file with a sensible name in the file itself type in your name and student id and save the file as type ~.org~. Make a note of where you save it, because you will need to ... 13 | 6. Log on to learn and submit the file. 14 | 15 | * Comments 16 | 17 | If you want to try something fun open the file back up in emacs after doing the above. Then type ~C-c C-e h h~. ~C-c~ means typing the "Ctrl" key and the lower case "c" key simultaneously. The spaces between those instructions mean you have a sequence of four key chords to enter. If all goes well you have just created a web page of that file. You should be able to open it in your browser. To test, use the file browser in Xubuntu to navigate to the file with the name you used above, but now ending in ~.html~ and not the ~.org~ one. Double click and your web browser should open with that file displayed. 18 | 19 | To get ahead of things and learn more about the org-mode utilities you just used you can search for emacs and orgmode online. Or type ~C-h i~ to open the information functionality and navigate to the orgmode chapter. 20 | 21 | And if you get stressed you can always consult Emacs' built in therapist with ~M-x doctor~. 22 | -------------------------------------------------------------------------------- /chapters/assets/assessments/installXubuntuAssessment.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Install Ubuntu - Assessment 2 | 3 | * Task 4 | 5 | Demonstrate that you have installed Ubuntu to your computer. If you are one of my uwaterloo students you will do this by uploading a screen shot of your Ubuntu desktop to the Learn Dropbox. Have something open where you can type in your name and student id so that I can verify who is who. 6 | 7 | * Comments 8 | 9 | There are [[https://linuxconfig.org/how-to-take-a-screenshot-on-ubuntu-20-04-focal-fossa-linux][screen capture tools]] available for your Ubuntu installation. 10 | -------------------------------------------------------------------------------- /chapters/assets/assessments/plottingRandPyAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Plotting Assessment: R and Python 2 | 3 | * Task 4 | 1. Do exactly what we did in the topic, but reverse which language you use to do each. 5 | 2. Use python functions to generate a sequence (for the x), a function to get a y from the x, and a random number generator to get y_randoms as long as the x and y values, and then generate a line and scatter plot for your x and y's and y_random's all on the same plot. 6 | 3. The interaction plot should be done with R 7 | 8 | * What to submit 9 | An *.org file that includes code blocks for the plots (and the included files for the plots) that accomplish the assigned tasks. It should export to a nice html (see the example exported from the topic file in the 10 | [[file:~/gitRepos/Intro2Computing4Psychology/chapters/codeExamples/plottingExample/plottingRandPy.org][codeExamples]] subdirectory). 11 | 12 | 13 | * Hints 14 | - R can read in data from a url as well as pandas. See [[https://stackoverflow.com/questions/6299220/access-a-url-and-read-data-with-r][this]]stack overflow question/answer. 15 | - R has a [[https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/interaction.plot][built in function]] for interaction plots that might work. 16 | - It might be easier with ~ggplot~. Here is a [[https://sebastiansauer.github.io/vis_interaction_effects/][blog]] showing how. 17 | - [[https://docs.python.org/3/library/random.html][Random numbers]] are easy in python. 18 | - What you need for [[https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.line.html][plotting lines]] in python is shown in the interaction plot example - just skip the "ols" model part. 19 | -------------------------------------------------------------------------------- /chapters/assets/assessments/psychopyAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Psychopy Assessement 2 | 3 | * Task 4 | Submit a .py file that demonstrates a minimal version of a single trial of a Posner cuing task. 5 | 6 | * Objective 7 | To familiarize yourself with the basic elements of the psychopy library and how to combine a few of them into something that could become a psychology experiment. We will use the [[https://en.wikipedia.org/wiki/Posner_cueing_task][Posner Cuing]] task for this project. 8 | 9 | * Detailed Instructions 10 | Provide me with a python file that, 11 | 1. Imports the psychopy library elements (and any other necessary libraries) in order to, 12 | 2. Places a white cross (or plus sign) at the center of the screen. Make the cross white and the background gray. Imagine the cross is to be our "fixation spot." 13 | 3. After a delay a white square appears to the right or left of fixation (the side to be chose randomly on each trial). 14 | 4. 200 ms after the white square appears a black dot (or filled circle) appears either in the center of the white square or equidistant on the other side. The first if a "valid" cue condition, and the second is "invalid." 15 | 5. Require the user/participant to press the z button on the keyboard if the target (black dot) is on the left and the "/" key if the target is on the right. 16 | 6. After the keypress print to the screen which key was pressed and how much time elapsed between the appearance of the black dot and the key press. This is your reaction time (RT). 17 | 7. _Optional_ if that comes very quickly make a loop to do this ten times and write the results to a file rather than putting them on the screen. 18 | 19 | * Hints 20 | The following psychopy objects may be useful. 21 | 1. Visual.window 22 | 2. Visual.TextStim 23 | 3. Visual.ShapeStim or Visual.Circle 24 | 4. Core.Quit 25 | 5. Clock.Clock 26 | 6. Clock.getTime 27 | 7. Clock.wait 28 | 8. Event.getKeys 29 | 30 | -------------------------------------------------------------------------------- /chapters/assets/assessments/rStudioInstallationWinMacAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Installing RStudio on Windows and Macs 2 | 3 | * Tasks 4 | 1. Install RStudio 5 | 1. This will require that you first install [[https://cran.r-project.org/][R]]. 6 | The download links are on this page. One for each of the major operating systems. 7 | 2. Then you install the appropriate version of [[https://rstudio.com/products/rstudio/download/#download][RStudio Download Page]]. 8 | 2. Verify a successful installation by opening the program and getting it to tell you the answer to ~2+2~. You do this by typing exactly that equation and, depending on your defaults, hitting . 9 | 3. Demonstrate the above with appropriate screen shots submitted to the Learn Dropbox for [[https://learn.uwaterloo.ca/d2l/lms/dropbox/user/folder_submit_files.d2l?db=263433&grpid=0&isprv=0&bp=0&ou=802943][RStudio Installation.]] 10 | 11 | * Comments 12 | We will be using linux based tools predominantly. However, it may take some users awhile to get linux installed and working. Therefore, we can begin our introduction to programming environments and markdown languages by using the RStudio tool installed on the users traditional software. The goal of this assessment is to make sure you can download the tool and get it up and running. *If* you already have Linux installed then do this activity with linux. *If not* return and repeat the exercise after you have successfully installed RStudio in Linux. 13 | -------------------------------------------------------------------------------- /chapters/assets/assessments/reportGenAssessment.org: -------------------------------------------------------------------------------- 1 | #+Title: Report Generation with Org Babel 2 | 3 | * Purpose 4 | Gain familiarity with report generation using org and babel and the inclusion of code blocks, graphics, and reference sections 5 | 6 | * Task 7 | Provide an org file and its companion bib file that has a 8 | 1. Title 9 | 2. Author 10 | 3. Sections for 11 | - Introduction 12 | - Methods 13 | - Results 14 | - Conclusions 15 | - References 16 | 4. Just have the headings and some minimal text. The purpose here is to get a working skeleton of a file that you can use and adapt later on. 17 | 5. Cut and paste from your earlier examples of Rmd and Org files using R and Python to have some analysis in the results section. Make sure it includes as a minimum: 18 | - one code block 19 | - one figure 20 | - one inline code reference 21 | - one new citation other than the ones that were used in the example. 22 | There are many ways to get references in the bibtex format. Scholar Google can export that format, and so will most of the major journal web pages. 23 | 24 | * Comments 25 | I will evaluate submissions by compiling from org to pdf in my version of emacs. Either I will be able to produce a pdf of your report or I won't. If I can, and it meets all the requirements above then you will get full credit. 26 | -------------------------------------------------------------------------------- /chapters/assets/assessments/rmd2htmlRstudio.org: -------------------------------------------------------------------------------- 1 | #+Title: Rmd to Html Assessment 2 | 3 | * Task 4 | Expand on your Rmd file submitted for Your First Rmd File to include additional material. 5 | 6 | * Goal/Purpose 7 | Markdown allows you to use plain text to give instructions to a /compiler/ to assemble a file with appropriate formatting. My assembling an html file with code and links from a markdown starter file you will see the basics of this approach. 8 | 9 | 1. A simple function definition (illustrations and examples will be provided in the lessons). 10 | 11 | 2. A code block using your function to produce output. 12 | 13 | 3. A for loop that counts from 1 to 10 and prints the even numbers. 14 | 15 | Your submission should include both the Rmd file and the compiled html file produced in RStudio (see lessons for example of what these terms mean and what I am looking for). 16 | 17 | 18 | 19 | * Instructions 20 | 21 | 22 | 1. Take your Rmd file from the first Rmd assessment as a starting point. 23 | 24 | 2. Add a code block with a simple function definition. 25 | 26 | 3. Add another code block using your function to produce output. 27 | 28 | 4. Add a code block that executes a ~for~ loop that counts from 1 to 10 and prints the even numbers. 29 | 30 | 5. Submit both the Rmd file and the compiled html file produced in RStudio (you get the html by using the =knit to html= button in RStudio. 31 | -------------------------------------------------------------------------------- /chapters/assets/assessments/terminal.org: -------------------------------------------------------------------------------- 1 | #+Title: Terminal Assessment 2 | 3 | * Goal 4 | Demonstrate basic knowledge about and usage of the terminal (aka: command line or shell). 5 | 6 | * Tasks 7 | 8 | *Note* This assessment has two parts and asks for two separate files. 9 | 10 | ** Submit a file that answers the following questions: 11 | 1. What is a terminal? 12 | 2. What shell is your version of Xubuntu using? 13 | 3. What is one other shell you might use? 14 | 4. Give two reasons (not more) why one might want to use the terminal. 15 | 5. I mentioned =ssh=. What does ssh stand for and how does it relate to the concept of a shell? 16 | *** File Requirements 17 | 1. Make sure it has your name and student number on it. 18 | 2. Make sure it is in .org format. To do this you will want to, 19 | 1. open Emacs. 20 | 2. open a new file 21 | 3. =save as= (you can try ~C-x C-s~) with a suitable name and the extension ".org". 22 | 4. Give each question its own heading (start the line with a single "*" and a following space). 23 | 5. Put your answer underneath this heading. 24 | 6. Save. 25 | 7. Upload to the "Terminal" dropbox on Learn. 26 | ** Submit a file that does the following: 27 | 1. Can be run as a shell script. 28 | 2. Echos your name to the terminal. 29 | 3. Prints out the current directory. 30 | 4. Name this file as _.sh 31 | 5. Upload to the "Terminal" dropbox on Learn. 32 | 33 | ** Last Thoughts 34 | Enjoy the power the terminal provides, but don't go overboard. https://xkcd.com/196/ 35 | 36 | 37 | -------------------------------------------------------------------------------- /chapters/baseplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/baseplot1.png -------------------------------------------------------------------------------- /chapters/baseplot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/baseplot2.png -------------------------------------------------------------------------------- /chapters/baseplot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/baseplot3.png -------------------------------------------------------------------------------- /chapters/codeExamples/brainsInR/brains_in_R_kaitlin.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "fsbrain examples" 3 | author: "Kaitlin Gaerlan" 4 | date: "01/10/2020" 5 | output: html_document 6 | --- 7 | 8 | ```{r setup, include=FALSE} 9 | chooseCRANmirror(graphics=FALSE, ind=1) 10 | knitr::opts_chunk$set(echo = TRUE) 11 | ``` 12 | 13 | ## Installing fsbrain 14 | 15 | The fsbrain package exists on [CRAN](https://cran.r-project.org/package=fsbrain) 16 | To install the package on rstudio, use the following code: 17 | 18 | ```{r, eval=FALSE} 19 | 20 | install.packages("fsbrain"); 21 | ``` 22 | 23 | You might get a warning message that prompts you to install Rtools, but this package seems to work without it so you can just continue. 24 | 25 | ## Annotated Brain 26 | 27 | Use the following code to load the fsbrain library and download the data needed for the visualizations: 28 | 29 | ```{r,} 30 | library("fsbrain"); 31 | fsbrain::download_optional_data(); 32 | subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir"); 33 | subjects_list = c("subject1", "subject2"); 34 | subject_id = 'subject1'; 35 | ``` 36 | 37 | You can now use this code to generate a visualization of the brain that divides it into different sections: 38 | 39 | ```{r, eval=FALSE} 40 | vis.subject.annot(subjects_dir, 'subject1', 'aparc', 'both', views=c('si')); 41 | ``` 42 | 43 | A window should open with a brain like the one pictured below, but you should be able to grab it with your mouse and move it around. 44 | 45 |
46 | 47 | ![Annotation Style](brain2.JPG) 48 | 49 |
50 | 51 | ## Adding a colourbar 52 | 53 | Using the same data from the first example, you can use this code to create an image that includes a colourbar. This graph is showing the range of thickness in the brain, but you can change the measure to something else like volume. You can also rotate this image once it's generated. 54 | 55 | ```{r, eval=FALSE} 56 | rgloptions=list("windowRect"=c(50, 50, 1000, 1000)); # larger plot 57 | surface = 'white'; 58 | measure = 'thickness'; 59 | vis.subject.morph.native(subjects_dir, subject_id, measure, 'both', views=c('si'), rgloptions=rgloptions, draw_colorbar = TRUE); 60 | ``` 61 | 62 |
63 | 64 | ![Colourbar Example](brain1.JPG) 65 | 66 |
67 | 68 | ## Lightbox Slices 69 | 70 | If you install and load the "magick" package, you can look at brain volume, which is visualized by brain slices using the code below. 71 | 72 | ```{r, eval=FALSE} 73 | install.packages("magick") 74 | library("magick") 75 | brain = subject.volume(subjects_dir, subject_id, 'brain') / 255; 76 | bounded_brain = vol.boundary.box(brain, apply=TRUE); 77 | volvis.lightbox(bounded_brain); 78 | ``` 79 | 80 |
81 | 82 | ![Volume Slices](brain4.png) 83 | 84 |
85 | 86 | ## Masks 87 | 88 | You can mask certain areas to isolate others. Use the code below and then compare to the image generated from the very first example. You'll notice that it's the same image but with the green area isolated. 89 | 90 | ```{r, eval=FALSE} 91 | 92 | surface = 'white'; 93 | hemi = 'both'; 94 | atlas = 'aparc'; 95 | region = 'bankssts'; 96 | 97 | # Create a mask from a region of an annotation: 98 | lh_annot = subject.annot(subjects_dir, subject_id, 'lh', atlas); 99 | rh_annot = subject.annot(subjects_dir, subject_id, 'rh', atlas); 100 | lh_label = label.from.annotdata(lh_annot, region); 101 | rh_label = label.from.annotdata(rh_annot, region); 102 | lh_mask = mask.from.labeldata.for.hemi(lh_label, length(lh_annot$vertices)); 103 | rh_mask = mask.from.labeldata.for.hemi(rh_label, length(rh_annot$vertices)); 104 | 105 | # visualize it 106 | vis.mask.on.subject(subjects_dir, subject_id, lh_mask, rh_mask); 107 | ``` 108 | 109 |
110 | 111 | ![Masks with Annotations](brain3.JPG) 112 | 113 |
114 | 115 | ## Surface Options 116 | 117 | For any visualization, you can add and change the "surface" parameter to change the texture of the brain. The past examples use "white" as default, but you can also use "pial" or "inflated". The code below generates three different images of the same brain, with the three different surfaces. 118 | 119 | ```{r, eval=FALSE} 120 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si')) 121 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='pial') 122 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='inflated') 123 | ``` 124 | 125 | 126 | -------------------------------------------------------------------------------- /chapters/codeExamples/brainsInR/brains_in_R_kaitlin.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
58 | 59 | 60 | 61 | 62 |
63 | 64 | 65 | 66 |

fsbrain examples

67 |

Kaitlin Gaerlan

68 |

01/10/2020

69 | 70 |
71 | 72 | 73 |
74 |

Installing fsbrain

75 |

The fsbrain package exists on CRAN To install the package on rstudio, use the following code:

76 |
install.packages("fsbrain");
77 |

You might get a warning message that prompts you to install Rtools, but this package seems to work without it so you can just continue.

78 |
79 |
80 |

Annotated Brain

81 |

Use the following code to load the fsbrain library and download the data needed for the visualizations:

82 |
library("fsbrain");
 83 | fsbrain::download_optional_data();
 84 | subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
 85 | subjects_list = c("subject1", "subject2");
 86 | subject_id = 'subject1';
87 |

You can now use this code to generate a visualization of the brain that divides it into different sections:

88 |
vis.subject.annot(subjects_dir, 'subject1', 'aparc', 'both', views=c('si'));
89 |

A window should open with a brain like the one pictured below, but you should be able to grab it with your mouse and move it around.

90 |
91 |
92 | 93 |

Annotation Style

94 |
95 |
96 |
97 |
98 |

Adding a colourbar

99 |

Using the same data from the first example, you can use this code to create an image that includes a colourbar. This graph is showing the range of thickness in the brain, but you can change the measure to something else like volume. You can also rotate this image once it’s generated.

100 |
rgloptions=list("windowRect"=c(50, 50, 1000, 1000));     # larger plot
101 | surface = 'white';
102 | measure = 'thickness';
103 | vis.subject.morph.native(subjects_dir, subject_id, measure, 'both', views=c('si'), rgloptions=rgloptions, draw_colorbar = TRUE);
104 |
105 |
106 | 107 |

Colourbar Example

108 |
109 |
110 |
111 |
112 |

Lightbox Slices

113 |

If you install and load the “magick” package, you can look at brain volume, which is visualized by brain slices using the code below.

114 |
install.packages("magick")
115 | library("magick")
116 | brain = subject.volume(subjects_dir, subject_id, 'brain') / 255;
117 | bounded_brain = vol.boundary.box(brain, apply=TRUE);
118 | volvis.lightbox(bounded_brain);
119 |
120 |
121 | 122 |

Volume Slices

123 |
124 |
125 |
126 |
127 |

Masks

128 |

You can mask certain areas to isolate others. Use the code below and then compare to the image generated from the very first example. You’ll notice that it’s the same image but with the green area isolated.

129 |
surface = 'white';
130 | hemi = 'both';
131 | atlas = 'aparc';
132 | region = 'bankssts';
133 | 
134 | # Create a mask from a region of an annotation:
135 | lh_annot = subject.annot(subjects_dir, subject_id, 'lh', atlas);
136 | rh_annot = subject.annot(subjects_dir, subject_id, 'rh', atlas);
137 | lh_label = label.from.annotdata(lh_annot, region);
138 | rh_label = label.from.annotdata(rh_annot, region);
139 | lh_mask = mask.from.labeldata.for.hemi(lh_label, length(lh_annot$vertices));
140 | rh_mask = mask.from.labeldata.for.hemi(rh_label, length(rh_annot$vertices));
141 | 
142 | # visualize it
143 | vis.mask.on.subject(subjects_dir, subject_id, lh_mask, rh_mask);
144 |
145 |
146 | 147 |

Masks with Annotations

148 |
149 |
150 |
151 |
152 |

Surface Options

153 |

For any visualization, you can add and change the “surface” parameter to change the texture of the brain. The past examples use “white” as default, but you can also use “pial” or “inflated”. The code below generates three different images of the same brain, with the three different surfaces.

154 |
vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'))
155 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='pial')
156 | vis.subject.morph.native(subjects_dir, subject_id, 'thickness', hemi='both', views=c('si'), surface='inflated')
157 |
158 | 159 | 160 | 161 | 162 |
163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /chapters/codeExamples/brainsInR/readme.org: -------------------------------------------------------------------------------- 1 | * Read-me 2 | 3 | A student in the Fall 2020 offering did a Rmd file on using the Brains in R toolbox. The Rmd file and exported HTML are saved here as an example. 4 | 5 | -------------------------------------------------------------------------------- /chapters/codeExamples/emacsInit/init.el: -------------------------------------------------------------------------------- 1 | (require 'package) 2 | (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) 3 | (package-initialize) 4 | 5 | (global-visual-line-mode) 6 | 7 | ;; 1. makes sure the file ~/.emacs does not exist. (look out for that "dot" at the front) 8 | 9 | ;; 2. make sure that the directory ~/.emacs.d/ DOES exist; create it if necessary 10 | ;; and watch all those dots. 11 | 12 | ;; 3. After that put this file in ~/.emacs.d/ 13 | 14 | ;; 4. Restart emacs and make sure you see NO ERROR MESSAGES or warning. 15 | 16 | ;; 5. Then look at "readme" in this directory for further instructions. 17 | 18 | ;; (use-package magit 19 | ;; :ensure t 20 | ;; :bind ("C-c m" . magit-status) 21 | ;; ) 22 | -------------------------------------------------------------------------------- /chapters/codeExamples/emacsInit/readme.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+Title: Readme for Emacs Init 3 | 4 | * Purpose 5 | To provide a minimal emacs init example. 6 | 7 | * Emacs initialization 8 | This is the process emacs follows when it starts. All computers and all programs have something similar. Emacs reads a file to see what to do when it starts. It has coded into it where to look for those files and what they are called. Most contemporary advice is to use =~/.emacs.d/init.el= as the initialization file. For that to work you may have to get rid of =~/.emacs= first. 9 | 10 | * The init file 11 | A [[file:init.el][minimal version]] of an emacs init file is found in this same directory. 12 | 13 | 14 | * Testing (requires an internet connection) 15 | 1. Copy the init file as instructed in the commented points numbered 1 to 5 in the init file. 16 | 2. *If* you get no errors then delete those commented lines and save the file. Close emacs. Restart. 17 | 3. *If* you still have no errors run, 18 | =M-x package-list-packages= 19 | 20 | This should refresh the list of packages. Now you can search for (=C-s=) "use-package". When you find it mark it with an "i" for installation, and then an "x" for execute. You should see stuff happening that is the installation. 21 | 4. If that worked without errors open up your init file and uncomment (delete the two semi-colons) the lines for the magit package. Save. Now when you close and restart emacs it should install the magit package. You should see no errors. 22 | ** Orgmode and Org Babel 23 | If you have the above working then you will want to be able to have the right functions set up for using orgmode that the course requires. That will involve some additional elisp code to be cut and pasted into your init.el file. Here is the code you need (the stuff between the begin and end lines): 24 | 25 | #+begin_src elisp :eval never 26 | (setq org-confirm-babel-evaluate nil) 27 | (setq org-babel-python-command "python3") 28 | (org-babel-do-load-languages 29 | 'org-babel-load-languages 30 | '((emacs-lisp . t) 31 | (R . t) 32 | (python . t))) 33 | #+end_src 34 | 35 | You may need to save, and restart emacs for this to take effect. 36 | ** Using Emacs and Org for Running R and Python 37 | In addition to what you do in emacs you need to have installed R and python to your computer first. Then, if you want some nice syntax highlighting for python install the =elpy= package. And to be able to run =R= inside emacs install the ess package. Below are the two "use-package" snippets you will need to add to your init.el file to get them downloaded and installed the next time you start emacs[fn:1]. 38 | 39 | #+begin_src elisp :eval never 40 | (use-package elpy 41 | :ensure t 42 | :init (elpy-enable)) 43 | 44 | (use-package ess 45 | :ensure t 46 | ) 47 | #+end_src 48 | 49 | * Footnotes 50 | 51 | [fn:1] There are ways to trigger this installation without restarting emacs all the time, but that is a safe way to start and helps you see when you have made an error. Then when you start emacs it will warn you if there is a syntax error in your start-up (init) script. 52 | -------------------------------------------------------------------------------- /chapters/codeExamples/pandas/getDataPandasExample.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import zipfile 3 | import pandas as pd 4 | 5 | def pandas_function(): 6 | url = "http://openpsychometrics.org/_rawdata/HSQ.zip" 7 | download_data(url) 8 | pandas_data = pd.read_csv("./HSQ/data.csv") 9 | print_columns(pandas_data) 10 | print("The length of one of the rows is: " 11 | + str(len(pandas_data['Q1'])) + "\n") 12 | print_mean(pandas_data.copy(), 'Q15', 'age') 13 | 14 | def download_data(url): 15 | request = requests.get(url) 16 | filename = url.split("/")[-1] 17 | with open(filename, 'wb') as output_file: 18 | output_file.write(request.content) 19 | 20 | with zipfile.ZipFile('./HSQ.zip', 'r') as zip_ref: 21 | zip_ref.extractall('.') 22 | 23 | def print_columns(data): 24 | print("The names of the columns are:\n") 25 | for column in data.columns: 26 | print(column) 27 | print("\n") 28 | 29 | def print_mean(data, column, sort_by): 30 | ages = [20,21,22,23,24,25] 31 | data_within_ages = data[data[sort_by].isin(ages)] 32 | 33 | print("The mean of Q15 for participants ages 20-25 is: " 34 | + str(data_within_ages[column].mean())) 35 | 36 | if __name__ == "__main__": 37 | pandas_function() 38 | -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/baseplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/baseplot1.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/baseplot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/baseplot2.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/baseplot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/baseplot3.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/ggplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/ggplot1.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/plotExampleJuly2022/mypyplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/plotExampleJuly2022/mypyplot.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/plotExampleJuly2022/myrplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/plotExampleJuly2022/myrplot.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/plotExampleJuly2022/readme.org: -------------------------------------------------------------------------------- 1 | A simple org file for testing plotting in python and R that worked in July 2022 on xubuntu. 2 | -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/plotExampleJuly2022/test.org: -------------------------------------------------------------------------------- 1 | #+Title: New test file for plotting 2 | 3 | * Python 4 | 5 | 6 | #+begin_src python :session *tst* :results silent :exports code 7 | import random as r 8 | import matplotlib 9 | from matplotlib import pyplot as plt 10 | #+end_src 11 | 12 | #+begin_src python :session *tst* :results file replace :exports both 13 | x = [r.random() for _ in range(10)] 14 | y = [r.random() for _ in range(10)] 15 | plt.plot(x,y,'bo') 16 | plt.savefig('./mypyplot.png') 17 | './mypyplot.png' 18 | #+end_src 19 | 20 | #+RESULTS: 21 | [[file:./mypyplot.png]] 22 | 23 | * R 24 | 25 | 26 | #+begin_src R :session *rtst* 27 | x = rnorm(10) 28 | y = rnorm(10) 29 | x 30 | #+end_src 31 | 32 | #+RESULTS: 33 | | -1.02260337386554 | 34 | | -0.970579796288701 | 35 | | 0.590838748829838 | 36 | | -1.24564293974992 | 37 | | 0.57971124057528 | 38 | | 0.0368641706338224 | 39 | | 1.09273067999275 | 40 | | 1.16276136392997 | 41 | | 0.720597366358001 | 42 | | 0.170190446483275 | 43 | 44 | #+begin_src R :session *rtst* :results output graphics file :file ./myrplot.png :exports both 45 | plot(x,y) 46 | #+end_src 47 | 48 | #+RESULTS: 49 | [[file:./myrplot.png]] 50 | -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/py-inter-fit-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/py-inter-fit-plt.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/py-inter-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/py-inter-plt.png -------------------------------------------------------------------------------- /chapters/codeExamples/plottingExample/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/plottingExample/simplePlot.png -------------------------------------------------------------------------------- /chapters/codeExamples/presents/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/presents/test.png -------------------------------------------------------------------------------- /chapters/codeExamples/presents/testBeamer.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:2 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testBeamer 7 | #+date: <2019-12-03 Tue> 8 | #+author: Britt Anderson 9 | #+email: britt@uwaterloo.ca 10 | #+language: en 11 | #+select_tags: export 12 | #+exclude_tags: noexport 13 | #+creator: Emacs 26.3 (Org mode 9.2.6) 14 | #+latex_class: article 15 | #+latex_class_options: 16 | #+latex_header: 17 | #+latex_header_extra: 18 | #+description: 19 | #+keywords: 20 | #+subtitle: 21 | #+latex_compiler: pdflatex 22 | #+date: \today 23 | #+startup: beamer 24 | #+Latex_Class: beamer 25 | #+Latex_Class_Options: [bigger] 26 | #+Beamer_Frame_Level: 2 27 | 28 | * This is the title of my slide show 29 | 30 | ** This is a slide 31 | Here is some important text. 32 | 33 | ** Another side with some math 34 | $\Sigma_{i=1}^n i$ 35 | 36 | 37 | ** Let's look at some code 38 | 39 | What is the correlation between height and weight in women? We can use the built in dataset =women= in R. 40 | 41 | #+Begin_src R :exports both :results output 42 | print(with(women,cor(height,weight))) 43 | #+End_src 44 | 45 | #+RESULTS: 46 | : [1] 0.9954948 47 | 48 | ** Including a plot 49 | 50 | #+Begin_src R :exports both :results value graphics :file test.png :height 200 :width 300 51 | print(with(women,plot(height,weight))) 52 | #+End_src 53 | 54 | #+Caption: Scatterplot of Women's Heights and Weights 55 | #+RESULTS: 56 | [[file:test.png]] 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /chapters/codeExamples/reportGen/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/reportGen/simplePlot.png -------------------------------------------------------------------------------- /chapters/codeExamples/reportGen/test.bib: -------------------------------------------------------------------------------- 1 | @book{anderson2014computational, 2 | title={Computational neuroscience and cognitive modelling: a student's introduction to methods and procedures}, 3 | author={Anderson, Britt}, 4 | year={2014}, 5 | publisher={Sage} 6 | } 7 | 8 | @article{turpin2019bullshit, 9 | title={Bullshit Makes the Art Grow Profounder}, 10 | author={Turpin, Martin Harry and Kara-Yakoubian, Mane and Walker, Alexander and Gabert, Nina N and Fugelsang, Jonathan and Stolz, Jennifer A}, 11 | journal={Available at SSRN 3410674}, 12 | year={2019} 13 | } 14 | 15 | -------------------------------------------------------------------------------- /chapters/codeExamples/reportGen/testLatex.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testLatex 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | This is a test of latex compiliation. 24 | 25 | If you type ~C-c C-e l p~ you should create a pdf version of this document. Test that it works by changing the title and author above and seeing the new names in your output. 26 | 27 | -------------------------------------------------------------------------------- /chapters/codeExamples/reportGen/testRBabel.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testRBabel 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | This is to test your installation of the files and programs needed to make a simple report. To compile to pdf use ~C-c C-e l p~. 24 | 25 | This loads an R library 26 | #+Begin_src R :session *testR* 27 | library(random) 28 | #+End_src 29 | 30 | #+RESULTS: 31 | | random | 32 | | stats | 33 | | graphics | 34 | | grDevices | 35 | | utils | 36 | | datasets | 37 | | methods | 38 | | base | 39 | 40 | 41 | Now we will see if we can some source code and a simple plot for our export. 42 | 43 | #+begin_src R :session *testR* :exports both 44 | x = 1:10 45 | y = rnorm(10) 46 | print(mean(y)) 47 | #+end_src 48 | 49 | #+RESULTS: 50 | : 0.149571258953334 51 | 52 | #+begin_src R :session *testR* :exports both :results graphics :file "simplePlot.png" 53 | plot(x,y,type = 'b') 54 | #+end_src 55 | 56 | #+RESULTS: 57 | [[file:simplePlot.png]] 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /chapters/codeExamples/reportGen/testRBabelBib.org: -------------------------------------------------------------------------------- 1 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 2 | #+options: author:t broken-links:nil c:nil creator:nil 3 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 4 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 5 | #+options: timestamp:t title:t toc:t todo:t |:t 6 | #+title: testRBabel 7 | #+author: Britt Anderson 8 | #+email: britt@uwaterloo.ca 9 | #+language: en 10 | #+select_tags: export 11 | #+exclude_tags: noexport 12 | #+creator: Emacs 26.3 (Org mode 9.2.6) 13 | #+latex_class: article 14 | #+latex_class_options: 15 | #+latex_header: \bibliographystyle{plain} 16 | #+latex_header_extra: 17 | #+description: 18 | #+keywords: 19 | #+subtitle: 20 | #+latex_compiler: pdflatex 21 | #+date: \today 22 | 23 | 24 | 25 | 26 | This is to test your installation of the files and programs needed to make a simple report. To compile to pdf use ~C-c C-e l p~. 27 | 28 | This loads an R library 29 | #+Begin_src R :session *testR* 30 | library(random) 31 | #+End_src 32 | 33 | 34 | Now we will see if we can some source code and a simple plot for our export. 35 | 36 | #+begin_src R :session *testR* :exports both 37 | x = 1:10 38 | y = rnorm(10) 39 | print(mean(y)) 40 | #+end_src 41 | 42 | #+RESULTS: 43 | : 0.18479671870621 44 | 45 | #+begin_src R :session *testR* :exports both :results graphics :file "simplePlot.png" 46 | plot(x,y,type = 'b') 47 | #+end_src 48 | 49 | ** Testing Citations 50 | 51 | This stackexchange [[https://tex.stackexchange.com/questions/114864/how-to-get-bibtex-to-work-with-org-mode-latex-export][question]] may be useful if you have trouble getting things to work. 52 | 53 | And the ta in the class wrote this article \cite{turpin2019bullshit} 54 | 55 | 56 | I wrote a book about using computers in psychology \cite{anderson2014computational}. 57 | 58 | 59 | 60 | 61 | #+latex: \bibliography{test} 62 | 63 | -------------------------------------------------------------------------------- /chapters/codeExamples/simpOrgDemoFile.org: -------------------------------------------------------------------------------- 1 | #+Title: This is a title 2 | 3 | * This is a heading 4 | * This is a subheading 5 | 6 | 1. this is a list item 7 | 2. this should be second 8 | 3. this is another list item 9 | 10 | ** Let's make a link 11 | 12 | [[https://uwaterloo.ca][University of Waterloo]] 13 | 14 | ** Let's try R 15 | 16 | #+Begin_src R :exports both 17 | a <- 2 18 | b <- 2 19 | print(a+b) 20 | #+end_src 21 | 22 | #+RESULTS: 23 | : 4 24 | 25 | 26 | -------------------------------------------------------------------------------- /chapters/codeExamples/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/codeExamples/simplePlot.png -------------------------------------------------------------------------------- /chapters/codeExamples/term/simpleTermEx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "This is an echo, echo, echo ... " 4 | name=`whoami` 5 | echo "My name is ${name}" 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /chapters/contents.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Contents 2 | 3 | - [[file:index.org][Introduction]] 4 | - [[file:beginning-r.org][Beginning R]] 5 | - [[file:version-control.org][Version Control]] 6 | - [[file:emacs.org][Emacs]] 7 | - [[file:linux.org][Linux]] 8 | - [[file:beginning-python.org][Beginning Python]] 9 | - [[file:working-with-data-in-python.org][Working With Data in Python]] 10 | - [[file:basic-plotting.org][Basic Plotting with R and Python]] 11 | - [[file:report-writing.org][Writing Reproducible Research Reports]] 12 | - [[file:terminal.org][Terminal]] 13 | - [[file:programming-psychology-experiments.org][Programming Psychology Experiments]] 14 | - [[file:rstudio.org][RStudio]] 15 | - codeExamples 16 | - [[file:codeExamples/simpOrgDemoFile.org][This is a title]] 17 | - plottingExample 18 | - [[file:codeExamples/plottingExample/plottingRandPy.org][Plotting in R and Python]] 19 | - plotExampleJuly2022 20 | - [[file:codeExamples/plottingExample/plotExampleJuly2022/test.org][New test file for plotting]] 21 | - presents 22 | - [[file:codeExamples/presents/testBeamer.org][testBeamer]] 23 | - reportGen 24 | - [[file:codeExamples/reportGen/testRBabel.org][testRBabel]] 25 | - [[file:codeExamples/reportGen/testRBabelBib.org][testRBabel]] 26 | - [[file:codeExamples/reportGen/testLatex.org][testLatex]] -------------------------------------------------------------------------------- /chapters/example-os.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/example-os.png -------------------------------------------------------------------------------- /chapters/ggplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/ggplot1.png -------------------------------------------------------------------------------- /chapters/i2c4p.bib: -------------------------------------------------------------------------------- 1 | @article{anderson08_effec_tempor_contex_tempor_expec, 2 | author = {Anderson, Britt and Sheinberg, David L.}, 3 | title = {Effects of Temporal Context and Temporal Expectancy 4 | on Neural Activity in Inferior Temporal Cortex}, 5 | journal = {Neuropsychologia}, 6 | volume = 46, 7 | pages = {947 - 957}, 8 | year = 2008, 9 | keywords = {britt,articlepub}, 10 | } 11 | 12 | -------------------------------------------------------------------------------- /chapters/index.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+options: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline 3 | #+options: author:t broken-links:nil c:nil creator:nil 4 | #+options: d:(not "LOGBOOK") date:t e:t email:nil f:t inline:t num:t 5 | #+options: p:nil pri:nil prop:nil stat:t tags:t tasks:t tex:t 6 | #+options: timestamp:t title:t toc:t todo:t |:t 7 | #+title: Introduction 8 | #+date: <2023-01-13 Fri> 9 | #+author: Britt Anderson 10 | #+email: britt@uwaterloo.ca 11 | #+language: en 12 | #+select_tags: export 13 | #+exclude_tags: noexport 14 | #+creator: Emacs 28.2 (Org mode 9.6-pre) 15 | #+bibliography: /home/britt/gitRepos/Intro2Computing4Psychology/chapters/i2c4p.bib 16 | #+cite_export: csl assets/chicago-note-bibliography-16th-edition.csl 17 | 18 | 19 | * Welcome 20 | 21 | These are the course notes for Psych363 at the University of Waterloo: An Introduction to Computing for Psychology students. This current update is for the Spring 2023 term. 22 | 23 | This is the /index/ file for finding your way through the course topics and activities. The later chapters often assume information from the earlier ones. I recommend you follow the topics in the order below. Work through each chapter in sequence and make sure you understand the basics before moving on. This will remove much confusion. Our term is twelve weeks long and there are twelve chapters. This means you will need to work through, on average, one chapter a week. I recommend you try to get the first two or three done in less time so as to allow more time for the more complex material that comes towards the end of the course. 24 | 25 | The videos that you will find embedded in this document can also be found on the course channel on [[https://vimeo.com/channels/i2c4p][vimeo]]. The videos and the written material are meant to work together and you will usually need to both read and watch to learn what you need know in order to complete the assessments. I recommend skimming the entire text before watching any of the videos. Then go back and start working through the text. You can then watch the video and fast forward or skip sections that you understand. My experience is that students who start with the videos, or only watch the videos, take longer and learn less. For most of you the worst approach is start with the assignments and then just try to skim around searching for solutions. The assessments are meant to help you learn. They are less about getting a score. I want you to be able to use these tools after the course is over. Approach the assessments as another tool for you to assess how well you have mastered the material. 26 | 27 | ** Goals 28 | The goal for the course is to expose you to an array of tools and techniques useful for research in psychology. Some of these tools are ancillary, e.g. managing a reference data base. Some of them are practical, such as programming a behavioral experiment. All of them will involve learning things about how to use your computer effectively. These fundamentals should serve you well even as the world of computing and computational tools evolve. It is the cliché of teaching one to fish. If you practice what is described here you will learn the ur-skills needed to master new tools and new techniques in the years to come. 29 | 30 | Our more practical goals are suggested by the chapter headings below. You will get an introduction to programming and using programming languages to do the things academics need to do: Analyze data; Visualize Data; Collect Data; and Report Data. 31 | 32 | As the framework for accomplishing these tasks I will be requiring you to use the Linux operating system. Mostly this is so you come to a deeper understanding of what software is and how to make your computer work for you. I do not want you to master how to use a particular program on a particular operating system, but to acquire the meta knowledge that will enable you to learn how to use any piece of software on any computing platform that your future career requires. But we do have to start somewhere and the installation process and terminology around Linux can be a big first step. Thus, our first lesson uses [[https://posit.co/][RStudio]]. This allows me to introduce some of the ideas and concepts for programming while not letting us get stuck waiting for you to install a new operating system. 33 | 34 | *Important Note* Computing changes quickly. Every time I teach this course some section of the notes, often large sections of the notes, go out of date. Most of the videos were made for the first pandemic offering in Winter 2020. If something seems wrong or doesn't work anymore then let me know so I can update things. You can do this most easily by using the [[https://github.com/brittAnderson/Intro2Computing4Psychology][github repository]] for this course. Ideally, you would fix the mistake with a pull request (see the chapter on [[file:version-control.org::*Terms][version control]]). But at a minimum you can report it as an [[https://github.com/brittAnderson/Intro2Computing4Psychology/issues][issue]]. This also allows you to see if someone else has already reported the same mistake and a fix has been shared. 35 | 36 | * Chapter RStudio 37 | [[file:rstudio.org][RStudio]] 38 | 39 | * Chapter Version Control 40 | [[file:version-control.org][Version Control]] 41 | 42 | * Linux 43 | [[file:linux.org][Linux]] 44 | 45 | * Terminal 46 | [[file:terminal.org][Terminal]] 47 | 48 | * Emacs 49 | [[file:emacs.org][Emacs]] 50 | 51 | * Beginning Python 52 | [[file:beginning-python.org][Beginning Python]] 53 | 54 | * Beginning R 55 | [[file:beginning-r.org][Beginnning R]] 56 | 57 | * Working With Data in Python 58 | [[file:working-with-data-in-python.org][Working with data in Python]] 59 | 60 | * Basic Plotting 61 | [[file:basic-plotting.org][Basic Plotting]] 62 | 63 | * Report Writing 64 | [[file:report-writing.org][Report Writing]] 65 | 66 | * Programming Psychology Experiments 67 | [[file:programming-psychology-experiments.org][Programming Psychology Experiments]] 68 | 69 | * Final Projects 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /chapters/myrplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/myrplot.png -------------------------------------------------------------------------------- /chapters/py-inter-fit-plt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/py-inter-fit-plt.png -------------------------------------------------------------------------------- /chapters/simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/chapters/simplePlot.png -------------------------------------------------------------------------------- /ggplot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/ggplot1.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | Introduction to Computing for Psychology Students (i2c4p) 10 | 11 | 12 | 196 | 197 | 198 |
199 |

Introduction to Computing for Psychology Students (i2c4p)

200 |

201 | Click here for the online course notes. 202 |

203 |
204 |
205 |

Date: 2023-02-14 Tue 00:00

206 |

Author: Britt Anderson

207 |

Created: 2023-02-14 Tue 09:20

208 |

Validate

209 |
210 | 211 | -------------------------------------------------------------------------------- /index.org: -------------------------------------------------------------------------------- 1 | #+Title: Introduction to Computing for Psychology Students (i2c4p) 2 | #+Author: Britt Anderson 3 | #+date: <2023-02-14 Tue> 4 | 5 | Click [[https://brittanderson.github.io/Intro2Computing4Psychology/book/index.html][here]] for the online course notes. 6 | -------------------------------------------------------------------------------- /myrplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/myrplot.png -------------------------------------------------------------------------------- /notes4nexttime.org: -------------------------------------------------------------------------------- 1 | #+Title: Notes for Next Time (S2023 edition) 2 | 3 | * Purpose 4 | Short, stream-of-conscious notes for things I may try to do, or re-do before the next offering. 5 | 6 | * Things to consider changing 7 | 1. How we depend on Linux. 8 | I still feel that getting familiarity with a second operatings system and its tools is useful, but this is weighed against the challenge of supporting such a diverse range of student capbabilities and different hardward. The VM machine is easy to get started, but hard to maintain. I had students creating 12gb virtual hard drives, and certain software (such as the Psychopy library) does not always install smoothly in this environment. 9 | 1. Things to try: Can I get all the windows users using WSL2 for Linux? 10 | 2. Can all the Mac users get the tools they need through their native terminal and homebrew? 11 | 2. Redo some of the videos. 12 | As interfaces change or even how arguments are listed the small changes can have a big effect on student comprehension. The demo videos seem quite successful. I should probably remake them (eventually all of them) to take account of the minor, but still confusing to new comers, changse that occur from version to version. 13 | 3. Replace hangman with something more structured to introduce writing both .R and .py files? 14 | Some students still don't get the hang of writing functions they can import and reuse. I still see very long scripts. Maybe this can just be made more structured with specific steps, or I can just grow the data analyses to include these components and stretch them out over time. 15 | 4. Replace psychopy 16 | The original goal for psychopy was an easy to use tool for coding experiments. The psychopy people have focused so heavily on the builder that the coder interface is hard to access. Also, the javascript and other components now seem to be the priority. Alas, it seems that psychopy is basically becoming e-prime. I don't want students learning to use a /particular/ tools, but rather learning how to use tools generally. For this reason I think it may be better to use pygame directly. That should be good enough here. The practice components I build up to, instead of just a simple posner cuing, could use words and pictures and RT. Also, a better way to handle data and save to file could better equip students for after the course. 17 | 18 | Also noted that the '/' key doesn't work anymore unless you use the name 'slash'. 19 | 5. Emacs 29 with =citeproc= and =org-cite= 20 | Should be much easier for the citation components. Will this be part of the -buntu offerings? If not, show how to install from source? 21 | 6. Good set of youtube [[https://systemcrafters.net/guides/][videos]] on Emacs 22 | 7. Students noticed a mismatch between learn and github: 23 | #+begin_quote 24 | > On GitHub, it states that we need at least one plot, and that the introduction and discussion must have at least one citation 25 | > each. On LEARN, you’ve asked that we have two plots and at least five citations. Which guidelines should we follow? 26 | #+end_quote 27 | 8. Look at seaborn package to make for easier nicer plotting in python? 28 | 9. Citing figures (or at least acknowledge sources) 29 | 10. Reference/cite your use of computational and statistical software. Not just the statistical method but which version of R/Psychopy and any other packages. 30 | 11. Discuss possibly a package for Rmd to mix python with R code? [[https://rstudio.github.io/reticulate/articles/r_markdown.html][Reticulate]] [[https://github.com/posit-dev/positron][Positron]]. A new ide from the rstudio people for mixing R with Python and looks like VSCode. 31 | 12. Another VM option for newer macs? Yet to try: [[https://eclecticlight.co/virtualisation-on-apple-silicon/][Viable]]. 32 | 13. Former student had an interesting idea of pairing students from more technical backgrounds with more junior students. Maybe that might help get over code paralysis. Could do it as a mini-group project with hangman? 33 | 14. A citation to justify why they have to document their analytical choices: https://www.nature.com/articles/d41586-023-03177-1 34 | 15. An [[https://github.com/james-stoup/emacs-org-mode-tutorial#org56377d5][org mode]] guide that might be useful? 35 | 16. Use a pandoc workflow for the report writing? 36 | 17. There is a nice update to citation handling that I should adapt. It is well described in this [[https://amerygration.com/Blog/citation_handling_in_emacs.html][recent blog post]]. A six part series on the same topic starts [[https://www.miskatonic.org/2024/01/08/org-citations-basic/][here]]. 37 | 38 | * Other links to include? 39 | 1. An [[https://neuro4ml.github.io/][online course]] I have not had a chance to look at yet. Might be good for 420. 40 | -------------------------------------------------------------------------------- /readme.org: -------------------------------------------------------------------------------- 1 | #+Title: Introduction to Computing for Psychology Students 2 | #+Author: Britt Anderson 3 | 4 | * Overview 5 | This repository houses material I use in teaching at the University of Waterloo (Canada). The purpose is to introduce psychology undergraduates with limited quantitative and computing backgrounds to using their computers as research tools The topics covered include: 6 | 7 | 1. version control, 8 | 2. operating system and software installation, 9 | 3. using the terminal/command line, 10 | 4. coding (Python and R), 11 | 1. General purpose computing 12 | 2. Data analysis 13 | 3. Statistics 14 | 4. Data Visualizations 15 | 5. and the writing tools necessary for conducting 16 | 1. a simple data collection (Psychopy), 17 | 2. analysis, and 18 | 3. generation of a reproducible report. 19 | 20 | 21 | 22 | * Org Book 23 | In December 2022 I began work on collating the material into a sort of "book" using the ~org-publish~ functionality of emacs org-mode. The =org-book= branch tracks that effort. It also incorporates changes in the lessons that have been prompted by new features in the citation features of org-mode and many changes in the methods for installing linux on Windows and Mac laptops. 24 | 25 | I have recorded a [[https://vimeo.com/448900968][brief video introduction]] to the course. Many of those lessons are out of date and the ordering is hard to divine (it is basically alphabetical), but I hope to provide an easier path to follow in this revision. 26 | 27 | * Invitation 28 | 29 | While the material was developed for students at the University of Waterloo, I hope that some of the material may be useful to others. Feel free to provide feedback, or suggest material for inclusion. 30 | 31 | * Organization of the Repository 32 | 33 | What follows is left from the =s22= branch. It will be updated as the revision proceeds. 34 | 35 | - In the ~startHere~ directory there is an [[file:startHere/outline.org][outline]] with a path through the material. Other paths are certainly possible, and you are encouraged to just pick and chose what is relevant for you. If you find that you pick a topic and it requires something you skipped you can always backtrack and pick it up later. 36 | 37 | The teaching material is divided into subdirectories based on the nature of the content. Your main focus should be the ~topics~ folder. The ~assessments~ directory contains versions of assessments I give the students to provide them a concrete opportunity to use the skills and in order to document their progress and to give feedback. You are welcome to use the assessments to develop your own skills, but don't expect feedback or submit them to me. ~codeExamples~ contains examples submitted by past students, or written by me, to show how certain lessons might be tackled, or as educational illustrations. Many of the exercises are accompanied by videos or screencasts walking through various tasks. Those videos are hosted on [[https://vimeo.com][Vimeo]] in the *i2c4p* [[https://vimeo.com/channels/i2c4p][channel]]. Their titles will guide you to the accompanying activity. 38 | 39 | The best way to use this repository is by forking or cloning your own version. Work locally in your clone. There are internal links between files that don't work properly if you just try and open the directories here and click on the links. The rendered version of one of the ~.org~ files may look like a web page, but it isn't. Also, any exports to html that I include will open as raw files on /Github/ not as nicely rendered web pages, which they will often on your local computer[fn:1]. Links and file type associations should work better if you work within a local clone of the repository than if you work by clicking on files in github or download files one at a time. Having your own version of all the files locally also makes it easier for you to copy and amend the material to suit your own needs. 40 | 41 | * Feel Free to Comment or Contribute 42 | If something is unclear go ahead and open an issue. If you find small changes like typos or broken links that you know how to fix please feel free to make a pull request, or if that is too inconvenient you can also point me to the needed fixes as an issue. 43 | 44 | This material is taught in many ways and many places. Most of it is not original to me. I am just curating topics and ideas that I have learned from others or providing links to others' material that has helped me. Even when I make a video or a written file to explain something I am probably telling you something I learned elsewhere. 45 | 46 | If you have ideas about approaches you think may work better for this material or want to talk about pedagogical strategies please feel free to [[mailto: britt@uwaterloo.ca][email me]]. I am happy to entertain ideas for additional segments and topics, but all such suggestions or major restructuring of content will have to wait until this first version is completed and has been trialed by my Fall 2020 course at the [[https://uwaterloo.ca][University of Waterloo]]. 47 | 48 | * Footnotes 49 | 50 | [fn:1] There is a trick to simulate the look of a html file as a webpage. Prefix it with ~https://htmlpreview.github.io/?~. 51 | -------------------------------------------------------------------------------- /simplePlot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/brittAnderson/Intro2Computing4Psychology/120f5eb3277787903df30de6c2f23484fed0fda0/simplePlot.png -------------------------------------------------------------------------------- /topics/emacs.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+Title: Emacs Topic Introduction 3 | * Goal 4 | Introduce emacs and the rudiments of its use. We will build on these basics as we work through our additional exercises in coding and programming experiments and writing reports. 5 | * What is Emacs 6 | Emacs is the tool we will be leveraging to produce our reproducible research report, but it is much more. It is a highly extensible text editor that can make your life much easier through its auxilliary functions and capacities. 7 | * Emacs is a text editor 8 | Emacs began in some form in the early 1970s [fn:1]. It has been continually developed for 50 years and quite a bit of humor and myth has settled about it [fn:2]. Some people joke that it is an operating system masquerading as a text editor. Many people argue that it is overly complex and overly engineered, but it truly allows one to do a great deal within a single interface and a single environment, and I introduce it because I love it, but more importantly, because I think it is one of the easiest way to become functional with some of the key tools that allow you to generate a reproducible report [fn:3]. 9 | * Emacs Basics 10 | ** Modifier Keys 11 | Your modifier keys may depend on your keyboard and operating system. Don't like what they are? [[https://www.x.org/releases/current/doc/man/man1/xmodmap.1.xhtml][Remap them]]. You use these simultaneously with other keys to invoke commands without using your mouse or menus. For example, to open a file you ~C-x C-f~. This means that you hold down the control key and press 'x'. Then you let up on both keys, press control and then simultaneously 'f' and let up on both. You are then prompted in the /minibuffer/ with a menu for the name and location of the new file. You can navigate the mini-buffer with by using backspace to delete and tab to move forward. 12 | *** Ctrl 13 | This is usually the key. Found on lower left (and sometimes also on lower right) of most keyboards. 14 | *** Meta 15 | On windows and macs this is usually the key. Sometimes it is mapped to the super key, which has the windows logo or the curly square of macs. 16 | ** What Can You Do With Emacs 17 | 1. Write code 18 | 2. Execute code 19 | 3. Execute code within the confines of a document 20 | 4. Export the document as a webpage or pdf. 21 | 5. Read and annotate pdfs. 22 | 6. Manage your email. 23 | 7. Securely encrypt/decrypt and sign emails. 24 | 8. Edit the names of files in your directories. 25 | 9. Compress and decompress files. 26 | 10. Manage your bibliography. 27 | 11. Create citations. 28 | 12. Interface with the ~git~ version control system. 29 | 13. Talk remotely to servers. Copy and move files between computers as if the were merely separate directories on your own machine. 30 | 14. Manage a knowledge data base in plain text. 31 | 15. Keep your calendar, journal, agenda, and to-do list integrated. 32 | 16. Take notes in a rapid outline fashion. 33 | ** Emacs Takes a Long Time to Learn 34 | I learn new things in emacs everyday. Don't expect to do all those things at the beginning. You will just frustrate yourself. Pick some small things that you do regularly and try to learn how to do that in emacs. The rest will grow naturally as your comfort expands and you tackle new use cases. 35 | *** First Things First 36 | Learn the basics. Take the Emacs tutorial ~Ctrl-h t~ (aka =C-h t=). Consult the Psychotherapist when needed (under help menu). Play a game - try ~M-x tetris~ . 37 | ** Emacs is highly customizable 38 | Just like linux distributions have package managers so does emacs. Usually your emacs customizations will be found in a /hidden/ directory (starts with a dot ('.') in your home directory. For example, =/home/britt/.emacs.d/= 39 | *** Where is your "init" file 40 | Emacs tries to find an initialization file to see your customizations and what, if any, extra packages you may have installed. There are multiple places where it looks, and we want it to look in the right one. 41 | Do ~C-x d~. This will display your current directory. The first line shows you where you are. Move up or down as needed to get to your home directory. Look for a file called ~.emacs~. Navigate to it by ~C-n~ and ~C-p~ to move up and down. When you find it and the cursor is on it. Type a capital ~D~. Then confirm the delete. Then ~C-x d~ and tab to =~/.emacs.d/=. Type a plus sign ~+~. For the name of the new file type ~init.el.~ 42 | *** The init.el file and packages 43 | Emacs has it's own package system that allows you to greatly expand its functionality. You can learn more by reading the info file =C-h i=. If for some reason your info files are missing see this Stackoverflow question for hints on how to install [fn:4]. Many packages could be installed through the =apt= methods, but it is better not to mix and match package systems. Since there may well be packages you will eventually want that are not built by xubuntu you should probably use packages from the emacs system. There are two big package warehouses that are commonly used and go by the names "elpa" and "melpa". Here is how to get a basic package database available. 44 | #+begin_src elisp :eval never :exports code 45 | (require 'package) 46 | (add-to-list 'package-archives '("melpa" ."http://melpa.org/packages/") t) 47 | (package-initialize) 48 | #+end_src 49 | Now we can look for packages by running ~M-x package-list-packages~ 50 | *** Additional Tools for Package Management with Emacs 51 | The easiest way to get started with Emacs packages is to install packages via the ~package-list-packages~. In that pane that opens up you can search for a package (using ~C-s~) and then type an "i" to install it. 52 | 53 | As you become more comfortable with Emacs, if in fact you ever do, you might want to consider other ways to manage your package. I quite like [[https://suvratapte.com/configuring-emacs-from-scratch-use-package/][use-package]] as it allowed me to write down what packages and customizations I was using in a single place. Then I could use that file on a new computer to fairly easily get the same set-up. Here is an example of how one might use the =use-package= system: 54 | 55 | #+begin_src elisp :eval never :exports code 56 | (use-package elpy 57 | :ensure t 58 | :init (elpy-enable)) 59 | 60 | (use-package ess 61 | :ensure t 62 | ) 63 | #+end_src 64 | 65 | If you become even more expert you may want to manage and compile your emacs packages directly from source. For that you might want to manage packages with [[https://github.com/radian-software/straight.el][straight.el]]. This is definitely a more advanced package management system, and should wait until you feel comfortable using Emacs. 66 | 67 | Lastly, there are Emacs bundles where someone has decided to create a system that uses Emacs and contains already configured a selection of emacs packages that play well together. Many people find these a nice help when getting started. If you decide you want to keep trying emacs after this course, but find it hard to get started, then one of these two options ([[https://www.spacemacs.org/][spacemacs]] ; [[https://github.com/doomemacs/doomemacs][doomemacs]] )might be worth a look. If you are the kind of person who likes books for learning, check out Mastering Emacs. 68 | *** Program Your Editor 69 | Emacs can be programmed with elisp code, it's own [[https://en.wikipedia.org/wiki/Lisp_(programming_language)][lisp]]. You can actually change the functions of your editor while using it. Usually, you don't really need to know elisp. You just need to have the confidence to cut and paste to the right location, usually your init.el file. 70 | **** An example: Turn off the tool bar. 71 | - To search for functions you can use the help ~C-h-f~. This will allow you to search for functions. Try the keyword menu and tab and see if you come across a likely contender (~menu-bar-showhide-tool-bar-menu-customize-disable~). 72 | - Navigate to the scratch buffer. Put that function in parantheses. Move to the end. Type ~C-x C-e~. Did your tool bar go away? 73 | *** [[info:org#Top][Orgmode]] 74 | 1. What is it? About the best thing ever. 75 | 2. Make an outline. Keep a calendar. Add code to your documents. Make links. Include images. 76 | 3. Practice now: 77 | Where is the help, remember? ~C-h i~ 78 | 1. Learn to use the short cuts to open, save, and so on. That is one of the powers of the command line and similar style tools. Enhance your productivity and control. 79 | 2. Create an outline. 80 | 3. Create a link 81 | 4. Insert an image 82 | 5. Export as a web page. 83 | 6. What would you need to export a pdf? 84 | Try installing ~texlive-latex-base texlive-latex-extra~. If that doesn't work, repeat with ~texlive-latex-recommended~. If that doesn't fix the problem go with ~texlive-full~. This is big. Be patient. 85 | * Emacs Activity and Assessment 86 | [[file:../assessments/emacsBeginningAssessment.org][Beginning Emacs Assessment]] 87 | * Footnotes 88 | 89 | [fn:1] https://www.emacswiki.org/emacs/EmacsHistory 90 | [fn:2] https://xkcd.com/378/ 91 | [fn:3] https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.2006930 92 | [fn:4] https://emacs.stackexchange.com/questions/48211/emacs-manuals-are-missing-on-debian-ubuntu/48214#48214 To get this to work I enabled the non-free icon on the repositories, did ~sudo apt install emacs-common-non-dfsg~ for all the documentation, and then ran as the super user the command to update the info directories. 93 | 94 | -------------------------------------------------------------------------------- /topics/emacsPythonIdeInstructions.org: -------------------------------------------------------------------------------- 1 | * Preliminaries 2 | To use Emacs as an IDE, or to do many other things with Emacs, you need to be able to install packages. Most of these will come internal to emacs, but some of them will come from your distribution. 3 | 4 | 5 | * Creating your "init" file. 6 | 1. Open Emacs 7 | 2. Use ~C-x C-f~ to open a new file. You want it to be =~/.emacs.d/init.el=. Note the tilde means your home directory, and that ~.emacs.d~ will already exist. Everything matters with computers. Note that "dot" before the word .emacs.d. 8 | 3. You should make sure you have the following text in your init file. 9 | #+begin_quote 10 | (require 'package) 11 | (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) 12 | (package-initialize) 13 | #+end_quote 14 | Watch out for trailing slashes and plurals. Any typos and you should see an error. You have to fix those before you can go on. 15 | * Test your init 16 | Save the init.el file. Shut down emacs and restart. If you see no errors, great! If you do, fix. 17 | Now try the command ~M-x package-refresh~. Watch what appears in the little mini-buffer at the bottom. If you miss something you can look at the ~*Messages*~ buffer to see what you missed. If you see anything about failing to download melpa then you have a problem to fix. 18 | * Get the python virtual environment tools you need. 19 | Virtual environments are a way to let programming languages work on your computer in isolation. Mistakes you make there or packages you install there will not pollute other parts of your system. You need to run the following in a terminal. 20 | #+begin_quote 21 | sudo apt install python3-venv 22 | #+end_quote 23 | * Adding elpy and enabling. 24 | Restart Emacs 25 | 26 | Make sure you have refreshed your packages (~M-x [[help:package-refresh-contents][package-refresh-contents]]~). 27 | 28 | Run ~package-install RET elpy RET~ 29 | 30 | If it tells you it needs to install other components then let it. 31 | 32 | Open up your init.el file again and add this below the package initialize line 33 | 34 | ~(elpy enable)~ 35 | * Test Again that Emacs is Error Free 36 | Save your init file. Shutdown Emacs and restart. You should see no error messages. 37 | * Test with python 38 | Open a new file with a name such as ~test.py~ and type in a few basic commands. You should see nice color syntax highlighting and other features appear like magic. 39 | * Comments 40 | To get everything you might need to install additional packages such as ~pip~. You may also need to adjust your ~PATH~ by setting it in your ~.bashrc~ or other locations, but those can be lessons for another day. 41 | -------------------------------------------------------------------------------- /topics/githubIDBasics.org: -------------------------------------------------------------------------------- 1 | #+Title: Github ID and the Basics 2 | 3 | * Goal 4 | Create a github account and learn how to fork repositories. 5 | * Overview 6 | Our longer term goal is to become fluent in version control. To do that we will use the [[https://git-scm.com/][git tool]] for managing changes we make to files in a project. In order to share and collaborate on our projects locally and remotely we will use a popular social coding platform: [[https://github.com][Github]]. 7 | * Summary of Steps 8 | 1. Create a Github Account. ([[https://vimeo.com/450563119][introductory video]]) 9 | 2. Read the "Hello World" Github guide. ([[https://vimeo.com/450563176][next steps video]]) 10 | 3. Navigate to the course repository. 11 | 4. /Fork/ both the course repository and the practice repository for the course. 12 | 5. Generate a screen shot of your github home page after you have forked the course repositories ([[file:~/gitRepos/introComp4Psych/assessments/githubIDAssessment.org][github intro assessment]]). 13 | * Details 14 | ** A Github Account 15 | Science is collaborative and iterative. Computing projects, whether for industry or research, are usually too big for one person. Therefore, we benefit when there are tools to facilitate revision, reversion, recording, and sharing. [[https://github.com][Github]] is a large social coding platform with high visibility. While there are other similar platforms (e.g, [[https://bitbucket.org/product][Bitbucket,]] or [[https://gitlab.com/explore][Gitlab]]) Github is convenient for our educational goals. While you do *not* need a Github account to use ~git~, the version control software, ~git~ is used to manage your github projects. Therefore, you first need to create an account to use Github. 16 | *** Get your id 17 | This is a straightfoward process. Navigate to [[https://github.com][Github]] and complete the sign up process on the home page. You should use whatever email address is convenient, and you can chose whatever username is available, but think for a moment. If you are successful in this course at improving your computing skills the Github platform is something you may want to use professionally in the future; pick a username that won't embarass you later. 18 | ** Sign in to your user account 19 | You should see a blank page with a random geometric avatar and no activity or respositories. 20 | ** Look at the Github Guides 21 | The [[https://guides.github.com/][Github Guides]] will provide you with short introductions to the git terminology, the Github workflow, and how to create your first repository. 22 | ** Read the Hello World guide and create your first repository. 23 | The [[https://guides.github.com/activities/hello-world/][hello world]] guide will walk you through creating a repository. Even if you delete after creation go through these steps to learn what a repository is. 24 | ** Navigate to my Github respositories and Fork the Course Repository and Practice Repository 25 | My respositories are at: [[https://github.com/brittAnderson?tab=repositories][Britt's Repos]] 26 | *** What is a "Fork"? 27 | There is short github guide on the notion of a [[https://guides.github.com/activities/forking/][fork]]. 28 | ** Fork the main course repository 29 | When you fork the course repository you will enable /cloning/ (to be covered later) your own local version on your home computer or laptop. Your fork will also give you access to your own copies of all files that you can edit or add to without affecting my copies. Your fork (and subsequently your clone) will give you a way to add changes back to my copies (if I accept your /pull request/) and easily incorporate new changes that I make into your version. 30 | The main course repository is here: https://github.com/brittAnderson/Intro2Computing4Psychology 31 | Note that there is a ~readme~ file on the landing page. This is created from the ~readme.org~ file that you can see in the list of code files right above. Open this up by clicking on it and make a local change to your version of the readme.org file. Maybe add a line that says this is your fork; something minor; and then ~commit~ that change. You should see the readme region change to reflect your change (you may have to refresh your browser). You will at this point have progressed through some of the core features of version control, but to practice some more ... 32 | ** For the course practice respository 33 | You can find that here: https://github.com/brittAnderson/psych363practice 34 | ** Complete the github id assessment 35 | [[file:~/gitRepos/introComp4Psych/assessments/githubIDAssessment.org][Github ID Assessment]] 36 | -------------------------------------------------------------------------------- /topics/githubPullRequest.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+Title: Github PullReqest and Remotes 3 | 4 | * Goal ([[https://vimeo.com/channels/i2c4p/456349826][video walk through]]) 5 | To advance our knowledge of git and version control using the github social coding site as our laboratory. 6 | * Overview 7 | In an [[file:githubIDBasics.org][earlier topic]] we learned some of the basics of learning git and using it with github. Here we will learn what /push/, /pull/, and /remotes/ are all about. 8 | * Not all repositories are git repositories 9 | (video: [[https://vimeo.com/channels/i2c4p/456349738][part1]]) 10 | ** There are many other version control options and many other places to host them. 11 | *** Other version control system 12 | 1. [[https://www.mercurial-scm.org/][Mercurial]] 13 | 2. [[http://darcs.net/][Darcs]] 14 | 3. [[https://www.nongnu.org/cvs/][CVS]] 15 | 4. [[https://subversion.apache.org/][Subversion]] 16 | Each has their own fans. CVS and Subversion are more legacy options, but you will see them. Darcs is more of an experiment than a broadly used system. Mercurial seems to be the cool kid, but doesn't have as much market share as git, but any one of them might be a good choice for you in the future. Main point: version contol is not only ~git~. 17 | *** Other Repositories 18 | Github is a very popular place to host your publically accessible repository, but it is far from your only option. 19 | 1. [[https://osf.io/][OSF.io]] 20 | For scientists OSF.io seeks to make itself a way to host scientific projects and their data. 21 | Trivia question? Do I have any repositories on Osf.io? 22 | 2. [[https://sourceforge.net/][Sourceforge]] 23 | An oldie, but still used. 24 | 3. [[https://bitbucket.org/][Bitbucket]] 25 | 4. Gitlab 26 | The university provides you with a gitlab account: [[https://git.uwaterloo.ca]] 27 | Main point: github is *not* your only option 28 | 29 | * Git and Linux 30 | If you want to see one big advantage to using Linux try installing a program to let you easily manage git repositories on Windows. Then when you get frustrated try the following on your Xubuntu installation: 31 | 32 | #+begin_src sh :eval never 33 | sudo apt install git 34 | #+end_src 35 | 36 | * But first ... 37 | Git wants to know who you are and how to get in contact with you. The first time you want to use git from the terminal you will have to specify this with the following 38 | 39 | #+begin_src sh :eval never 40 | git config --global user.name "John Doe" 41 | git config --global user.email johndoe@example.com 42 | #+end_src 43 | Please don't actually use "John Doe". More on these configuration options can be found [[https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup][here]]. 44 | 45 | * Git in Pictures 46 | A few helpful illustrations to the distinction of clones, forks, pull, push, and pull request can be found [[https://www.toolsqa.com/git/difference-between-git-clone-and-git-fork/][here]]. 47 | 48 | * Terms 49 | - Fork :: A copy of one github repository to another *github* repository. 50 | - Clone :: A copy of one *git* repository to another *git* repository. 51 | The first repository might be hosted on github, but the second one, the /cloned/ one exists on a local machine. In your case this is probably your laptop. 52 | - Remote :: This is a repository that you are following. You will typically /pull/ from these, but your /push/ permissions may be limited depending on the distinctions between forks and clones, and whether you own the remote or someone else does. You can have more than one remote. 53 | - Pull :: the transfer of information and changes *from* one repository incorporated into another. This is how you get the new information from a remote transported to a local repository that you control. 54 | - Push :: this is the transfer of information *to* a repository you control (or have permissions to push to) from another repository that you control. This is often from your local laptop version to the hosted repository (your fork) on github. 55 | - Pull Request :: When you have information or changes that you think would be helpful to a remote you do *not* have push permissions for then you can request that the owner of that repository pull in your changes. This is a formal process called a pull request. It is primarily a github concept and not a git concept. 56 | - Branch :: within a repository the development of the code may be proceeding in a few different directions at the same time. The principal production branch is conventionally called *master*. And the principal repository that is the main, shared one is called *origin*. We will not be working with branches in our course, but those terms do show up in commands. 57 | 58 | All of these "[[https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository][basics]]" are covered in detail in the book Pro Git (available on line). 59 | 60 | * Using *Git* in Linux 61 | Try to note when I use the word "git" and when I use the word "github". They are different things. 62 | 63 | ** Making your first repository (aka "repo") on your laptop. 64 | 1. Open a terminal 65 | 2. Move (~cd~ or ~dir~) into your Desktop 66 | 3. type =git init myrepo= 67 | 4. You should see message from the terminal prompt that it has been created. 68 | 5. Feel free to delete (e.g. =rm -rf ./myrepo=) 69 | ** Cloning a Course Repo 70 | (video: [[https://vimeo.com/channels/i2c4p/456349595][what is a repository and a remote?]]) 71 | You should already have forked the two course repositories. If not, go back and [[file:../assessments/githubIDAssessment.org][do that]]. 72 | Then, on your laptop (Xubuntu): 73 | 1. Move to a directory where you want to keep things organized. I use =~/gitRepos/=. To make that directory you could do ~mkdir ~/gitRepos/~ and then ~cd~ to it. Verify you are there with ~pwd~. All this is happening /in the terminal./ 74 | 2. Open a web browser and find *your fork* of Psych363. On that page there should be a button to clone it that will allow you to copy the command. It may be hidden. Look for a blue "code" button. Hitting that may open the dialogue that shows you the clone command. 75 | 3. Go back to your terminal and paste it (usually =Ctrl-Shift v=). Hit . 76 | 4. You should see some activity that things are being copied. 77 | 5. =ls= to see you have a new directory in your =gitRepos= directory. 78 | 6. =cd= into this new directory and look around. Compare it to what you see when you look at your fork on github. 79 | For the assessment we will create more remotes and work on generating a pull request. 80 | (video: [[https://vimeo.com/channels/i2c4p/456349516][working through the pull request assessment]]) 81 | *** Magit 82 | 1. Emacs provides you with an interface for this called magit. 83 | 2. If you watched the [[https://vimeo.com/455628993#t=942s][emacs beginning video]] you will have seen the commands you need to add to your =init.el= file to get the =magit= package. If not, you can always take a look now. 84 | 3. You will probably have to quit and then restart Emacs for the magit package to be visible. 85 | 4. Then you launch it by navigating (in Emacs) to the directory of your repository and typing: ~C-c m~ or ~M-x magit~ usually. 86 | * Extra 87 | Xournal and Screenkeys - how do you get them and why is git/github relevant? ([[https://vimeo.com/channels/i2c4p/456349697][video]]) 88 | -------------------------------------------------------------------------------- /topics/installingR.org: -------------------------------------------------------------------------------- 1 | * Installing R 2 | ** Really Simple or Just Simple 3 | Installing R on Ubuntu is a straightforward ~sudo apt install r-base~. However, this Ubuntu package often trails the development of R by several months. That almost never matters for general use. However, if you are using a very new method, or one where the packages are being updated frequently you may want to track the repository maintained by the r-project. Adding a repository is another "apt" command, and not too difficult. I am using the Ubuntu package here. 4 | 5 | More installation details can be found here: [[https://computingforgeeks.com/how-to-install-r-and-rstudio-on-ubuntu-debian-mint/][Link]]. 6 | 7 | This [[https://linuxize.com/post/how-to-install-r-on-ubuntu-20-04/][blog]] shows you how to add the CRAN (r-project) repository first. 8 | ** Another thing you may want 9 | Many document conversions, those used by RStudio and many other applications, make use of a wonderful swiss-army knife piece of software: [[https://pandoc.org/][pandoc]]. This is the PAN DOCument conversion tool. The latest version can be found on their [[https://github.com/jgm/pandoc/releases/tag/2.10.1][github page.]] "Deb" files are easy to install (in fact the =dpkg= tool is running under the hood of most of the =apt= installations we have been using). After downloading the deb file, and making sure you know where it is you would =cd= to that directory and run =sudo dpkg -i =. Where "i" stands for install. 10 | * Installing RStudio 11 | Should you install RStudio? It is a wonderful piece of software, but its graphical interface can shield you from knowing what the underlying tools are. This can impede your growth as an R user, and limit what you know to possible, and your ability to implement the cutting-edge or idiosyncratic analysis method. My advice is to learn the base R first, and then expand to RStudio if you find it convenient. But know that it is not necessary to use RStudio to use R. RStudio is a nice wrapper around software that is free for your use, and may be more convenient and flexible when used directly. 12 | 13 | Opinions do differ on this though. Here are couple of links to further discussion and opinions on RStudio and the tidyverse versus base R. 14 | [[https://github.com/matloff/TidyverseSkeptic][Should you?]] 15 | [[https://news.ycombinator.com/item?id=20362626][More debate.]] 16 | * Simple demonstration of Rmd- > HTML Without RStudio 17 | There are many inputs for "knitting". The one I prefer is Rnw which goes via LaTeX to pdf. It gives you exquisite control over the appearance of your final product. It may however be overkill for simple projects. 18 | In the [[https://vimeo.com/460262566][linked video]] near the end I show at the end how to generate an html output from an Rmd file without using RStudio just to show you how it is possible. 19 | -------------------------------------------------------------------------------- /topics/intro2TheTerminal.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | #+Title: Introduction to the Terminal 3 | 4 | * Find the terminal 5 | (video: [[https://vimeo.com/channels/i2c4p/453837330][Introduction]]) 6 | Different operating systems refer to the terminal differently. In Windows the =CMD.exe= [fn:1] command is an approximation to a terminal as is the =Power Shell= [fn:2]. 7 | 8 | For OSX you navigate to you applications, find the folder "Utilities" and look in their for the terminal application. 9 | 10 | For Xubuntu click the icon in the upper left of the screen and type terminal in the search bar. 11 | 12 | ** Terminology 13 | While they do not mean exactly the same thing, you will often find the following terms being used relatively interchangeably. 14 | - terminal 15 | - shell 16 | - command line 17 | What they have in common is the idea of a text based interface to communicating with the operating system. What this means is that instead of opening a gui (gui: *G* raphical *U* ser *I* nterface) to navigate your file tree you do this with a text based system of commands. 18 | 19 | ** An example - your directory tree 20 | 21 | #+begin_src sh :eval :never :export code 22 | ls 23 | #+end_src 24 | 25 | Typing this command in your terminal will list the files and directory. 26 | 27 | #+begin_src sh :eval :never :export code 28 | ls -la 29 | #+end_src 30 | 31 | Typing this command will get you a *l* ong version of the same list, /plus/ all the hidden files that can be hard to see from a conventional file manager display. 32 | 33 | ** An Historical Aside 34 | In the early days of computing people wrote their programs on [[https://en.wikipedia.org/wiki/Computer_programming_in_the_punched_card_era][punch cards]]. Some see the inspiration as the [[https://en.wikipedia.org/wiki/Jacquard_machine][Jacquard machine.]] There are still programmers alive who can tell you their horror stories of tripping and falling and scattering their punch cards everywhere. Want to know if your program worked? Take it to the main frame data center, drop it off, and come back the next day to get your print out. 35 | [[https://en.wikipedia.org/wiki/Computer_terminal][Terminals]] came along as an alternative to communicating with big central processors. There was a screen and keyboard. By typing you could send input to the computer that returned the output to your screen. 36 | The terminals we have today are not true terminals, but emulators. Though few people refer to them as such. We emulate this old way of communicating to the processor because it works and is efficient. 37 | 38 | * Why use a terminal? 39 | 40 | You can get more done. You can get it done more quickly. Once you learn to do one hard thing you never have to figure out how to do it again, because you can [[https://www.theatlantic.com/technology/archive/2018/10/agents-of-automation/568795/][easily script it]]. That is why you want to learn to use the terminal 41 | 42 | Terminals are ubiquitous. They are low in their resource usage. They permit remote logins without the need for sending graphics back and forth. In fact, the remote computer need not have a system installed for displaying windows or even a physical screen attached (called headless). 43 | 44 | Knowing how to use a terminal will allow you to use =ssh= to connect to remote hosts. It will allow you to quickly and efficiently navigate your system, and it will make it easy for you to do things that used to take ages. 45 | 46 | 47 | ** A scripting example 48 | Want to convert and compress a large directory of videos as I did for this course. No need to open up each in an application and click a bunch of mouse clicks. Just write a =bash= script to invoke a command line program to do all the work for you. Go get a cup of coffee and come back when the [[https://xkcd.com/1319/][job is done]]. 49 | 50 | #+begin_src sh :eval never :exports code 51 | for i in *.MP4; 52 | do name=`echo "$i" | cut -d'.' -f1`; 53 | echo "$name"; 54 | ffmpeg -i "$i" -c:v libx264 -b:v 1.5M -c:a aac -b:a 128k "${name}S.mp4"; 55 | done 56 | #+end_src 57 | 58 | Almost all of this I copied off the Internet where it appeared as an answer to a question from someone else wanting to do essentially the same thing I did. It took me a while to tweak it to my particular use case, but when that was done my problem was solved, /forever./ Every new batch of videos I just put in their own directory and run this script from the command line. Note that this script uses a *for loop*, one of the constructs introduced in the first [[file:rStudioWinMacFirstSteps.org::*Loops][RStudio lesson]]. 59 | 60 | What learning the terminal does is allow you to leverage the knowledge of more people. Thus you get to think about the interesting part of your problems. 61 | 62 | * Resources 63 | There are a great many resources on how to use the terminal effectively, but don't go out and read them all. One of the skills to learn in learning to use the computer is to develop your own set of links and resources you can go to when need arises. Don't try to learn everything at once. You will get overwhelmed and discouraged. Instead you learn what you need when the need arises. And if you need to know something more than once, then you spend the time to dive deeper. There are a great many things about using the terminal that I do not know, but I know the ones I use often, and I know where to find more when I need to know more. You should do the same. Here are a few online resources to get you started. 64 | 65 | 1. [[https://ryanstutorials.net/linuxtutorial/commandline.php][The command line]] 66 | 2. [[https://ubuntu.com/tutorials/command-line-for-beginners#1-overview][A Short Series of Terminal Lessons from the UbuntuWiki]] 67 | 3. [[https://null-byte.wonderhowto.com/how-to/hack-like-pro-scripting-for-aspiring-hacker-part-1-bash-basics-0149422/][Some Scripting Basics]] 68 | Most of what you want to do at the command line, at least in the beginning, you can do with typing directly into the terminal. But at some point you will want to write a file, a script, that has all the commands typed into it. They you can run that script from the terminal. This blog post has some basic background for how to get started. 69 | Note the use of the term "BASH". This stands for the Bourne Again Shell. Your terminal can use different shells. So while you can use the terms interchangeably most of the time, they don't mean exactly the same thing. The default shell in use by the terminals in Xubuntu is BASH. Another shell favored by many advanced programmers is [[https://ohmyz.sh/][zsh]]. You [[https://wiki.ubuntu.com/ChangingShells][can change the shell]] for your terminal if you like. 70 | 4. [[https://hpc-carpentry.github.io/hpc-shell/05-scripts/index.html][Another Scripting Introduction]] 71 | 5. [[https://medium.com/tech-tajawal/writing-shell-scripts-the-beginners-guide-4778e2c4f609][A More Detailed Treatment of Shell Scripting]] 72 | 73 | * Terminal Games 74 | (video: [[https://vimeo.com/channels/i2c4p/453837142][Terminal Games]]) 75 | In order to give you some structure for your self-directed learning, I have organized a few activities you might try and a few questions you might ask yourself. 76 | 1. ~ls -la /home/~ 77 | - What does all this output mean? 78 | - What changes when you leave out the ~-la~? 79 | - What does the hyphen do? 80 | 2. Can you find the location of your desktop folder in your terminal? 81 | 3. Can you change to that directory? 82 | ~cd~ 83 | 4. Find out where you are? 84 | ~pwd~ 85 | 5. Can you find out who the computer thinks you are, your user name? 86 | ~whoami~ 87 | 6. Find out how much free space you have on your computer disk. 88 | ~df -h~ 89 | 7. How do you get help for most of these commands? 90 | Usually ~command --help~ or (~-h~) 91 | 8. How do you find the manual? 92 | ~man ls~ 93 | 9. Navigating 94 | 1. Paths: absolute and relative. 95 | 2. What do those "dots" mean? 96 | 3. What do those slashes mean? 97 | 4. Tab is your friend. 98 | 5. Try the up arrow too. 99 | 10. File ownership 100 | 1. Make a text file from the command line. 101 | ~touch /home/yourname/Documents/testText.txt~ 102 | 2. Who owns it? 103 | 11. Make a directory 104 | ~mkdir /home/britt/Documents/myFirstDir/~ 105 | Spaces are the enemy. Never use them, but if you have to, escape (~\~) them. 106 | 12. Want more practice? Try some of the [[*Resources][resources]] above. 107 | 108 | * Assessment 109 | (video: [[https://vimeo.com/channels/i2c4p/453837048][assessment]]) 110 | [[file:../assessments/terminal.org][terminal.org]] 111 | 112 | * Footnotes 113 | [fn:1] [[https://www.howtogeek.com/235101/10-ways-to-open-the-command-prompt-in-windows-10/][CMD]] 114 | 115 | [fn:2] [[https://docs.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell?view=powershell-6][Power Shell]] 116 | 117 | -------------------------------------------------------------------------------- /topics/pythonData.org: -------------------------------------------------------------------------------- 1 | # -*- org-link-file-path-type: relative; -*- 2 | * Data Handling in Python 3 | For a long time data handling and graph production in python lagged behind that of R. Data were collected in comma or tab separated ([[https://en.wikipedia.org/wiki/Comma-separated_values][CSV]]) formats or often in [[https://docs.python.org/3/library/pickle.html][pickle]] files. Pickled data was converted to a binary representation and had to be converted back to be read. These issues made it harder to use python in an interactive and interpreted environment for data analyis and many workers in psychology would collect their data with experiments coded in python (or other languages), and then use R as the language for statistical testing. 4 | 5 | However, over the last few years the scientific python community has expanded its options for both graphing and data handling markedly, and working entirely in python is increasingly a viable option. The most widely used python library for handling data is [[https://pandas.pydata.org/][Pandas]]. In many respects it has a similar look and feel to the =data.frame= style of data analysis used in R. However, there are definite syntactic and implementation differences. While a familiarity with R and data.frames is a good base for beginning to use Pandas there will remain a lot of concrete specfics to learn to use python effectively. In this topic a few of the pandas basics are demonstrated. In addition to the illustrations here, there are numerous online tutorials and blogs that explain pandas in more detail, and with many more examples. 6 | ** Some additional sources 7 | *** Pandas Books 8 | - [[https://www.chapters.indigo.ca/en-ca/books/python-for-data-analysis-data/9781449319793-item.html][Python for Data Analysis]] - This book is available for online reading to University of Waterloo students. 9 | *** Blogs 10 | - [[https://pandas.pydata.org/pandas-docs/stable/getting_started/tutorials.html][Community Tutorials]] 11 | - [[https://www.learnpython.org/en/Pandas_Basics][Learn Python]] 12 | ** Data handling in Python 13 | *** Pandas 14 | How to get Pandas? 15 | 1. [[https://docs.continuum.io/anaconda/][Anaconda]] (Conda) - you will see this in a lot of documentation. This is a collection of packages for python that are curated to work well together and allow you to set up virutal environments (which protects your projects and their differing requirements from leading to conflicts with each other). Using =conda= is not hard, but it is another took, and it has its own learning curve, so it will not be used here. If you find yourself using python regularly and you are comfortable with how to install and use software and packages then I encourage you to read more Anaconda and decided if it is a python solution that will work for you. 16 | 2. Xubuntu stable ~sudo apt-get install python3-pandas~. 17 | 3. Pip (PyPI) ~pip3 install pandas~ 18 | 19 | To try and get all our python packages from one source (and thereby reduce our chance for conflicts) we will use the =pip= method as that will work well with our subsequent installation of the =psychopy= package. 20 | *** Interactve Pandas 21 | Python is an interpreted language. You can use Python from an interpreter much as you used R in an R console (or RStudio). 22 | **** Getting Your Data Into Python 23 | Before you can get data into python, you have to get data. 24 | 25 | There are a large number of sources for data online that you can use to explore different tools and analyses. 26 | 1. [[https://openpsychometrics.org/_rawdata/][Open Psychometrics]] 27 | 2. [[https://www.apa.org/research/responsible/data-links][Data Links from the APA]] 28 | 3. [[https://data.world/datasets/psychology][Data World]] 29 | 4. [[https://www.kaggle.com/tags/psychology][The Kaggle Competition]] 30 | Kaggle competitions allow you to make data analysis a competitive sport. 31 | 32 | For demonstration purposes we will get data from the Open Psychometrics project (I am using the humor questi. You could just go to the website and right click and download, but you could also use python to get the data. There are many methods for this and the one used here came from this [[https://www.simplifiedpython.net/python-download-file/][online post.]] 33 | 34 | You will have to ~pip3 install requests~ to get the requests library 35 | 36 | Then you will want to be in the directory where you want the file to download. I am using a ~:session:~ in order to allow variables to persist across babel code blocks. 37 | 38 | 39 | #+begin_src python :session: *Psych363* 40 | import requests 41 | url = "http://openpsychometrics.org/_rawdata/HSQ.zip" 42 | r = requests.get(url) 43 | filename = url.split('/')[-1] # -1 gets us the last item of a list, in this case the filenamel 44 | with open(filename,'wb') as output_file: 45 | output_file.write(r.content) 46 | #+end_src 47 | 48 | This file is a "zip" file. For a zip file the data have been compressed to save space. There are many other compression types available. Tar is fairly common. Rar is rare. Python also has facilities to unzip files. Why bother using all these tools rather than doing everything manually? Well, for one thing you could script it. Why waste your time clicking random buttons. Let the computer do the work. 49 | 50 | #+begin_src python :session: *Psych363* 51 | import zipfile 52 | with zipfile.ZipFile('./HSQ.zip', 'r') as zip_ref: 53 | zip_ref.extractall('.') ; # what does "." mean in this context? 54 | #+end_src 55 | 56 | #+begin_src python 57 | You have to import pandas to use it. 58 | #+begin_src python :session *Psych363* :results value 59 | import pandas as pd 60 | dpd = pd.read_csv("./HSQ/data.csv") 61 | dpd.columns.values 62 | #+end_src 63 | 64 | **** Repeating Things We Did In R With Pandas 65 | ***** The length of a list 66 | In R you would use the ~length~ command, but in python it is ~len~. Almost every language you will program in will have a command for finding the length, but the actual word may different or the syntax may be different. 67 | 68 | #+begin_src python :session *P363* 69 | len(dpd['Q1']) 70 | #+end_src 71 | 72 | ***** Using A Conditional 73 | In R we did things like ~mydataframe$mydatacol~ to get a column of data from a data frame. In python the format looks more like a python dictionary. 74 | 75 | #+begin_src python :session *P363* 76 | dpdmg = dpd.copy() 77 | dpdmg = dpdmg[dpdmg['gender'].isin([1,2])] 78 | len(dpdmg['Q1']) 79 | #+end_src 80 | 81 | What happens if you just select with ~in~? You keep the same number of rows, because you replace the ineligible data with NaNs (not a number). 82 | 83 | **** Functional Styles versus Object Orientation 84 | Python is an object oriented language. R is in a more eclectic style that reflects its LISP origins. Object oriented languages have data structures: objects, that encapsulate both attributes (what objects are like) and methods (what objects can do). A list would have its contents, the items in the list, as its attributes, but would have the ability, a method, to report the length of its /self/ [fn:1]. The attributes and methods of a python object are often accessed by a name that includes a *dot* '~.~' like the ".isin" you see in the code snippet above. Pandas creates a /data.frame object/ (the name emphasizes its R heritage), but it is not the same thing, and while most of the commands are achievable in either, they are not the same. The *dot* shows you we are accessing either an attribute or a method of an object. 85 | 86 | * Assessing Your Use of Pandas 87 | [[file:../assessments/dataPandasAssessment.org][Data Pandas Assessment]] 88 | * Footnotes 89 | [fn:1] Self is in italics because this is the special name one often sees in object oriented code were the definition of an object is given. Self typically refers to the particular instance of an object as it is being made. 90 | -------------------------------------------------------------------------------- /topics/rStudioWinMacFirstSteps.org: -------------------------------------------------------------------------------- 1 | #+Title: First Steps in Programming and Markdown: RStudio 2 | 3 | * Goal 4 | Our eventual goal is to do all the above in Linux. But in order to make some progress with our programming practice while we puzzle our way through the [[file:installUbuntu.org][Linux installation instructions]] we will begin by using a tool easily accessible in Windows and on Macs for using the programming language R, common for statistical analyses, and RStudio a programming environment that uses R and facilitates our first steps in learning to integrate code with text for integrated report generation. 5 | * Summary of Steps 6 | We will: 7 | 1. Download R ([[https://vimeo.com/450719112][downloadR video]]) 8 | 2. Download RStudio ([[https://vimeo.com/450719047][downloadRStudio video]]) 9 | 3. Verify they are working ([[https://vimeo.com/450719009][RStudio Walk-through video]]) 10 | 4. Generate a simple Rmd file to see some of the basic components of the markdown syntax ([[https://vimeo.com/450718879][simpleRmdDemo video]]) 11 | 5. Add some simple computing constructs including a 12 | - variable 13 | - for loop 14 | - function 15 | 6. Produce an Rmd file from the above 16 | 7. And export it to an html file that we can open in a web browser and that displays correctly. 17 | * Detailed Steps 18 | ** Download R 19 | R is free statistical software. As it is a very popular language of academic statisticians many new and cutting edge statistical techniques are available for R users that are well vetted. If you are using linux you can usually find instructions for downloading and installing that are specific to your linux distribution and its package manager. The comprehensive R network ([[https://cran.r-project.org/][CRAN]]) also maintains download links and instructions and this is the right place to go for [[https://cran.r-project.org/bin/windows/][Windows]] and [[https://cran.r-project.org/bin/macosx/][Mac]] downloads. 20 | 21 | The CRAN webpage also has links to [[https://cran.r-project.org/manuals.html][manuals]] that are useful for learning more about the language and its functions. While there is great material elsewhere, and you can find it by internet searches, it is still advisable to start at CRAN first. You know that information is curated by the body that funds, develops, and supports the language. 22 | ** Download RStudio 23 | RStudio is not R. It is a development environment wrapped around R. You can absolutely use R without RStudio (that is the way I use it and what I recommend). RStudio provides a lot of help to get a beginner started, and I used it as a beginner too, but it also reflects the opinions of the RStudio developers about their preferred way of using the language and the packages they think are best, but which may not be exactly what you want or how you want to use the tool. So, while I recommend RStudio to get going you should also try other ways to use R, and other styles of using R before you decide on your preferred approach. The people who make RStudio have a free desktop version that will provide all the functionality that we will need. They also make commercial tools that build on the basic RStudio functionality. 24 | [[https://rstudio.com/products/rstudio/download/#download][Here]] is where you can get RStudio. Choose the right version for your operating system and follow the instructions. 25 | ** Verify they are working. 26 | Just click the icon and try to open the software. If it starts it works. 27 | ** Generate and Rmd file; Try some simple programming; export a webpage 28 | RStudio supports several different ways of interacting with R. We will use the Rmd file, which stands for R Mark Down; R because we are using the R language for our programming, and markdown because we are using the R markdown syntax (there are other varieties of markdown with slight differences in syntax and functions) for telling RStudio how to format our export file when it runs the code and reads our program. We will use this below to make the file we open in our browser. 29 | 30 | A [[https://vimeo.com/450718879][video]] shows an example. If you practice without watching the video pay attention to the difference between the /editor/ window and the /console/. The console evaluates the code and prints out the answer. You can use it to test whether your R code does what you think. The editor is where you mix the code with text. It lies static until you tell it to run a line, a block, or the entire document. It will then ouput the result (if there were no errors that you have to fix) in a viewer that in internal to RStudio. You want to be able to save that output somewhere (or know where RStudio saves it). Then you can open that file in your browser to see the full power of being able to write a simple text file and get produced a fully featured web page. 31 | *** Variable 32 | A *variable* is something that holds a value. A value doesn't have to be a number. It could be name, character, or a list of pupil diameters, of even some larger data structure. As the name implies in R, as in most, but not all, programming languages a variable may vary. You could use a variable to "count" how many times you have done an operation and it would increment the value on each pass through the loop. 33 | 34 | #+Name: A Variable Demonstration 35 | #+begin_src R :exports both 36 | a = 3 37 | a = a + 1 38 | print(a) 39 | #+end_src 40 | 41 | #+RESULTS: 42 | : 4 43 | *** Loops 44 | Often we use programs to automate things that need to be done over and over again. In many statistical and experimental procedures this need for repetition is common. Consider running all the trials of an experiment of finding the mean reaction time for a large number of experimental participants. When you have a task to do that needs to run until some condition is met you will often use a ~while~ loop. When you need to do something for a set number of time or through a list of items then you will typically use a ~for~ loop. A ~for~ loop iterates through a structure and executes the same code, the code in the /body/ of the loop each time through. 45 | 46 | #+begin_src R :exports both :results output 47 | for (i in seq(1,10)) { 48 | print(i) 49 | } 50 | #+end_src 51 | 52 | #+RESULTS: 53 | #+begin_example 54 | [1] 1 55 | [1] 2 56 | [1] 3 57 | [1] 4 58 | [1] 5 59 | [1] 6 60 | [1] 7 61 | [1] 8 62 | [1] 9 63 | [1] 10 64 | #+end_example 65 | *** Functions 66 | Functions in programming languages are black boxes for taking input and returning output. You, the author of the function, fill in the details of the black box, but we users only know what we feed in and what we get back. Each programming language has its own way of telling the processor what is and what is not a function. In R we use the keyword ~function~ and assign that to a name that we can use for our convenience when we want to invoke that function. 67 | 68 | For example, let's say we want to know if a number is even. We can use R's built in function to tell us the remainder of a division. This function is an /infix/ function as we put it INside its arguments. It uses the symbols ~%%~. For example ~ 5 %% 2~ equals 1 because if you divide 5 by 2 you have 1 left over. 69 | 70 | To know if a number is odd or even we only need to know if the remainder when divided by two is or is not zero. To do this we can use a *predicate*. It is a conventional way of saying it is a test that comes back true or false depending on whether a condition is met. Putting this altogether we can write a function that evaluates if a number is odd. 71 | 72 | #+begin_src R :exports code :results silent :session *isodd* 73 | isOdd <- function(n) { 74 | return(n %% 2 != 0) 75 | } 76 | #+end_src 77 | 78 | And then we can use our function in a test: 79 | 80 | #+begin_src R :exports both :results output :session *isodd* 81 | print(isOdd(5)) 82 | #+end_src 83 | 84 | #+RESULTS: 85 | : [1] TRUE 86 | 87 | We could then use this output value to test whether to print the number by using an "if" statement. Note that some of the syntax I am using in this file to get R to work is special to orgmode and not RStudio. You will see a demo of the same idea with RStudio in the videos for this topic. 88 | -------------------------------------------------------------------------------- /topics/readme.org: -------------------------------------------------------------------------------- 1 | I have not ported over <2023-02-06 Mon> all the text from these files to the chapters/book version. Need to come back and verify one at a time that this is done then delete each one as complete. 2 | --------------------------------------------------------------------------------