---
title: "Creating Scales "
author: "William Revelle"
date: "5/25/2018"
output: html_document
---

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

#Filtering Items
```{r}
library(psych)
```
```{r}

fn <- "/Users/wr/Downloads/sapa.peers.Rda"
 read.file(fn)
 ls()   # to see what we downloaded
 

```

#Homework:  I combined Mariani and Jack's keys
```{r}
Mariani_keys <- list(
  agreeableness = cs(q_150, q_217, q_253, q_1385, q_1410, q_1419, q_4264, -q_141, -q_146, -q_239),
  anxiety = cs(q_66, q_867, q_986, q_1495, q_1989, q_4249, -q_89, -q_248, -q_1616, -q_1835),
  conscientiousness = cs(q_519, q_619, q_930, q_1190, q_1290, q_1507, q_1979, q_4272, -q_602, -q_1254, -q_1401),
  extraversion = cs(q_745, q_1742, q_1768, q_1904, q_3110, q_4230, q_4295, -q_241, -q_565, -q_684),
  neuroticism = cs(q_101, q_105, q_108, q_208, q_793, q_960, -q_177, -q_179, -q_1350, -q_1571),
  openness = cs(q_148, q_194, q_294, q_755, q_1058, q_1334, q_1542, q_4222, -q_689, -q_1540),
agre = cs( q_1869, q_1585, q_319, q_217, q_145, q_121, q_39, -q_142, -q_141, -q_139),
 anxi = cs( q_986, q_995, q_1505, q_1989, q_4249, q_4252, -q_85, -q_248, -q_1596, -q_1616),
 cons=  cs( q_76, q_124, q_530, q_554, q_559, q_1507, -q_636, -q_1173, -q_1511, -q_1553),
 extr = cs( q_819, q_1803, q_1899, q_4230, q_4267, -q_312, -q_1531, -q_1575, -q_4247, -q_4259),
 open= cs( q_6, q_77, q_94, q_148, q_3153, -q_82, -q_239, -q_566, -q_689, -q_1540),
 neur = cs( q_53, q_126, q_808, q_867, q_960, q_4258, -q_89, -q_168, -q_727, -q_804)
 )
```
#Mariani_keys
```{r}
Jacks_Keys <- list(
 agre = cs( q_1869, q_1585, q_319, q_217, q_145, q_121, q_39, -q_142, -q_141, -q_139,),
 anxi = cs( q_986, q_995, q_1505, q_1989, q_4249, q_4252, -q_85, -q_248, -q_1596, -q_1616),
 cons=  cs( q_76, q_124, q_530, q_554, q_559, q_1507, -q_636, -q_1173, -q_1511, -q_1553),
 extr = cs( q_819, q_1803, q_1899, q_4230, q_4267, -q_312, -q_1531, -q_1575, -q_4247, -q_4259),
 open= cs( q_6, q_77, q_94, q_148, q_3153, -q_82, -q_239, -q_566, -q_689, -q_1540),
 neur = cs( q_53, q_126, q_808, q_867, q_960, q_4258, -q_89, -q_168, -q_727, -q_804)
 )
```

```{r}
 Emilie_keys <- list(
  agreeableness = cs(q_98, q_150, q_185, q_217, q_851, q_1162, q_1206, q_1421, -q_1663, q_1763),
  anxiety = cs(q_66, -q_85, q_808, q_986, q_1505, q_1989, q_1992, q_3835, q_4232, q_4285),
  conscientiousness = cs(-q_35, -q_44, q_76, q_82, q_491, q_619, -q_746, q_931, q_1321, q_1507, q_1916),
  extraversion = cs(q_20, q_31, -q_55, q_158, q_168, q_254, q_262, q_279, -q_314, -q_684),
  neuroticism = cs(q_52, q_67, -q_85, q_126, q_331, q_811, q_994, q_1479, -q_1596, q_4235),
  openness = cs(q_38, q_39, q_77, q_89, q_128, q_148, q_292, q_516, q_1334, -q_2775))
```

##Now show the combined keys
This includes some information on peer ratings.  It is arranged as a list.

```{r}
short.keys2 <- c(short.keys,Emilie_keys)
```

#Score the 371 and peer ratings on SAPA correlation matrix.

We use *scoreOverlap* function to correct for overlapping items

The output is rather long but is useful

```{r}
scores <- scoreOverlap(short.keys2,peers.cor)
scores
```

##Empirical scale construction
What are the items that most correlate with the peerratings?

We use the *bestScales* function to do this.

If we do this on the raw items, we can then bootstrap and aggregate multiple solutions.

#not currently working
