---
title: "350 Homework for week1"
output:
  html_document: default
  pdf_document: default
date: "March 26, 2024"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(width=100)
```

If not already, R is well on its way to becoming the lingua franca of statistical analysis. It is open source, free, and extraordinarily powerful. Most importantly, more and more \emph{packages} are being contributed to core \R{}. As of today there are at least 21,365 packages that add to the functionality of R. More packages are added daily. R is a data analysis system that is both open source and is also extensible. Open source means that the actual computer code behind all operations is available to anyone to examine and to reuse, within the constraints of the GPL 2.0. It is free software in the meaning of free speech in that everyone can use it, everyone can examine the code, everyone can distribute it, and everyone can add to it. Psychologists around the world are learning to take advantage of R for their research and this course will allow you to do so as well.

These notes and homework assignments are part of a course Psychology 350: Special Topics: An introduction to R for psychological research at Northwestern University.

The syllabus for this course is available at <http://personality-project.org/courses/350.syllabus.pdf>. Lecture notes and readings are available there.

# Homework for week 1

Although R can be used from several different interfaces, a recommended one is to use RStudio. Thus, the homework for the first week will be to download R and RStudio and practice using Markdown and some very baby steps in R.

## Instructions for downloading R and RStudio

### First, download R

R is hosted on mirror servers around the world. One of the most convenient ones is probably the one hosted by Rstudio in (on) the cloud:

<https://cloud.r-project.org>

(note that the RStudio web site is now called Posit.)

Select your operating system, and then go to the download page.

Select the most recent release (currently R-4.3.3) and click to install. Thats it!

### Then, download RStudio (desktop)

Go to Rstudio.com <https://www.rstudio.com/products/rstudio/download/> and select your installer (e.g. Rstudio Version 2023.12.1+402 )

# Now open Rstudio and start using it

### RStudio and RMarkdown

RStudio is not R, but rather an interface to 'R' but it is a convenient way to write up notes (and eventually run your R code). The first example actually does run a small R function and shows the output.

Choose new file from the file menu

Select R markdown as your file

### The default R Markdown script

When you ask for a new file, of type Markdown, it will look like this:

<https://personality-project.org/courses/350/first.Rmd>

Which can rendered into an HTML or PDF document by choosing the `Knit" option.

<https://personality-project.org/courses/350/first.html>.

This is all very nice, but we actually want to do something useful.  So we modify that script.

We can take the default script and modify it, or completely erase it and start with a brand new window where we paste what we want.

A new window will open which will look like this <https://personality-project.org/courses/350/350.homework-1.Rmd> which produces output which looks like this: <https://personality-project.org/courses/350/350.homework-1.html>

(It is possible that you need to copy this file from the server and paste into R Markdown. I am still playing with this and we will work through this in class. )

Select the Knit button and you have just run your first R code, as well as making your first R markdown example.





## Lets make it more powerful: Install the psych package

You can do this from R studio by selecting the Install Packages and then entering psych to be installed. Install psychTools as well.

This should be version 2.4.3



### Or you can install it using the install.packages command

## Now, change your markdown script file to do something interesting

We want to

make psych active (using library)

make psychTools active (using library)

run a simple function (describe)

Show some nice output (pairs.panels)

# Here is the code to do that

```{r}
library(psych)
library(psychTools)
sessionInfo()  #to see what packages are active
describe(iris)  # a built in data set from Fisher
pairs.panels(iris) #a graphic display
```

### Here is the revised markdown script:

<https://personality-project.org/courses/350/example2.Rmd> which produces output like this: <https://personality-project.org/courses/350/example2.html>
