HOMEWORK 4

PCA analysis

Research question: Can we identify underlying patterns of personal values and preferences based on these variables?
mydata<-read.table("./ESS9e03_2.csv", header = TRUE, sep= "," , dec=";")
#because the sample is too big only the observations regarding Austria (AT) will be filtered first and the varibales that have potential for this analysis will be included
#install.packages("dplyr")
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
mydata_AT<- filter(mydata, cntry== "AT")
mydata_AT1<- select(mydata_AT, "ipcrtiv","impdiff","ipadvnt", "ipgdtim", "happy", "health", "sclmeet", "sclact")
#now in order to make sample smaler and easier to work with we are going to preform the random sampling, leaving only 300 observations. 
set.seed(123)
mydata_AT1_samp <- mydata_AT1[sample(nrow(mydata_AT1),size = 300), ]
na.omit(mydata_AT1_samp)
##      ipcrtiv impdiff ipadvnt ipgdtim happy health sclmeet sclact
## 2463       6       6       6       4     9      2       3      2
## 2227       2       3       5       5     8      3       5      4
## 526        1       3       2       2     8      2       6      4
## 195        1       1       2       3     4      2       5      3
## 1842       3       6       2       1    10      3       5      2
## 1142       4       4       6       5     7      2       5      3
## 1253       3       5       5       2     9      2       5      5
## 1268       3       4       4       1     8      2       5      3
## 1038       2       2       2       1     9      1       5      3
## 665        1       2       2       1    10      2       6      4
## 1627       1       3       3       1     8      1       6      3
## 1011       3       4       4       2     9      2       4      2
## 1115       5       4       5       4     6      2       4      2
## 953        3       3       1       2     7      3       2      1
## 348        4       1       5       1    10      2       6      3
## 1017       1       3       2       3    10      1       4      3
## 2013       1       1       3       1     9      2       6      3
## 1379       1       1       6       1    10      1       5      3
## 2074       5       6       6       4     8      3       5      3
## 1450       1       1       5       4     8      3       6      4
## 1673       5       2       2       2     7      2       4      3
## 1790       3       3       4       3     7      3       5      3
## 211        1       4       5       5    10      1       6      3
## 1614       2       4       4       2     9      1       6      3
## 555        1       5       5       5     9      1       6      5
## 1895       8       6       5       6     3      4       1      1
## 373        2       3       4       2     8      3       6      3
## 1167       3       2       5       2     7      1       7      3
## 1799       1       3       3       3     8      2       3      1
## 905        3       3       2       3     3      2       5      3
## 1866       2       3       3       1     6      2       6      3
## 1047       1       3       4       4     9      1       6      3
## 309        6       6       6       3     7      2       3      3
## 1248       1       2       4       1     7      2       6      3
## 166        3       3       2       3     5      2       5      3
## 217        3       3       3       2     7      3       5      3
## 1314       1       1       4       1     8      1       5      8
## 2120       3       3       5       3     8      3       3      2
## 588        1       1       2       2     9      1       6      3
## 1599       2       3       3       4     8      2       6      4
## 141        1       4       6       4    10      1       5      3
## 722        2       1       3       1     7      3       6      2
## 153        4       4       4       3     4      3       2      2
## 294        2       5       4       1     9      1       6      4
## 277        1       2       4       3    10      2       5      2
## 1487       3       3       5       3     8      2       5      3
## 41         4       1       5       5     4      3       6      5
## 2138       3       4       5       4     6      3       7      3
## 316        8       8       8       8     8      1       4      3
## 1183       2       2       3       2     9      1       6      2
## 752        1       4       5       1    10      2       7      1
## 374        4       2       4       2     8      1       6      3
## 2495       3       3       3       2     8      2       5      4
## 2033       3       5       6       2     9      2       5      3
## 2082       5       5       4       3     9      3       6      2
## 516        4       2       3       1     8      2       4      3
## 13         3       2       5       2    10      3       5      3
## 2117       2       2       3       2     8      2       4      3
## 2038       4       3       4       2     6      2       3      1
## 1919       3       6       4       5     3      3       2      8
## 755        1       1       1       1    10      1       6      4
## 1332       2       4       5       2     9      2       5      3
## 1113       1       1       1       1     9      1       5      4
## 1006       1       2       2       2     9      1       6      3
## 2339       3       1       2       2     8      2       5      2
## 1448       1       3       3       2     8      3       6      4
## 671        5       5       6       5     7      3       3      2
## 2169       3       4       5       2     7      2       4      2
## 1134       1       2       2       2    10      1       7      4
## 1088       5       4       6       4    10      2       3      2
## 1507       2       2       6       2     5      4       4      4
## 1934       4       5       6       4     9      2       5      3
## 1501       4       6       6       6     8      2       6      3
## 480        1       4       2       1     6      2       3      2
## 2115       5       5       4       1     8      3       5      1
## 1914       2       2       3       1     7      2       6      3
## 1871       3       2       4       1     9      2       6      3
## 1109       2       4       4       3     8      2       5      3
## 165        3       1       4       1     7      1       2      2
## 1075       2       3       3       2     8      1       5      3
## 1386       2       5       5       4     7      3       2      2
## 2284       3       4       4       3     7      3       6      2
## 610        3       2       3       1     8      2       6      5
## 2378       4       3       3       2     9      1       5      3
## 127        2       1       1       1     8      2       6      4
## 2260       1       1       1       1     9      3       6      4
## 686        2       3       4       4     7      2       5      3
## 1982       2       1       1       1     6      1       7      4
## 931        2       3       3       3    10      1       6      3
## 2291       2       2       3       1     8      1       4      3
## 847        1       2       2       2     7      2       6      5
## 983        1       5       6       1    10      2       4      3
## 619        2       3       3       2     9      1       4      3
## 1927       3       1       3       2     7      2       4      2
## 477        2       4       5       1    10      3       4      3
## 1999       4       4       2       2     9      1       5      3
## 151        2       1       3       2     7      2       4      3
## 1638       3       1       2       1    10      3       6      3
## 2208       1       5       6       2     6      1       6      3
## 2203       3       3       3       2     6      2       6      4
## 1029       2       3       5       4     6      1       6      3
## 326        3       2       5       4     8      2       6      3
## 1956       2       3       5       2     8      1       6      3
## 1262       4       5       6       2    10      3       5      3
## 1788       2       2       3       4     8      1       5      3
## 1363       3       5       4       3     9      2       6      2
## 985        3       5       6       2     9      3       5      3
## 2087       3       5       5       3     8      3       5      2
## 986        1       3       4       3     8      1       6      3
## 137        1       1       2       1     7      1       6      3
## 1762       3       4       5       2     9      1       5      3
## 1584       4       6       6       5     7      3       4      3
## 589        3       3       3       2     8      2       4      3
## 1903       2       2       4       2     7      2       5      3
## 2392       2       4       4       3     7      2       5      3
## 2244       3       4       5       1     6      2       5      2
## 1793       2       4       4       3     8      2       5      3
## 680        4       3       6       4     6      2       6      4
## 1630       2       2       2       2     9      1       7      4
## 2393       4       4       5       3     7      3       3      2
## 1808       3       3       4       2     8      3       6      3
## 344        1       1       2       2    10      1       2      1
## 2496       2       1       3       1     7      3       4      3
## 1885       4       4       5       4     5      3       3      2
## 876        4       5       6       4     9      2       3      1
## 2225       4       5       4       2    10      3       3      2
## 554        3       4       4       3     8      2       5      3
## 2132       1       2       3       3     6      2       6      4
## 1547       2       2       2       3     8      1       6      4
## 1326       2       6       6       2    10      4       2      1
## 706        3       3       5       3     6      2       4      3
## 712        2       2       2       1     7      1       6      3
## 1452       2       4       4       3     8      3       5      3
## 672        2       1       5       3     5      3       5      3
## 1274       2       3       4       3     7      4       3      1
## 1828       7       8       7       8    10      2       5      3
## 528        4       4       3       3     6      2       5      3
## 1569       3       1       1       1     9      2       7      5
## 2088       2       2       5       3    10      2       6      4
## 1960       1       2       2       2     8      1       6      3
## 473        1       2       3       2     6      2       6      3
## 2248       1       1       5       3     6      2       3      1
## 2002       3       2       3       1     3      3       6      3
## 1149       1       1       3       1     7      2       5      2
## 2037       1       2       1       1     9      1       4      3
## 2313       3       3       3       2     8      2       4      3
## 2406       3       2       2       2     8      1       7      4
## 2234       3       5       3       3     8      2       6      4
## 458        3       2       5       2     8      2       3      3
## 831        1       1       6       1     6      3       3      2
## 1078       2       3       4       2     8      2       6      4
## 919        2       3       4       2     8      2       4      4
## 1562       3       5       6       3     8      2       6      3
## 2283       2       2       4       2     9      1       4      4
## 1313       3       2       2       1     7      3       6      4
## 185        2       2       5       3    10      1       6      2
## 413        3       2       3       3     9      2       4      3
## 627        4       3       3       2     7      4       5      3
## 1333       1       1       4       2    10      1       4      1
## 2253       3       1       2       2     5      2       1      1
## 1899       1       3       3       2     7      2       4      3
## 779        3       3       4       2     9      1       6      3
## 1561       2       2       3       2     8      2       5      3
## 564        2       3       3       1    10      2       6      3
## 794        2       3       4       4     9      2       4      2
## 1415       6       6       6       5     8      3       6      3
## 1370       1       1       6       3     7      2       6      3
## 160        3       4       5       3     7      3       6      2
## 617        3       4       6       3     8      3       3      3
## 357        2       3       5       3     8      1       4      2
## 279        3       4       6       4     6      3       4      4
## 270        3       3       4       3     8      2       5      3
## 2266       1       4       4       2     8      2       6      4
## 618        3       4       4       3     8      1       6      3
## 1905       2       2       3       3     8      1       6      4
## 337        3       4       5       3     5      3       2      2
## 2481       4       4       4       3     9      2       4      2
## 539        3       3       6       3     6      3       6      3
## 981        3       5       6       3     8      2       4      2
## 956        5       3       4       3     3      3       6      4
## 1781       4       3       5       3     7      3       2      2
## 1690       2       3       5       1    10      3       6      3
## 1522       1       2       6       3     8      1       5      3
## 1445       4       5       5       4     7      3       4      2
## 1081       3       2       1       1     4      2       4      4
## 2211       3       3       2       2     6      3       4      2
## 2286       3       3       3       3     7      2       5      3
## 1697       1       2       5       1     9      1       6      3
## 1413       2       3       4       2     9      2       5      4
## 117        3       4       4       3     8      2       6      3
## 648        5       6       6       5     8      3       4      2
## 1079       1       2       3       2     7      1       2      1
## 1241       1       1       2       1     8      1       7      1
## 1706       2       3       4       2     7      2       6      4
## 873        1       3       3       2     5      2       5      1
## 757        1       2       2       3     9      1       5      3
## 1965       1       4       5       4     8      2       5      2
## 988        2       4       4       3     8      2       5      3
## 711        3       3       2       2     8      3       5      3
## 1492       4       3       3       2     8      1       7      3
## 1234       3       5       6       6     7      3       4      2
## 349        3       3       4       2     7      2       4      2
## 1425       2       3       5       2     8      1       5      2
## 2374       3       6       3       3    10      1       4      3
## 386        2       1       3       2     7      3       4      4
## 1165       2       3       4       4     9      1       4      3
## 2072       3       3       3       3     8      1       7      2
## 1987       4       6       7       5     8      2       6      3
## 1154       1       5       4       4     7      2       6      3
## 2213       1       2       5       3     9      1       7      3
## 1727       4       4       6       5     6      2       4      2
## 1612       2       5       4       4     6      3       4      2
## 1401       3       3       4       3     8      2       5      3
## 2218       3       2       3       2     6      1       4      3
## 1469       3       3       3       2     9      1       4      3
## 710        1       3       3       3     9      2       6      2
## 1258       6       5       6       6     9      3       5      3
## 2112       8       3       5       2     8      3       5      3
## 2128       1       1       1       2    10      1       4      2
## 2429       3       3       6       1    10      3       7      1
## 1347       1       2       6       3     8      1       7      4
## 791        6       4       6       1     4      3       5      2
## 2292       3       5       6       4     9      1       4      3
## 2470       1       4       4       3     9      1       4      2
## 1341       2       2       2       1     6      3       6      2
## 807        4       4       4       4     7      2       4      3
## 1246       3       3       4       1     8      2       4      2
## 1311       4       2       3       1     8      2       5      3
## 1758       1       2       5       1     8      2       4      2
## 292        1       2       2       1    10      2       3      4
## 1250       2       4       5       5    10      2       4      2
## 1814       1       2       3       2     9      1       6      3
## 1708       2       7       5       5    10      1       6      4
## 297        2       1       5       2     7      2       7      4
## 860        3       4       5       3     7      3       5      2
## 605        4       5       5       4     7      2       3      3
## 1835       3       4       2       3     6      3       5      3
## 1261       2       3       3       1     8      2       6      4
## 2290       2       3       3       3     7      1       5      3
## 2407       1       5       5       5     5      4       5      2
## 1057       1       1       3       1     3      1       6      2
## 83         2       2       2       1     8      1       6      2
## 866        2       4       6       5     4      3       2      2
## 1023       5       6       5       3     6      2       5      3
## 76         2       2       3       2     9      1       6      3
## 1118       3       4       4       3     8      2       3      4
## 2163       1       1       2       2    10      1       5      3
## 2287       2       4       6       2     8      2       4      2
## 1382       3       3       3       2     7      2       6      4
## 682        3       4       1       2    10      1       5      5
## 2434       6       6       6       6     7      3       5      3
## 2347       3       4       6       5     9      2       6      5
## 989        3       5       6       4     9      2       4      3
## 1961       3       5       5       3     5      3       5      4
## 1738       4       2       2       3     9      1       5      4
## 1471       4       3       4       3     8      2       6      4
## 1362       3       3       5       3     5      4       6      2
## 243        3       3       5       2     7      1       6      2
## 2154       3       5       5       3     5      4       4      1
## 2059       3       4       4       3     7      2       4      3
## 625        4       3       5       2    10      2       6      4
## 2295       5       2       1       1     7      1       6      3
## 461        2       1       4       2    10      2       6      5
## 2459       2       3       4       2     6      3       7      4
## 31         3       4       4       3    10      1       7      4
## 1950       2       6       4       1    10      1       2      3
## 1139       2       3       3       2     7      3       4      2
## 2268       1       2       1       1    10      3       2      1
## 94         2       3       4       2     9      1       3      2
## 16         2       5       4       2     5      2       6      3
## 178        5       5       6       3     8      4       5      2
## 1436       5       3       6       2    77      5       2      2
## 2296       3       2       3       2     8      1       4      3
## 524        5       6       6       2     9      3       6      4
## 1461       2       2       4       1     9      2       6      4
## 924        4       3       6       2     8      2       4      2
## 1602       3       3       4       2     9      3       6      4
## 204        3       2       3       2     8      3       5      2
## 1146       3       4       5       3     8      2       5      3
## 259        2       6       6       2    10      1       5      1
## 494        1       4       3       3     8      1       6      4
## 1889       3       4       4       3     7      2       2      1
## 1784       2       3       3       3     7      3       4      3
## 2345       3       4       4       2     8      2       5      3
## 1355       2       2       2       2    10      1       4      3
## 1132       1       4       1       2     3      3       7      3
## 1325       2       1       6       4     8      1       4      3
## 10         3       2       4       2     9      1       6      3
## 170        3       4       5       5     8      2       7      3
## 1233       4       4       5       1     8      3       5      3
## 1851       3       1       4       2     5      2       4      3
## 2479       3       1       1       2     5      1       6      3
## 108        2       3       4       3    10      2       6      2
## 8          3       6       6       4     5      4       6      3
## 626        3       2       6       1     8      3       5      2
## 261        2       3       4       3     8      1       6      5
## 1098       2       3       4       3     8      2       5      3
## 1609       2       5       6       1    10      3       4      4
## 1911       1       2       6       2     9      2       5      3
## 1286       2       3       4       2     8      1       4      3
ID<-1:nrow(mydata_AT1_samp)
mydata_AT1_samp<-cbind(ID, mydata_AT1_samp)
#cleaning the values from mydata_AT1_samp because during the check of the data in the table we found some values that were out of the scale for the sampling (for example- the scale for one variable was from 1 to 6 and we had observation that had number 8), that data was removed here:
mydata_AT1_samp<-mydata_AT1_samp %>%
  filter(!ID %in% c(26, 49,218, 136, 233, 208, 272, 37, 60, 100, 288, 71, 213, 1))
head(mydata_AT1_samp, 10)
##    ID ipcrtiv impdiff ipadvnt ipgdtim happy health sclmeet sclact
## 1   2       2       3       5       5     8      3       5      4
## 2   3       1       3       2       2     8      2       6      4
## 3   4       1       1       2       3     4      2       5      3
## 4   5       3       6       2       1    10      3       5      2
## 5   6       4       4       6       5     7      2       5      3
## 6   7       3       5       5       2     9      2       5      5
## 7   8       3       4       4       1     8      2       5      3
## 8   9       2       2       2       1     9      1       5      3
## 9  10       1       2       2       1    10      2       6      4
## 10 11       1       3       3       1     8      1       6      3

Description of dataset:

  • ipcrtiv: Important to think new ideas and being creative (numeric with range 1-6)
  • impdiff: Important to try new and different things in life (numeric with range 1-6)
  • ipadvnt: Important to seek adventures and have an exciting life (numeric with range 1-6)
  • ipgdtim: Important to have a good time (numeric with range 1-6)

For this four variables the scale was following: 1 - Very much like me 2 - Like me 3 - Somewhat like me 4 - A little like me
5 - Not like me 6 - Not like me at all

  • happy: How happy are you (numeric with range 0-10; 0 is: extremly unhappy, 10 is: extremely happy)
  • health: Subjective general health (numeric with range 1-5; 1 is: very good, 5 is: very bad)
  • sclmeet: How often socially meet with friends, relatives or colleagues (numeric with range 1-7; 1 - Never, 2 - Less than once a month, 3 Once a month, 4 - Several times a month, 5 - Once a week, 6 - Several times a week, 7 - Every day )
  • sclact: Take part in social activities compared to others of same age (numeric with range 1-5; 1 - Much less than most, 2 - Less than most, 3 - About the same, 4 - More than most, 5 - Much more than most)

source: https://ess.sikt.no/en/datafile/b2b0bf39-176b-4eca-8d26-3c05ea83d2cb/267?tab=1&elements=[%22c3242129-1729-4d8d-bdf3-5919ab59f6a4/2%22]

library(psych)
describe(mydata_AT1_samp [ ,-1])
##         vars   n mean   sd median trimmed  mad min max range  skew kurtosis
## ipcrtiv    1 286 2.53 1.19      2    2.44 1.48   1   6     5  0.57     0.01
## impdiff    2 286 3.11 1.38      3    3.07 1.48   1   6     5  0.24    -0.71
## ipadvnt    3 286 3.92 1.44      4    3.97 1.48   1   6     5 -0.20    -0.88
## ipgdtim    4 286 2.49 1.17      2    2.38 1.48   1   6     5  0.69     0.10
## happy      5 286 7.79 1.58      8    7.91 1.48   3  10     7 -0.71     0.40
## health     6 286 2.01 0.82      2    1.98 1.48   1   4     3  0.28    -0.77
## sclmeet    7 286 4.95 1.25      5    5.05 1.48   1   7     6 -0.59    -0.09
## sclact     8 286 2.87 0.90      3    2.88 1.48   1   5     4 -0.03     0.00
##           se
## ipcrtiv 0.07
## impdiff 0.08
## ipadvnt 0.09
## ipgdtim 0.07
## happy   0.09
## health  0.05
## sclmeet 0.07
## sclact  0.05

Description of the data: the question of importance to think new ideas and being creative has average rating 2.53 which tells us that on average, people sampled in Austria consider themselves creative and able to think of new ideas and overall personal values from first four variables are indicating that Austrians are thinking for themselves more in positive manner related to the question than in negative. For the next four questions which were more about subjective well-being and social exclusion, people on average claimed to be happy and in good health and that on average meet with friends, relatives or colleagues couple times per month. Taking part in social activities compared to others of same age was rated as “less than most” on average.

library(stats)
#install.packages("FactoMineR")
library(FactoMineR)
# Standardize the variables because of the different scales that were used for sampling
standardized_data <- scale(mydata_AT1_samp)
standardized_data_PCA<- standardized_data[ ,-1]
R<- cor(standardized_data_PCA)
round(R, 3)
##         ipcrtiv impdiff ipadvnt ipgdtim  happy health sclmeet sclact
## ipcrtiv   1.000   0.428   0.303   0.270 -0.169  0.343  -0.142 -0.057
## impdiff   0.428   1.000   0.512   0.449  0.025  0.307  -0.158 -0.129
## ipadvnt   0.303   0.512   1.000   0.471  0.014  0.287  -0.115 -0.154
## ipgdtim   0.270   0.449   0.471   1.000 -0.137  0.162  -0.100 -0.017
## happy    -0.169   0.025   0.014  -0.137  1.000 -0.321   0.075  0.094
## health    0.343   0.307   0.287   0.162 -0.321  1.000  -0.178 -0.174
## sclmeet  -0.142  -0.158  -0.115  -0.100  0.075 -0.178   1.000  0.465
## sclact   -0.057  -0.129  -0.154  -0.017  0.094 -0.174   0.465  1.000
library(psych)
cor.plot(R)

On this plot we can see that variables happy and health were not correlated enough with others for our analysis so we decided to remove those variables (correlation between variables should be >= 0.3).

#removing the variable "happy" and "health" since it is not showing good correlation with other variables 
Rnew0 <- mydata_AT1_samp[, -which(names(mydata_AT1_samp) == "happy",)]
Rnew <- Rnew0[, -which(names(Rnew0) == "ID",)]
Rnew1 <- Rnew[, -which(names(Rnew) == "health",)]
str(Rnew1)
## 'data.frame':    286 obs. of  6 variables:
##  $ ipcrtiv: int  2 1 1 3 4 3 3 2 1 1 ...
##  $ impdiff: int  3 3 1 6 4 5 4 2 2 3 ...
##  $ ipadvnt: int  5 2 2 2 6 5 4 2 2 3 ...
##  $ ipgdtim: int  5 2 3 1 5 2 1 1 1 1 ...
##  $ sclmeet: int  5 6 5 5 5 5 5 5 6 6 ...
##  $ sclact : int  4 4 3 2 3 5 3 3 4 3 ...
library(stats)
library(FactoMineR)
#standardizing new set 
standardized_data1 <- scale(Rnew1)
Rnew_stan<- standardized_data1
Rsn<- cor(Rnew_stan)
round(Rsn, 3)
##         ipcrtiv impdiff ipadvnt ipgdtim sclmeet sclact
## ipcrtiv   1.000   0.428   0.303   0.270  -0.142 -0.057
## impdiff   0.428   1.000   0.512   0.449  -0.158 -0.129
## ipadvnt   0.303   0.512   1.000   0.471  -0.115 -0.154
## ipgdtim   0.270   0.449   0.471   1.000  -0.100 -0.017
## sclmeet  -0.142  -0.158  -0.115  -0.100   1.000  0.465
## sclact   -0.057  -0.129  -0.154  -0.017   0.465  1.000
#checking again the correlation plot
library(psych)
cor.plot(Rsn)

Data is better/ more defined in our new plot and we can see the differences between the correlations of social variables and the ones with personal values.

library(psych)
cortest.bartlett(Rsn, n= nrow(Rnew_stan))
## $chisq
## [1] 325.7407
## 
## $p.value
## [1] 2.447541e-60
## 
## $df
## [1] 15

H0: P=I

H1: P not equal to I

Based on data sampled, we reject null hypothesis (p<0,0001) and conclude that at least on correlation coefficient differs from 0.

det(Rsn)
## [1] 0.3152383
library(psych)
KMO(Rsn)
## Kaiser-Meyer-Olkin factor adequacy
## Call: KMO(r = Rsn)
## Overall MSA =  0.69
## MSA for each item = 
## ipcrtiv impdiff ipadvnt ipgdtim sclmeet  sclact 
##    0.77    0.73    0.73    0.74    0.56    0.52

Our data is adequate since the overall MSA is higher than 0.5. Regarding the MSA for each item, we can see that most appropriate on is ipcrtiv and least appropriate is sclact variable (has least in common with others).

library(FactoMineR)
components <- PCA(Rnew1,
                  scale.unit = TRUE,
                  graph = FALSE)
#install.packages("factoextra")
library(factoextra)
## Loading required package: ggplot2
## 
## Attaching package: 'ggplot2'
## The following objects are masked from 'package:psych':
## 
##     %+%, alpha
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
get_eigenvalue(components)
##       eigenvalue variance.percent cumulative.variance.percent
## Dim.1  2.3414894        39.024823                    39.02482
## Dim.2  1.3625766        22.709610                    61.73443
## Dim.3  0.7754276        12.923794                    74.65823
## Dim.4  0.5939467         9.899112                    84.55734
## Dim.5  0.4729608         7.882680                    92.44002
## Dim.6  0.4535988         7.559981                   100.00000

Here we can see the eigenvalue and how the 39% of information of measured variables is transferred to PC1 (dimension1). Using Kaiser’s rule only first two would be retained (>1) and third principal component has variance 0.775 which is to low.

fviz_eig(components,
         choice = "eigenvalue",
         main = "Screeplot",
         ylab = "Eigenvalue",
         xlab = "Principal component",
         addlabels = TRUE)

library(psych)
fa.parallel(Rnew1,
            sim = FALSE,
            fa = "pc")

## Parallel analysis suggests that the number of factors =  NA  and the number of components =  2

Based on the screeplot we can see the biggest break between second and third component which would suggest us to take only the first two. Parallel analysis scree plot confirms that since only first two PC have actual eigenvalue higher than theoretical.

library(FactoMineR)
components<- PCA(Rnew1,
                 ncp = 2,
                 scale.unit = TRUE,
                 graph = FALSE)
components
## **Results for the Principal Component Analysis (PCA)**
## The analysis was performed on 286 individuals, described by 6 variables
## *The results are available in the following objects:
## 
##    name               description                          
## 1  "$eig"             "eigenvalues"                        
## 2  "$var"             "results for the variables"          
## 3  "$var$coord"       "coord. for the variables"           
## 4  "$var$cor"         "correlations variables - dimensions"
## 5  "$var$cos2"        "cos2 for the variables"             
## 6  "$var$contrib"     "contributions of the variables"     
## 7  "$ind"             "results for the individuals"        
## 8  "$ind$coord"       "coord. for the individuals"         
## 9  "$ind$cos2"        "cos2 for the individuals"           
## 10 "$ind$contrib"     "contributions of the individuals"   
## 11 "$call"            "summary statistics"                 
## 12 "$call$centre"     "mean of the variables"              
## 13 "$call$ecart.type" "standard error of the variables"    
## 14 "$call$row.w"      "weights for the individuals"        
## 15 "$call$col.w"      "weights for the variables"
components$var$cor
##              Dim.1     Dim.2
## ipcrtiv  0.6207451 0.1452760
## impdiff  0.7973875 0.1692922
## ipadvnt  0.7592666 0.1712091
## ipgdtim  0.6916062 0.2965180
## sclmeet -0.3920140 0.7515366
## sclact  -0.3344520 0.7942096

Here we can see that our first PC shows the difference social variables and the ones with personal values. Our second principal component explains the general opinions regarding the social and personal questions.

Eigenvalue for the PC1 is the sum of squares of all variables from PC1 and that is: 2.3414894 and for the PC2: 1.3625766.

For the first variable, by summing the squares from both PC1 and PC2 of it we get 0.41 ~ 41% , which means that during the process 59% of information of that variable was lost.

components$var$contrib
##             Dim.1     Dim.2
## ipcrtiv 16.456386  1.548912
## impdiff 27.154803  2.103357
## ipadvnt 24.620470  2.151259
## ipgdtim 20.427988  6.452697
## sclmeet  6.563130 41.451410
## sclact   4.777222 46.292365

Here we can see that first variable contributed only 16.5% to the PC1.

fviz_pca_var(components, repel = TRUE)

Here we can see visual representation of our variables and the clear difference between the social variables and the ones with personal values.

library(factoextra)
fviz_pca_biplot(components)

When we add the observations we can see that for example, person number 118 is bellow average compared to the general opinions and evaluates higher her/his personal values compared to the social activities it takes, while the person number 130 is above average compared to the general opinions and evaluates her/his social activities higher than personal values.

sapply(Rnew1, FUN = mean)
##  ipcrtiv  impdiff  ipadvnt  ipgdtim  sclmeet   sclact 
## 2.531469 3.108392 3.919580 2.486014 4.954545 2.870629
Rnew1[2, ]
##   ipcrtiv impdiff ipadvnt ipgdtim sclmeet sclact
## 2       1       3       2       2       6      4
Rnew1_std<- as.data.frame(scale(Rnew1))
Rnew1_std[2, ]
##     ipcrtiv     impdiff   ipadvnt    ipgdtim   sclmeet   sclact
## 2 -1.287541 -0.07848062 -1.330596 -0.4147022 0.8372133 1.251167
Rnew1$PC1<- components$ind$coord[ , 1]
Rnew1$PC2<- components$ind$coord[ , 2]

head(Rnew1, 3)
##   ipcrtiv impdiff ipadvnt ipgdtim sclmeet sclact        PC1        PC2
## 1       2       3       5       5       5      4  0.8376584  1.4650337
## 2       1       3       2       2       6      4 -1.9021464  0.9197784
## 3       1       1       2       3       5      3 -1.8236614 -0.3450479
cor(x=Rnew1$PC1, y=Rnew1$PC2)
## [1] -2.018171e-16

RQ: Can we identify underlying patterns of personal values and preferences based on these variables?

Results: