library(knitr)
library(gtools)
## Warning: package 'gtools' was built under R version 4.1.3
library(multicon)
## Loading required package: psych
## 
## Attaching package: 'psych'
## The following object is masked from 'package:gtools':
## 
##     logit
## Loading required package: abind
## Loading required package: foreach
library(psych)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(Hmisc)
## Warning: package 'Hmisc' was built under R version 4.1.3
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.1.3
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following object is masked from 'package:psych':
## 
##     describe
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(usdm)
## Warning: package 'usdm' was built under R version 4.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.1.3
## Loading required package: raster
## Warning: package 'raster' was built under R version 4.1.3
## 
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
## 
##     select
library(car)
## Warning: package 'car' was built under R version 4.1.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.1.3
## 
## Attaching package: 'car'
## The following object is masked from 'package:usdm':
## 
##     vif
## The following object is masked from 'package:dplyr':
## 
##     recode
## The following object is masked from 'package:psych':
## 
##     logit
## The following object is masked from 'package:gtools':
## 
##     logit
# Set the working directory.  
x <- getwd()
setwd(x)

#read in CSV file
mydata = read.csv("kindness data ac removed.csv", header=T, sep=",")
names(mydata)
##  [1] "VIA1"          "VIA2"          "VIA3"          "VIA4"         
##  [5] "VIA5"          "VIA6"          "VIA7"          "R_VIA8"       
##  [9] "R_VIA9"        "R_VIA10"       "PSA_1"         "PSA_2"        
## [13] "PSA_3"         "PSA_4"         "PSA_5"         "PSA_6"        
## [17] "PSA_7"         "PSA_8"         "PSA_9"         "PSA_10"       
## [21] "PSA_11"        "PSA_12"        "PSA_13"        "PSA_14"       
## [25] "PSA_15"        "PSA_16"        "R_BFI2.S_1_E"  "BFI2.S_2_A"   
## [29] "R_BFI2.S_3_C"  "BFI2.S_4_N"    "BFI2.S_5_O"    "BFI2.S_6_E"   
## [33] "R_BFI2.S_7_A"  "R_BFI2.S_8_C"  "BFI2.S_9_N"    "R_BFI2.S_10_O"
## [37] "BFI2.S_11_E"   "BFI2.S_12_A"   "BFI2.S_13_C"   "R_BFI2.S_14_N"
## [41] "BFI2.S_15_O"   "BFI2.S_16_E"   "R_BFI2.S_17_A" "BFI2.S_18_C"  
## [45] "R_BFI2.S_19_N" "R_BFI2.S_20_O" "R_BFI2.S_21_E" "BFI2.S_22_A"  
## [49] "BFI2.S_23_C"   "R_BFI2.S_24_N" "BFI2.S_25_O"   "R_BFI2.S_26_E"
## [53] "R_BFI2.S_27_A" "R_BFI2.S_28_C" "BFI2.S_29_N"   "R_BFI2.S_30_O"
## [57] "Age"           "Education"     "Marital"       "ACCheck"
#create dataframe with only BFI items 
BFIitems <- mydata %>% dplyr::select(R_BFI2.S_1_E, BFI2.S_2_A, R_BFI2.S_3_C, BFI2.S_4_N, BFI2.S_5_O, BFI2.S_6_E, R_BFI2.S_7_A, R_BFI2.S_8_C, BFI2.S_9_N, R_BFI2.S_10_O, BFI2.S_11_E, BFI2.S_12_A, BFI2.S_13_C, R_BFI2.S_14_N, BFI2.S_15_O, BFI2.S_16_E, R_BFI2.S_17_A, BFI2.S_18_C, R_BFI2.S_19_N, R_BFI2.S_20_O, R_BFI2.S_21_E, BFI2.S_22_A, BFI2.S_23_C, R_BFI2.S_24_N, BFI2.S_25_O, R_BFI2.S_26_E, R_BFI2.S_27_A, R_BFI2.S_28_C, BFI2.S_29_N, R_BFI2.S_30_O)
describe(BFIitems)
## BFIitems 
## 
##  30  Variables      148  Observations
## --------------------------------------------------------------------------------
## R_BFI2.S_1_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.954    3.236     1.66 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     27    25    22    34    40
## Proportion 0.182 0.169 0.149 0.230 0.270
## --------------------------------------------------------------------------------
## BFI2.S_2_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958    3.034    1.544 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     23    36    31    29    29
## Proportion 0.155 0.243 0.209 0.196 0.196
## --------------------------------------------------------------------------------
## R_BFI2.S_3_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958     2.98     1.66 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     33    27    31    24    33
## Proportion 0.223 0.182 0.209 0.162 0.223
## --------------------------------------------------------------------------------
## BFI2.S_4_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    3.095     1.66 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     33    19    31    31    34
## Proportion 0.223 0.128 0.209 0.209 0.230
## --------------------------------------------------------------------------------
## BFI2.S_5_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    3.216    1.564 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     22    26    34    30    36
## Proportion 0.149 0.176 0.230 0.203 0.243
## --------------------------------------------------------------------------------
## BFI2.S_6_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.954    3.203    1.503 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     18    30    38    28    34
## Proportion 0.122 0.203 0.257 0.189 0.230
## --------------------------------------------------------------------------------
## R_BFI2.S_7_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958    3.081    1.638 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     27    33    23    31    34
## Proportion 0.182 0.223 0.155 0.209 0.230
## --------------------------------------------------------------------------------
## R_BFI2.S_8_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.959    3.128    1.605 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     26    27    31    30    34
## Proportion 0.176 0.182 0.209 0.203 0.230
## --------------------------------------------------------------------------------
## BFI2.S_9_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958    3.088    1.661 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     29    30    23    31    35
## Proportion 0.196 0.203 0.155 0.209 0.236
## --------------------------------------------------------------------------------
## R_BFI2.S_10_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.957    2.811    1.552 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     32    37    28    29    22
## Proportion 0.216 0.250 0.189 0.196 0.149
## --------------------------------------------------------------------------------
## BFI2.S_11_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    2.953    1.652 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     37    21    30    32    28
## Proportion 0.250 0.142 0.203 0.216 0.189
## --------------------------------------------------------------------------------
## BFI2.S_12_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.955    3.182    1.665 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     29    25    21    36    37
## Proportion 0.196 0.169 0.142 0.243 0.250
## --------------------------------------------------------------------------------
## BFI2.S_13_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.959    3.088    1.548 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     24    30    32    33    29
## Proportion 0.162 0.203 0.216 0.223 0.196
## --------------------------------------------------------------------------------
## R_BFI2.S_14_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    2.946    1.631 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     29    39    22    27    31
## Proportion 0.196 0.264 0.149 0.182 0.209
## --------------------------------------------------------------------------------
## BFI2.S_15_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956     3.02    1.535 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     29    23    36    36    24
## Proportion 0.196 0.155 0.243 0.243 0.162
## --------------------------------------------------------------------------------
## BFI2.S_16_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.955    3.108    1.464 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     19    33    35    35    26
## Proportion 0.128 0.223 0.236 0.236 0.176
## --------------------------------------------------------------------------------
## R_BFI2.S_17_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.949    3.311    1.643 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     22    30    21    30    45
## Proportion 0.149 0.203 0.142 0.203 0.304
## --------------------------------------------------------------------------------
## BFI2.S_18_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    2.919    1.634 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     30    39    23    25    31
## Proportion 0.203 0.264 0.155 0.169 0.209
## --------------------------------------------------------------------------------
## R_BFI2.S_19_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    3.209     1.62 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     27    22    28    35    36
## Proportion 0.182 0.149 0.189 0.236 0.243
## --------------------------------------------------------------------------------
## R_BFI2.S_20_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958    2.885    1.669 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     36    31    25    26    30
## Proportion 0.243 0.209 0.169 0.176 0.203
## --------------------------------------------------------------------------------
## R_BFI2.S_21_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958    2.953    1.653 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     34    26    33    23    32
## Proportion 0.230 0.176 0.223 0.155 0.216
## --------------------------------------------------------------------------------
## BFI2.S_22_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.957        3    1.557 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     30    24    35    34    25
## Proportion 0.203 0.162 0.236 0.230 0.169
## --------------------------------------------------------------------------------
## BFI2.S_23_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.959    3.074    1.637 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     29    27    30    28    34
## Proportion 0.196 0.182 0.203 0.189 0.230
## --------------------------------------------------------------------------------
## R_BFI2.S_24_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    3.101    1.554 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     27    22    37    33    29
## Proportion 0.182 0.149 0.250 0.223 0.196
## --------------------------------------------------------------------------------
## BFI2.S_25_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    2.764    1.577 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     35    37    27    26    23
## Proportion 0.236 0.250 0.182 0.176 0.155
## --------------------------------------------------------------------------------
## R_BFI2.S_26_E 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.956    2.986    1.539 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     30    24    35    36    23
## Proportion 0.203 0.162 0.236 0.243 0.155
## --------------------------------------------------------------------------------
## R_BFI2.S_27_A 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.959    2.959    1.652 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     35    25    28    31    29
## Proportion 0.236 0.169 0.189 0.209 0.196
## --------------------------------------------------------------------------------
## R_BFI2.S_28_C 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.959    3.149    1.588 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     25    27    30    33    33
## Proportion 0.169 0.182 0.203 0.223 0.223
## --------------------------------------------------------------------------------
## BFI2.S_29_N 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.948    2.926    1.524 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     26    41    20    40    21
## Proportion 0.176 0.277 0.135 0.270 0.142
## --------------------------------------------------------------------------------
## R_BFI2.S_30_O 
##        n  missing distinct     Info     Mean      Gmd 
##      148        0        5    0.958     3.02    1.527 
## 
## lowest : 1 2 3 4 5, highest: 1 2 3 4 5
##                                         
## Value          1     2     3     4     5
## Frequency     25    30    37    29    27
## Proportion 0.169 0.203 0.250 0.196 0.182
## --------------------------------------------------------------------------------
#create key for scoring.  Items with negative signs reversed scored.
BFIkeys.list<-list("Ext"=c(-1, 6, 11, 16, -21, -26), "Agr"=c(2, -7, 12, -17, 22, -27), "Con"=c(-3, -8, 13, 18, 23, -28), "Neur"=c(4, 9, -14, -19, -24, 29), "Open"=c(5, -10, 15, -20, 25, -30))

#Score measure and enter scores in a data frame  
BFIout <- scoreTest(BFIitems, BFIkeys.list, rel=T, maxScore=5, minScore=1, check.keys=T)
## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.

## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.

## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.

## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
describe(BFIout$scores)
## BFIout$scores 
## 
##  5  Variables      148  Observations
## --------------------------------------------------------------------------------
## Ext 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       16    0.991    3.015    0.631    2.058    2.333 
##      .25      .50      .75      .90      .95 
##    2.667    3.000    3.333    3.833    4.000 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.83333333333333 (5, 0.034), 2 (3, 0.020), 2.16666666666667 (6, 0.041),
## 2.33333333333333 (5, 0.034), 2.5 (11, 0.074), 2.66666666666667 (18, 0.122),
## 2.83333333333333 (17, 0.115), 3 (17, 0.115), 3.16666666666667 (21, 0.142),
## 3.33333333333333 (11, 0.074), 3.5 (8, 0.054), 3.66666666666667 (9, 0.061),
## 3.83333333333333 (7, 0.047), 4 (7, 0.047), 4.16666666666667 (2, 0.014),
## 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
## Agr 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       19    0.991    2.977   0.7067    1.833    2.167 
##      .25      .50      .75      .90      .95 
##    2.500    3.000    3.375    3.833    4.000 
## 
## lowest : 1.500000 1.666667 1.833333 2.000000 2.166667
## highest: 3.833333 4.000000 4.166667 4.333333 4.500000
## 
## 1.5 (2, 0.014), 1.66666666666667 (3, 0.020), 1.83333333333333 (4, 0.027), 2 (2,
## 0.014), 2.16666666666667 (7, 0.047), 2.33333333333333 (10, 0.068), 2.5 (12,
## 0.081), 2.66666666666667 (6, 0.041), 2.83333333333333 (24, 0.162), 3 (14,
## 0.095), 3.16666666666667 (16, 0.108), 3.33333333333333 (11, 0.074), 3.5 (15,
## 0.101), 3.66666666666667 (3, 0.020), 3.83333333333333 (10, 0.068), 4 (3,
## 0.020), 4.16666666666667 (3, 0.020), 4.33333333333333 (2, 0.014), 4.5 (1,
## 0.007)
## --------------------------------------------------------------------------------
## Con 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       17    0.993    2.971   0.6872    2.000    2.167 
##      .25      .50      .75      .90      .95 
##    2.500    3.000    3.333    3.833    4.000 
## 
## lowest : 1.666667 1.833333 2.000000 2.166667 2.333333
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.66666666666667 (4, 0.027), 1.83333333333333 (3, 0.020), 2 (3, 0.020),
## 2.16666666666667 (6, 0.041), 2.33333333333333 (11, 0.074), 2.5 (11, 0.074),
## 2.66666666666667 (19, 0.128), 2.83333333333333 (12, 0.081), 3 (18, 0.122),
## 3.16666666666667 (15, 0.101), 3.33333333333333 (11, 0.074), 3.5 (10, 0.068),
## 3.66666666666667 (6, 0.041), 3.83333333333333 (8, 0.054), 4 (7, 0.047),
## 4.16666666666667 (3, 0.020), 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
## Neur 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       15     0.99    2.975   0.6438    2.058    2.167 
##      .25      .50      .75      .90      .95 
##    2.625    3.000    3.333    3.667    4.000 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.500000 3.666667 3.833333 4.000000 4.166667
## 
## 1.83333333333333 (2, 0.014), 2 (6, 0.041), 2.16666666666667 (9, 0.061),
## 2.33333333333333 (6, 0.041), 2.5 (14, 0.095), 2.66666666666667 (23, 0.155),
## 2.83333333333333 (11, 0.074), 3 (11, 0.074), 3.16666666666667 (21, 0.142),
## 3.33333333333333 (13, 0.088), 3.5 (7, 0.047), 3.66666666666667 (11, 0.074),
## 3.83333333333333 (3, 0.020), 4 (8, 0.054), 4.16666666666667 (3, 0.020)
## --------------------------------------------------------------------------------
## Open 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       16     0.99    3.047   0.6379    2.058    2.333 
##      .25      .50      .75      .90      .95 
##    2.667    3.000    3.500    3.833    3.942 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.83333333333333 (5, 0.034), 2 (3, 0.020), 2.16666666666667 (4, 0.027),
## 2.33333333333333 (8, 0.054), 2.5 (13, 0.088), 2.66666666666667 (8, 0.054),
## 2.83333333333333 (17, 0.115), 3 (18, 0.122), 3.16666666666667 (23, 0.155),
## 3.33333333333333 (11, 0.074), 3.5 (11, 0.074), 3.66666666666667 (8, 0.054),
## 3.83333333333333 (11, 0.074), 4 (3, 0.020), 4.16666666666667 (4, 0.027),
## 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
BFIout$rel
##       raw_alpha  std.alpha   G6(smc)  average_r       S/N        ase     mean
## Ext  0.08986836 0.09931858 0.0972824 0.01804675 0.1102705 0.11593469 2.962838
## Agr  0.15318865 0.15592532 0.1553861 0.02986861 0.1847293 0.10772893 2.977477
## Con  0.15545746 0.15708274 0.1592229 0.03012372 0.1863561 0.10726943 2.916667
## Neur 0.27690589 0.27836321 0.2594490 0.06040627 0.3857387 0.09190162 3.027027
## Open 0.22809062 0.22935937 0.2382879 0.04725938 0.2976217 0.09780354 3.024775
##             sd         NA
## Ext  0.5931140 0.01199299
## Agr  0.6250166 0.04113753
## Con  0.6225481 0.04127326
## Neur 0.6624167 0.06533663
## Open 0.6300502 0.05347805
BFI.scores <-data.frame(BFIout$scores)

#create dataframe with only PSA items
PSAitems <- mydata %>% dplyr::select(PSA_1, PSA_2, PSA_3, PSA_4, PSA_5, PSA_6, PSA_7, PSA_8, PSA_9, PSA_10, PSA_11, PSA_12, PSA_13, PSA_13, PSA_14, PSA_15, PSA_16)
PSAscore <- PSAitems %>% rowMeans
PSA.score<-data.frame(PSAscore)

#create dataframe with only VIA items
VIAitems <- mydata %>% dplyr::select(VIA1, VIA2, VIA3, VIA4, VIA5, VIA6, VIA7, R_VIA8, R_VIA9, R_VIA10)

#create key for scoring. Items with negative signs reverse scored. 
VIAkeys.list<-list("VIA.Kindness" = c(1, 2, 3, 4, 5, 6, 7, -8, -9, -10))

#score measure and enter scores in a data frame
VIAout <- scoreTest(VIAitems, VIAkeys.list, rel = T, maxScore = 5, minScore = 1, check.keys = T)
## Warning in alpha(data.frame(x), check.keys = check.keys): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
describe(VIAout$scores)
## VIAout$scores 
## 
##  1  Variables      148  Observations
## --------------------------------------------------------------------------------
## VIA.Kindness 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       22    0.994    2.954   0.4967     2.20     2.37 
##      .25      .50      .75      .90      .95 
##     2.70     3.00     3.30     3.50     3.60 
## 
## lowest : 1.7 2.0 2.1 2.2 2.3, highest: 3.6 3.7 3.8 4.0 4.1
## --------------------------------------------------------------------------------
VIAout$rel
##              raw_alpha std.alpha  G6(smc)  average_r       S/N      ase
## VIA.Kindness 0.1762038 0.1759178 0.209134 0.02090094 0.2134712 0.100619
##                  mean        sd         NA
## VIA.Kindness 2.948649 0.4881572 0.02123895
VIA.score<-data.frame(VIAout$scores)

#combine datasets
mydatascored <- data.frame(BFI.scores, VIA.score, PSA.score)
names(mydatascored)
## [1] "Ext"          "Agr"          "Con"          "Neur"         "Open"        
## [6] "VIA.Kindness" "PSAscore"
#check histograms for normality
hist(mydatascored$Ext)

hist(mydatascored$Agr)

hist(mydatascored$Open)

hist(mydatascored$Con)

hist(mydatascored$Neur)

hist(mydatascored$VIA.Kindness)

hist(mydatascored$PSAscore)

#check normality using psych package - might need to remove Hmisc
describe(mydatascored)
## mydatascored 
## 
##  7  Variables      148  Observations
## --------------------------------------------------------------------------------
## Ext 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       16    0.991    3.015    0.631    2.058    2.333 
##      .25      .50      .75      .90      .95 
##    2.667    3.000    3.333    3.833    4.000 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.83333333333333 (5, 0.034), 2 (3, 0.020), 2.16666666666667 (6, 0.041),
## 2.33333333333333 (5, 0.034), 2.5 (11, 0.074), 2.66666666666667 (18, 0.122),
## 2.83333333333333 (17, 0.115), 3 (17, 0.115), 3.16666666666667 (21, 0.142),
## 3.33333333333333 (11, 0.074), 3.5 (8, 0.054), 3.66666666666667 (9, 0.061),
## 3.83333333333333 (7, 0.047), 4 (7, 0.047), 4.16666666666667 (2, 0.014),
## 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
## Agr 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       19    0.991    2.977   0.7067    1.833    2.167 
##      .25      .50      .75      .90      .95 
##    2.500    3.000    3.375    3.833    4.000 
## 
## lowest : 1.500000 1.666667 1.833333 2.000000 2.166667
## highest: 3.833333 4.000000 4.166667 4.333333 4.500000
## 
## 1.5 (2, 0.014), 1.66666666666667 (3, 0.020), 1.83333333333333 (4, 0.027), 2 (2,
## 0.014), 2.16666666666667 (7, 0.047), 2.33333333333333 (10, 0.068), 2.5 (12,
## 0.081), 2.66666666666667 (6, 0.041), 2.83333333333333 (24, 0.162), 3 (14,
## 0.095), 3.16666666666667 (16, 0.108), 3.33333333333333 (11, 0.074), 3.5 (15,
## 0.101), 3.66666666666667 (3, 0.020), 3.83333333333333 (10, 0.068), 4 (3,
## 0.020), 4.16666666666667 (3, 0.020), 4.33333333333333 (2, 0.014), 4.5 (1,
## 0.007)
## --------------------------------------------------------------------------------
## Con 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       17    0.993    2.971   0.6872    2.000    2.167 
##      .25      .50      .75      .90      .95 
##    2.500    3.000    3.333    3.833    4.000 
## 
## lowest : 1.666667 1.833333 2.000000 2.166667 2.333333
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.66666666666667 (4, 0.027), 1.83333333333333 (3, 0.020), 2 (3, 0.020),
## 2.16666666666667 (6, 0.041), 2.33333333333333 (11, 0.074), 2.5 (11, 0.074),
## 2.66666666666667 (19, 0.128), 2.83333333333333 (12, 0.081), 3 (18, 0.122),
## 3.16666666666667 (15, 0.101), 3.33333333333333 (11, 0.074), 3.5 (10, 0.068),
## 3.66666666666667 (6, 0.041), 3.83333333333333 (8, 0.054), 4 (7, 0.047),
## 4.16666666666667 (3, 0.020), 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
## Neur 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       15     0.99    2.975   0.6438    2.058    2.167 
##      .25      .50      .75      .90      .95 
##    2.625    3.000    3.333    3.667    4.000 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.500000 3.666667 3.833333 4.000000 4.166667
## 
## 1.83333333333333 (2, 0.014), 2 (6, 0.041), 2.16666666666667 (9, 0.061),
## 2.33333333333333 (6, 0.041), 2.5 (14, 0.095), 2.66666666666667 (23, 0.155),
## 2.83333333333333 (11, 0.074), 3 (11, 0.074), 3.16666666666667 (21, 0.142),
## 3.33333333333333 (13, 0.088), 3.5 (7, 0.047), 3.66666666666667 (11, 0.074),
## 3.83333333333333 (3, 0.020), 4 (8, 0.054), 4.16666666666667 (3, 0.020)
## --------------------------------------------------------------------------------
## Open 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       16     0.99    3.047   0.6379    2.058    2.333 
##      .25      .50      .75      .90      .95 
##    2.667    3.000    3.500    3.833    3.942 
## 
## lowest : 1.833333 2.000000 2.166667 2.333333 2.500000
## highest: 3.666667 3.833333 4.000000 4.166667 4.333333
## 
## 1.83333333333333 (5, 0.034), 2 (3, 0.020), 2.16666666666667 (4, 0.027),
## 2.33333333333333 (8, 0.054), 2.5 (13, 0.088), 2.66666666666667 (8, 0.054),
## 2.83333333333333 (17, 0.115), 3 (18, 0.122), 3.16666666666667 (23, 0.155),
## 3.33333333333333 (11, 0.074), 3.5 (11, 0.074), 3.66666666666667 (8, 0.054),
## 3.83333333333333 (11, 0.074), 4 (3, 0.020), 4.16666666666667 (4, 0.027),
## 4.33333333333333 (1, 0.007)
## --------------------------------------------------------------------------------
## VIA.Kindness 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       22    0.994    2.954   0.4967     2.20     2.37 
##      .25      .50      .75      .90      .95 
##     2.70     3.00     3.30     3.50     3.60 
## 
## lowest : 1.7 2.0 2.1 2.2 2.3, highest: 3.6 3.7 3.8 4.0 4.1
## --------------------------------------------------------------------------------
## PSAscore 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##      148        0       27    0.996    2.995   0.3955    2.438    2.562 
##      .25      .50      .75      .90      .95 
##    2.797    2.969    3.250    3.456    3.541 
## 
## lowest : 2.1250 2.3125 2.3750 2.4375 2.5000, highest: 3.6250 3.6875 3.7500 3.8125 3.8750
## --------------------------------------------------------------------------------
library(Hmisc)
#correlation table, examine independence of observations
mydatamatrix<-as.matrix(mydatascored)
rcorr(mydatamatrix)
##                Ext   Agr   Con Neur  Open VIA.Kindness PSAscore
## Ext           1.00 -0.12 -0.04 0.05  0.14         0.03    -0.19
## Agr          -0.12  1.00 -0.03 0.07  0.02         0.15    -0.05
## Con          -0.04 -0.03  1.00 0.01  0.07        -0.08     0.02
## Neur          0.05  0.07  0.01 1.00  0.02         0.04     0.12
## Open          0.14  0.02  0.07 0.02  1.00         0.05    -0.09
## VIA.Kindness  0.03  0.15 -0.08 0.04  0.05         1.00    -0.11
## PSAscore     -0.19 -0.05  0.02 0.12 -0.09        -0.11     1.00
## 
## n= 148 
## 
## 
## P
##              Ext    Agr    Con    Neur   Open   VIA.Kindness PSAscore
## Ext                 0.1333 0.6556 0.5324 0.0823 0.7291       0.0230  
## Agr          0.1333        0.7281 0.4182 0.8372 0.0742       0.5808  
## Con          0.6556 0.7281        0.9459 0.4181 0.3193       0.8115  
## Neur         0.5324 0.4182 0.9459        0.8055 0.6435       0.1602  
## Open         0.0823 0.8372 0.4181 0.8055        0.5788       0.2703  
## VIA.Kindness 0.7291 0.0742 0.3193 0.6435 0.5788              0.1680  
## PSAscore     0.0230 0.5808 0.8115 0.1602 0.2703 0.1680
#multicollinearity
vif.1<-usdm::vif(mydatascored)
vif.1
##      Variables      VIF
## 1          Ext 1.084345
## 2          Agr 1.050305
## 3          Con 1.014812
## 4         Neur 1.028788
## 5         Open 1.034037
## 6 VIA.Kindness 1.044339
## 7     PSAscore 1.076651
#create first model
VIA.Kindness.Model<-lm(VIA.Kindness ~ Agr + Open, data = mydatascored)
summary(VIA.Kindness.Model)
## 
## Call:
## lm(formula = VIA.Kindness ~ Agr + Open, data = mydatascored)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.19175 -0.24326 -0.00049  0.31604  1.13956 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.54354    0.26076   9.754   <2e-16 ***
## Agr          0.10304    0.05775   1.784   0.0765 .  
## Open         0.03404    0.06421   0.530   0.5968    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4375 on 145 degrees of freedom
## Multiple R-squared:  0.02356,    Adjusted R-squared:  0.01009 
## F-statistic: 1.749 on 2 and 145 DF,  p-value: 0.1776
#checking assumptions
#homoscedasticity
plot(VIA.Kindness.Model, which = 1)

#normally distributed residuals
plot(VIA.Kindness.Model, which = 2)

#checking lineraity 
plot(VIA.Kindness~Agr, data=mydatascored)

plot(VIA.Kindness~Open, data=mydatascored)

#All assumptions met for first model

#create second model
PSA.Model<-lm(PSAscore ~ Agr + Open, data = mydatascored)
summary(PSA.Model)
## 
## Call:
## lm(formula = PSAscore ~ Agr + Open, data = mydatascored)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.85814 -0.23247 -0.01943  0.25162  0.84098 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.23898    0.20821  15.556   <2e-16 ***
## Agr         -0.02467    0.04611  -0.535    0.593    
## Open        -0.05612    0.05127  -1.095    0.276    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3494 on 145 degrees of freedom
## Multiple R-squared:  0.01027,    Adjusted R-squared:  -0.00338 
## F-statistic: 0.7524 on 2 and 145 DF,  p-value: 0.4731
#checking assumptions
#homoscedasticity
plot(PSA.Model, which = 1)

#plot looks a little odd, check homoscedasticity with Breusch-Pagen test
ncvTest(PSA.Model)
## Non-constant Variance Score Test 
## Variance formula: ~ fitted.values 
## Chisquare = 0.3191687, Df = 1, p = 0.57211
#normally distributed residuals
plot(PSA.Model, which = 2)

#checking lineraity 
plot(PSAscore~Agr, data=mydatascored)

plot(PSAscore~Open, data=mydatascored)

#All assumptions met for second model

```