# The practical task includes three types of action:
# 1. running a script that is already written for you.
# The script embraces something new or reminds the material.
# I give you an explanation and interpretation of the results.
# 2. answering questions. You should write down each answer.
# 3. writing a script. You should write down own script and
# explanation of the results.
# If there are no errors in the script, you can knit a document,
# and send me doc, Html or pdf file.
# Open the notebook and read about the variables that we work with.
library(foreign)
# setwd ("C:/Users/Desktop")
wvs = read.spss("wvs RU.sav", to.data.frame=TRUE)
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): wvs RU.sav:
## Unrecognized record type 7, subtype 8 encountered in system file
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 0, 2, 3, 4, 9, 10, 11, 12, 25, 27, 28, 29, 30, 32, 33, 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, 67, 68, 69, 70, 71, 72, 73, 74, 75,
## 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
## 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
## 111, 112, 113, 114, 115, 116, 117, 120, 121, 122, 123, 124, 125, 126, 127,
## 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 143, 144,
## 145, 147, 148, 150, 153, 155, 157, 160, 165, 168, 170, 175, 177, 180, 182,
## 200, 205, 210, 211, 215, 217, 220, 222, 224, 225, 230, 232, 233, 235, 236,
## 237, 240, 244, 245, 247, 248, 250, 253, 254, 255, 256, 258, 300, 302, 305,
## 308, 309, 310, 313, 315, 320, 325, 330, 335, 340, 345, 347, 350, 400, 405,
## 408, 410, 420, 422, 425, 430, 435, 436, 440, 445, 450, 505, 515, 520, 536,
## 545, 700, 905, 910, 915, 920, 930, 945, 2345 added in variable: S010
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor S021: Morocco [2001], Spain [1990], Turkey [2001]
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor S021A: Morocco [2001], Spain [1990], Turkey [2001]
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V2: El Salvador
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V2A: El Salvador
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 0, 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, 67, 68, 69, 70, 71, 72, 73, 74, 75,
## 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
## 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110,
## 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
## 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
## 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
## 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
## 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185,
## 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
## 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215,
## 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
## 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
## 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260,
## 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275,
## 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290,
## 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305,
## 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320,
## 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335,
## 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
## 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365,
## 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380,
## 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395,
## 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410,
## 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425,
## 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440,
## 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455,
## 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470,
## 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485,
## 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500,
## 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515,
## 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530,
## 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545,
## 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560,
## 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575,
## 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590,
## 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605,
## 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620,
## 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635,
## 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650,
## 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665,
## 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680,
## 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695,
## 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710,
## 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725,
## 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740,
## 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755,
## 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770,
## 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785,
## 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800,
## 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815,
## 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830,
## 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845,
## 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860,
## 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875,
## 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890,
## 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905,
## 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920,
## 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935,
## 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950,
## 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965,
## 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980,
## 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995,
## 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008,
## 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020,
## 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032,
## 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044,
## 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056,
## 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068,
## 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080,
## 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092,
## 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104,
## 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116,
## 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128,
## 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140,
## 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152,
## 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164,
## 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176,
## 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188,
## 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200,
## 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212,
## 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224,
## 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
## 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248,
## 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260,
## 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272,
## 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284,
## 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296,
## 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308,
## 1309, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320,
## 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332,
## 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344,
## 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356,
## 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368,
## 1369, 1370, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380,
## 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392,
## 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404,
## 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416,
## 1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428,
## 1429, 1430, 1431, 1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440,
## 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1451, 1452,
## 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464,
## 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476,
## 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488,
## 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500,
## 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512,
## 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520, 1521, 1522, 1523, 1524,
## 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1536,
## 1537, 1538, 1539, 1540, 1541, 1542, 1543, 1544, 1545, 1546
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V231: BY: Republican Party of Labour and Justice, CA: Liberal,
## PC, NDP, AL, CZ: Duchodci za zivotnн jistoty (DZJ) - Pensioners’ for a Se,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, CZ: Undocumented,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, HU: undocumented,
## IN: MDMK, MX: Undocumented, MX: Undocumented, NO: Unknown, NO: Unknown,
## NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO:
## Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown,
## PL: Undocumented, SK: Undocumented, SK: Undocumented, SK: Undocumented,
## SK: Undocumented, CH: Undocumented, CH: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented, TR:
## Undocumented, TR: Undocumented, TR: Undocumented
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V232: BY: Republican Party of Labour and Justice, CA: Liberal,
## PC, NDP, AL, CZ: Duchodci za zivotnн jistoty (DZJ) - Pensioners’ for a Se,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, CZ: Undocumented,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, HU: undocumented,
## IN: MDMK, MX: Undocumented, MX: Undocumented, NO: Unknown, NO: Unknown,
## NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO:
## Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown,
## PL: Undocumented, SK: Undocumented, SK: Undocumented, SK: Undocumented,
## SK: Undocumented, CH: Undocumented, CH: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented, TR:
## Undocumented, TR: Undocumented, TR: Undocumented
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V233: BY: Republican Party of Labour and Justice, CA: Liberal,
## PC, NDP, AL, CZ: Duchodci za zivotnн jistoty (DZJ) - Pensioners’ for a Se,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, CZ: Undocumented,
## CZ: Undocumented, CZ: Undocumented, CZ: Undocumented, HU: undocumented,
## IN: MDMK, MX: Undocumented, MX: Undocumented, NO: Unknown, NO: Unknown,
## NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO:
## Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown, NO: Unknown,
## PL: Undocumented, SK: Undocumented, SK: Undocumented, SK: Undocumented,
## SK: Undocumented, CH: Undocumented, CH: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented, TR:
## Undocumented, TR: Undocumented, TR: Undocumented
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 1894, 1895, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905,
## 1906, 1907, 1908, 1909 added in variable: V236
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 15, 16 added in variable: V237
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 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, 44, 45, 50,
## 51, 55, 65 added in variable: V239
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) -99 added in variable: V242
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) -99 added in variable: V250
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V253CS: MT:, MT:, MT: Lm2000, MT:, MT:, MT:
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Undeclared
## level(s) 0 added in variable: V254
## Warning in read.spss("wvs RU.sav", to.data.frame = TRUE): Duplicated levels
## in factor V257: BE: unknown, BE: unknown, BE: unknown, BE: unknown, BE:
## unknown, BE: unknown, BE: unknown, BE: unknown, BE: unknown, BE: unknown,
## BE: unknown, CN: Undocumented, FR: unknown, FR: unknown, FR: unknown, FR:
## unknown, FR: unknown, FR: unknown, FR: unknown, FR: unknown, IE: unknown,
## IE: unknown, IE: unknown, IE: unknown, IE: unknown, IE: unknown, IE:
## unknown, IE: unknown, IE: unknown, IE: unknown, IE: unknown, IE: unknown,
## IE: unknown, IT: unknown, IT: unknown, IT: unknown, IT: unknown, IT:
## unknown, IT: unknown, IT: unknown, IT: unknown, IT: unknown, IT: unknown,
## IT: unknown, ES: unknown, ES: unknown, ES: unknown, ES: unknown, ES:
## unknown, ES: unknown, ES: unknown, ES: unknown, ES: unknown, ES: unknown,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, TR: Undocumented,
## TR: Undocumented, TR: Undocumented, TR: Undocumented, NIR: unknown, NIR:
## unknown, NIR: unknown, NIR: unknown, NIR: unknown, NIR: unknown, NIR:
## unknown
names(wvs)
## [1] "S003" "S004" "S007" "S009" "S010" "S018" "S018a"
## [8] "S019" "S019a" "S021" "S021A" "S024" "S024A" "S025"
## [15] "S025A" "S026" "V1" "V1A" "V1B" "V2" "V2A"
## [22] "V3" "V4" "V5" "V6" "V7" "V8" "V9"
## [29] "V10" "V11" "V12" "V13" "V14" "V15" "V16"
## [36] "V17" "V18" "V19" "V20" "V21" "V22" "V23"
## [43] "V24" "V25" "V26" "V27" "V28" "V29" "V30"
## [50] "V31" "V32" "V33" "V34" "V35" "V36" "V37"
## [57] "V38" "V39" "V40" "V41" "V42" "V43" "V44"
## [64] "V45" "V46" "V47" "V48" "V49" "V50" "V51"
## [71] "V52" "V53" "V54" "V55" "V56" "V57" "V58"
## [78] "V59" "V60" "V61" "V62" "V63" "V64" "V65"
## [85] "V66" "V67" "V68" "V69" "V69HK" "V70" "V70HK"
## [92] "V71" "V72" "V73" "V74HK" "V74" "V73HK" "V75"
## [99] "V76" "V77" "V78" "V79" "V80" "V81" "V82"
## [106] "V83" "V84" "V85" "V86" "V87" "V88" "V89"
## [113] "V90" "V91" "V92" "V93" "V94" "V95" "V96"
## [120] "V97" "V98" "V99" "V100" "V101" "V102" "V103"
## [127] "V104" "V105" "V106" "V107" "V108" "V109" "V110"
## [134] "V111" "V112" "V113" "V114" "V115" "V116" "V117"
## [141] "V118" "V119" "V120" "V121" "V122" "V123" "V124"
## [148] "V125" "V126" "V127" "V128" "V129" "V130" "V131"
## [155] "V132" "V133" "V134" "V135" "V136" "V137" "V138"
## [162] "V139" "V140" "V141" "V142" "V143" "V144" "V145"
## [169] "V146" "V147" "V148" "V149" "V150" "V151" "V152"
## [176] "V153" "V154" "V155" "V156" "V157" "V158" "V159"
## [183] "V160" "V161" "V162" "V163" "V164" "V165" "V166"
## [190] "V167" "V168" "V169" "V170" "V171" "V172" "V173"
## [197] "V174" "V175" "V176" "V177" "V178" "V179" "V180"
## [204] "V181" "V182" "V183" "V184" "V185" "V186" "V187"
## [211] "V188" "V189" "V190" "V191" "V192" "V193" "V194"
## [218] "V195" "V196" "V197" "V198" "V199" "V200" "V201"
## [225] "V202" "V203" "V204" "V205" "V206" "V207" "V208"
## [232] "V209" "V210" "V211" "V212" "V214" "V215" "V216"
## [239] "V217" "V218" "V219" "V220" "V221" "V222" "V223"
## [246] "V224" "V225" "V226" "V227" "V228" "V229" "V230"
## [253] "V231" "V232" "V233" "V233A" "V234" "V235" "V236"
## [260] "V237" "V238" "V239" "V240" "V241" "V242" "V243"
## [267] "V244" "V245" "V246" "V247" "V248" "V249" "V250"
## [274] "V251" "V252" "V252B" "V253" "V253CS" "V254" "V255"
## [281] "V255CS" "V256" "V257" "V258" "V259A" "V259" "V260"
## [288] "number" "country"
# PART 1.
# Preparing the data
# Find the variables.
wvs.ext <- data.frame(wvs$V237, wvs$V55, wvs$V238, wvs$V253,
wvs$V10, wvs$V22, wvs$S009, wvs$V23,
wvs$V46, wvs$V205,
wvs$V4,wvs$V5,wvs$V6,wvs$V7,wvs$V8,wvs$V9)
names (wvs.ext) <- c ("age", "marital", "edu", "income",
"happy", "satisf", "country", "trust",
"choice", "divorce", "Family",
"Friends", "LeisureTime", "Politics",
"Work", "Religion")
# Check the type of variables and RECODE each variable if necessary.
# For example.
class(wvs.ext$satisf)
## [1] "factor"
table(wvs.ext$satisf)
##
## Dissatisfied 2 3 4 5
## 767 427 902 869 2262
## 6 7 8 9 Satisfied
## 1135 1304 1363 621 941
wvs.ext$satisf1 <- ifelse(wvs.ext$satisf=="Satisfied",10,
ifelse(wvs.ext$satisf=="Dissatisfied",1,
wvs.ext$satisf))
table(wvs.ext$satisf, wvs.ext$satisf1)
##
## 1 2 3 4 5 6 7 8 9 10
## Dissatisfied 767 0 0 0 0 0 0 0 0 0
## 2 0 427 0 0 0 0 0 0 0 0
## 3 0 0 902 0 0 0 0 0 0 0
## 4 0 0 0 869 0 0 0 0 0 0
## 5 0 0 0 0 2262 0 0 0 0 0
## 6 0 0 0 0 0 1135 0 0 0 0
## 7 0 0 0 0 0 0 1304 0 0 0
## 8 0 0 0 0 0 0 0 1363 0 0
## 9 0 0 0 0 0 0 0 0 621 0
## Satisfied 0 0 0 0 0 0 0 0 0 941
wvs.ext$satisf <- as.numeric(wvs.ext$satisf)
class(wvs.ext$satisf1)
## [1] "numeric"
## happy
plot(wvs.ext$happy)

wvs.ext$happy0 <- ifelse(wvs.ext$happy=="Not at all happy",1,
ifelse(wvs.ext$happy=="Not very happy",2,
ifelse(wvs.ext$happy=="Quite happy",3,
ifelse(wvs.ext$happy=="Very happy",4, NA))))
table(wvs.ext$happy, wvs.ext$happy0)
##
## 1 2 3 4
## Very happy 0 0 0 1079
## Quite happy 0 0 5516 0
## Not very happy 0 3161 0 0
## Not at all happy 507 0 0 0
class(wvs.ext$happy)
## [1] "factor"
## income
wvs.ext$income1 <- ifelse (wvs.ext$income=="Eigth step",8,
ifelse(wvs.ext$income=="Fifth step",5,
ifelse(wvs.ext$income=="Fourth step",4,
ifelse(wvs.ext$income=="Lower step",1,
ifelse(wvs.ext$income=="Nineth step",9,
ifelse(wvs.ext$income=="second step",2,
ifelse(wvs.ext$income=="Seventh step",7,
ifelse(wvs.ext$income=="Sixth step",6,
ifelse(wvs.ext$income=="Tenth step",10,
ifelse(wvs.ext$income=="Third step",3,NA))))))))))
table(wvs.ext$income, wvs.ext$income1)
##
## 1 2 3 4 5 6 7 8 9 10
## Lower step 413 0 0 0 0 0 0 0 0 0
## second step 0 718 0 0 0 0 0 0 0 0
## Third step 0 0 1363 0 0 0 0 0 0 0
## Fourth step 0 0 0 1225 0 0 0 0 0 0
## Fifth step 0 0 0 0 1301 0 0 0 0 0
## Sixth step 0 0 0 0 0 872 0 0 0 0
## Seventh step 0 0 0 0 0 0 1002 0 0 0
## Eigth step 0 0 0 0 0 0 0 772 0 0
## Nineth step 0 0 0 0 0 0 0 0 512 0
## Tenth step 0 0 0 0 0 0 0 0 0 448
class(wvs.ext$income)
## [1] "factor"
## choice
table(wvs.ext$choice)
##
## None at all 2 3 4 5
## 552 307 531 650 1786
## 6 7 8 9 A great deal
## 894 1021 1175 568 1239
wvs.ext$choice1 <- ifelse (wvs.ext$choice=="None at all",1,
ifelse(wvs.ext$choice=="A great deal",10,
wvs.ext$choice))
wvs.ext$choice <- as.numeric(wvs.ext$choice)
table(wvs.ext$choice1,wvs.ext$choice)
##
## 1 2 3 4 5 6 7 8 9 10
## 1 552 0 0 0 0 0 0 0 0 0
## 2 0 307 0 0 0 0 0 0 0 0
## 3 0 0 531 0 0 0 0 0 0 0
## 4 0 0 0 650 0 0 0 0 0 0
## 5 0 0 0 0 1786 0 0 0 0 0
## 6 0 0 0 0 0 894 0 0 0 0
## 7 0 0 0 0 0 0 1021 0 0 0
## 8 0 0 0 0 0 0 0 1175 0 0
## 9 0 0 0 0 0 0 0 0 568 0
## 10 0 0 0 0 0 0 0 0 0 1239
#edu
table(wvs.ext$edu)
##
## No formal education
## 0
## Incomplete primary school
## 797
## Complete primary school
## 448
## Incomplete secondary school: technical/ vocational type
## 704
## Complete secondary school: technical/ vocational type
## 1981
## Incomplete secondary school: university-preparatory type
## 801
## Complete secondary school: university-preparatory type
## 1285
## Some university-level education, without degree
## 337
## University - level education, with degree
## 1168
wvs.ext$edu1 <- ifelse (wvs.ext$edu=="No formal education",1,
ifelse(wvs.ext$edu=="Incomplete primary school",2,
ifelse(wvs.ext$edu=="Complete primary school",3,
ifelse(wvs.ext$edu=="Incomplete secondary school: technical/ vocational type",4,
ifelse(wvs.ext$edu==" Complete secondary school: technical/ vocational type",5,
ifelse(wvs.ext$edu=="Incomplete secondary school: university-preparatory type",6,
ifelse(wvs.ext$edu=="Complete secondary school: university-preparatory type",7,
ifelse(wvs.ext$edu=="Some university-level education, without degree",8,
ifelse(wvs.ext$edu=="University - level education, with degree",9, NA)))))))))
table(wvs.ext$edu,wvs.ext$edu1)
##
## 2 3 4
## No formal education 0 0 0
## Incomplete primary school 797 0 0
## Complete primary school 0 448 0
## Incomplete secondary school: technical/ vocational type 0 0 704
## Complete secondary school: technical/ vocational type 0 0 0
## Incomplete secondary school: university-preparatory type 0 0 0
## Complete secondary school: university-preparatory type 0 0 0
## Some university-level education, without degree 0 0 0
## University - level education, with degree 0 0 0
##
## 6 7 8
## No formal education 0 0 0
## Incomplete primary school 0 0 0
## Complete primary school 0 0 0
## Incomplete secondary school: technical/ vocational type 0 0 0
## Complete secondary school: technical/ vocational type 0 0 0
## Incomplete secondary school: university-preparatory type 801 0 0
## Complete secondary school: university-preparatory type 0 1285 0
## Some university-level education, without degree 0 0 337
## University - level education, with degree 0 0 0
##
## 9
## No formal education 0
## Incomplete primary school 0
## Complete primary school 0
## Incomplete secondary school: technical/ vocational type 0
## Complete secondary school: technical/ vocational type 0
## Incomplete secondary school: university-preparatory type 0
## Complete secondary school: university-preparatory type 0
## Some university-level education, without degree 0
## University - level education, with degree 1168
class(wvs.ext$edu)
## [1] "factor"
#divorce
table(wvs.ext$divorce)
##
## Never justifiable 2 3
## 3546 413 613
## 4 5 6
## 531 2376 782
## 7 8 9
## 495 515 256
## Always justifiable
## 655
wvs.ext$divorce1 <- ifelse(wvs.ext$divorce=="Always justifiable",10,
ifelse(wvs.ext$divorce=="Never justifiable",1,
wvs.ext$divorce))
table(wvs.ext$divorce, wvs.ext$divorce1)
##
## 1 2 3 4 5 6 7 8 9 10
## Never justifiable 3546 0 0 0 0 0 0 0 0 0
## 2 0 413 0 0 0 0 0 0 0 0
## 3 0 0 613 0 0 0 0 0 0 0
## 4 0 0 0 531 0 0 0 0 0 0
## 5 0 0 0 0 2376 0 0 0 0 0
## 6 0 0 0 0 0 782 0 0 0 0
## 7 0 0 0 0 0 0 495 0 0 0
## 8 0 0 0 0 0 0 0 515 0 0
## 9 0 0 0 0 0 0 0 0 256 0
## Always justifiable 0 0 0 0 0 0 0 0 0 655
wvs.ext$divorce <- as.numeric(wvs.ext$divorce)
class(wvs.ext$divorce1)
## [1] "numeric"
#Family
table(wvs.ext$Family)
##
## Very important Rather important Not very important
## 8090 1130 170
## Not at all important
## 38
plot(wvs.ext$Family)

wvs.ext$Family0 <- ifelse(wvs.ext$Family=="Not at all important",1,
ifelse(wvs.ext$Family=="Not very important",2,
ifelse(wvs.ext$Family=="Rather important",3,
ifelse(wvs.ext$Family=="Very important",4, NA))))
table(wvs.ext$Family, wvs.ext$Family0)
##
## 1 2 3 4
## Very important 0 0 0 8090
## Rather important 0 0 1130 0
## Not very important 0 170 0 0
## Not at all important 38 0 0 0
class(wvs.ext$Family)
## [1] "factor"
#Friends
table(wvs.ext$Friends)
##
## Very important Rather important Not very important
## 2725 4890 1600
## Not at all important
## 201
plot(wvs.ext$Friends)

wvs.ext$Friends0 <- ifelse(wvs.ext$Friends=="Not at all important",1,
ifelse(wvs.ext$Friends=="Not very important",2,
ifelse(wvs.ext$Friends=="Rather important",3,
ifelse(wvs.ext$Friends=="Very important",4, NA))))
table(wvs.ext$Friends, wvs.ext$Friends0)
##
## 1 2 3 4
## Very important 0 0 0 2725
## Rather important 0 0 4890 0
## Not very important 0 1600 0 0
## Not at all important 201 0 0 0
class(wvs.ext$Friends)
## [1] "factor"
#LeisureTime
table(wvs.ext$LeisureTime)
##
## Very important Rather important Not very important
## 2134 4392 2363
## Not at all important
## 412
plot(wvs.ext$LeisureTime)

wvs.ext$LeisureTime0 <- ifelse(wvs.ext$LeisureTime=="Not at all important",1,
ifelse(wvs.ext$LeisureTime=="Not very important",2,
ifelse(wvs.ext$LeisureTime=="Rather important",3,
ifelse(wvs.ext$LeisureTime=="Very important",4, NA))))
table(wvs.ext$LeisureTime, wvs.ext$LeisureTime0)
##
## 1 2 3 4
## Very important 0 0 0 2134
## Rather important 0 0 4392 0
## Not very important 0 2363 0 0
## Not at all important 412 0 0 0
class(wvs.ext$LeisureTime)
## [1] "factor"
#Politics
table(wvs.ext$Politics)
##
## Very important Rather important Not very important
## 1075 2734 3695
## Not at all important
## 1741
plot(wvs.ext$Politics)

wvs.ext$Politics0 <- ifelse(wvs.ext$Politics=="Not at all important",1,
ifelse(wvs.ext$Politics=="Not very important",2,
ifelse(wvs.ext$Politics=="Rather important",3,
ifelse(wvs.ext$Politics=="Very important",4, NA))))
table(wvs.ext$Politics, wvs.ext$Politics0)
##
## 1 2 3 4
## Very important 0 0 0 1075
## Rather important 0 0 2734 0
## Not very important 0 3695 0 0
## Not at all important 1741 0 0 0
class(wvs.ext$Politics)
## [1] "factor"
#Work
table(wvs.ext$Work)
##
## Very important Rather important Not very important
## 5935 2341 749
## Not at all important
## 336
plot(wvs.ext$Work)

wvs.ext$Work0 <- ifelse(wvs.ext$Work=="Not at all important",1,
ifelse(wvs.ext$Work=="Not very important",2,
ifelse(wvs.ext$Work=="Rather important",3,
ifelse(wvs.ext$Work=="Very important",4, NA))))
table(wvs.ext$Work, wvs.ext$Work0)
##
## 1 2 3 4
## Very important 0 0 0 5935
## Rather important 0 0 2341 0
## Not very important 0 749 0 0
## Not at all important 336 0 0 0
class(wvs.ext$Work)
## [1] "factor"
#Religion
table(wvs.ext$Religion)
##
## Very important Rather important Not very important
## 3336 2296 2088
## Not at all important
## 1474
plot(wvs.ext$Religion)

wvs.ext$Religion0 <- ifelse(wvs.ext$Religion=="Not at all important",1,
ifelse(wvs.ext$Religion=="Not very important",2,
ifelse(wvs.ext$Religion=="Rather important",3,
ifelse(wvs.ext$Religion=="Very important",4, NA))))
table(wvs.ext$Religion, wvs.ext$Religion0)
##
## 1 2 3 4
## Very important 0 0 0 3336
## Rather important 0 0 2296 0
## Not very important 0 2088 0 0
## Not at all important 1474 0 0 0
class(wvs.ext$Religion)
## [1] "factor"
#age
wvs.ext$age <- as.numeric(wvs.ext$age)
#trust
table(wvs.ext$trust)
##
## Most people can be trusted CanÒ‘t be too careful
## 2821 7395
wvs.ext$trust1 <- ifelse(wvs.ext$trust=="Most people can be trusted",1,
ifelse(wvs.ext$trust=="CanÒ‘t be too careful",0,
wvs.ext$trust))
table(wvs.ext$trust, wvs.ext$trust1)
##
## 0 1
## Most people can be trusted 0 2821
## CanÒ‘t be too careful 7395 0
class(wvs.ext$trust1)
## [1] "numeric"
#country
table(wvs.ext$country)
##
## RU
## 10781
## Since there is only one country, we will not change it and use it in the model
#marital
table(wvs.ext$marital)
##
## Married
## 6905
## Living together as married
## 179
## Divorced
## 759
## Separated
## 202
## Widowed
## 902
## Single/Never married
## 1774
## Divorced, Separated or Widow
## 0
## Living apart but steady relation (married,cohabitation)
## 0
## We can make 2 groups, namely people who are in relationships and people who are do not.
wvs.ext$marital1 <- ifelse(wvs.ext$marital=="Married",10,
ifelse(wvs.ext$marital=="Living together as married",10,
ifelse(wvs.ext$marital=="Divorced",1,
ifelse(wvs.ext$marital=="Separated",1,
ifelse(wvs.ext$marital=="Widowed",1,
ifelse(wvs.ext$marital=="Single/Never married",1,NA))))))
table(wvs.ext$marital, wvs.ext$marital1)
##
## 1 10
## Married 0 6905
## Living together as married 0 179
## Divorced 759 0
## Separated 202 0
## Widowed 902 0
## Single/Never married 1774 0
## Divorced, Separated or Widow 0 0
## Living apart but steady relation (married,cohabitation) 0 0
class(wvs.ext$marital)
## [1] "factor"
# Creating index of happiness
wvs.ext$happyIND<- rowMeans(wvs.ext[c('happy0','satisf1')], na.rm=T)
summary(wvs.ext$happyIND)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 1.000 3.000 4.000 4.262 5.500 10.000 60
hist(wvs.ext$happyIND)

class(wvs.ext$happyIND)
## [1] "numeric"
# Can you remember what standardization means and why it necessary?
wvs.ext$happyINDscale <- scale (wvs.ext$happyIND)
hist(wvs.ext$happyINDscale)

# "happyINDscale" is the dependent variable.
## Standardizing makes easier to compare values,
## It also makes easier to read results from regression analysis
## Plus it is ensures that all variables contribute to a scale when added together.
## MODELING: relationships between the level of happiness, income, and age
model1 <- lm(wvs.ext$happyINDscale~ as.numeric(wvs.ext$age) +
as.numeric(wvs.ext$income1) + as.numeric(wvs.ext$choice))
summary(model1)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ as.numeric(wvs.ext$age) +
## as.numeric(wvs.ext$income1) + as.numeric(wvs.ext$choice))
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.9537 -0.5839 0.0046 0.5627 4.6403
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8561183 0.0383086 -22.35 <2e-16 ***
## as.numeric(wvs.ext$age) -0.0090692 0.0006403 -14.16 <2e-16 ***
## as.numeric(wvs.ext$income1) 0.0482466 0.0040943 11.78 <2e-16 ***
## as.numeric(wvs.ext$choice) 0.1280611 0.0039149 32.71 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8773 on 7928 degrees of freedom
## (2849 observations deleted due to missingness)
## Multiple R-squared: 0.1816, Adjusted R-squared: 0.1813
## F-statistic: 586.6 on 3 and 7928 DF, p-value: < 2.2e-16
# Interpret the results of regression.
## The intercept is -0.86,means that if age, income1 and choice are egual to 0, the level of happy is egual to -0.86.
## If an income1 changes on 1, the happy variable changes on 0.048;
## If a choice varible changes on 1, the happy variable changes on 0.13;
## If an age varible changes on 1, the happy variable changes on -0.009.
# Do you have outliers and leverage?
plot(model1)



## We have 3 outliers: 4162, 4910, 9356.
### INTERACTION MODELS###
# Ok, the older the person is, the lower the level of happiness is;
# and the richer the person is, the happier he/she is.
# And we can suggest that rich people are happier even in old age.
# Let's test this hypothesis!
wvs.ext$age <- as.numeric(wvs.ext$age)
wvs.ext$income1 <- as.numeric(wvs.ext$income1)
wvs.ext$choice <- as.numeric(wvs.ext$choice)
model2 <- lm(wvs.ext$happyINDscale~ choice + age * income1 ,
data= wvs.ext)
summary(model2)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ choice + age * income1,
## data = wvs.ext)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.9269 -0.5843 0.0024 0.5612 4.6413
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.8167208 0.0534746 -15.273 < 2e-16 ***
## choice 0.1278022 0.0039225 32.581 < 2e-16 ***
## age -0.0104389 0.0014465 -7.217 5.82e-13 ***
## income1 0.0407445 0.0081998 4.969 6.87e-07 ***
## age:income1 0.0002793 0.0002645 1.056 0.291
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8772 on 7927 degrees of freedom
## (2849 observations deleted due to missingness)
## Multiple R-squared: 0.1818, Adjusted R-squared: 0.1813
## F-statistic: 440.2 on 4 and 7927 DF, p-value: < 2.2e-16
library(sjPlot)

# browseVignettes("sjPlot")
plot_model(model2, type = "int")

# The interactive effect is insignificant,
# which means that with age the level of happiness decreases
# equally for both the poor and the rich.
# What about the choice? If older people feel
# they have completely free choice and control over their lives,
# are they happier than those who think "no choice at all"?
model3 <- lm(wvs.ext$happyINDscale~ age * choice + income1 ,
data= wvs.ext)
summary(model3)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ age * choice + income1,
## data = wvs.ext)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8555 -0.5720 -0.0009 0.5641 4.6403
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.6454136 0.0570204 -11.319 < 2e-16 ***
## age -0.0158706 0.0015073 -10.529 < 2e-16 ***
## choice 0.0943615 0.0078117 12.080 < 2e-16 ***
## income1 0.0472345 0.0040932 11.540 < 2e-16 ***
## age:choice 0.0011569 0.0002322 4.983 6.4e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8759 on 7927 degrees of freedom
## (2849 observations deleted due to missingness)
## Multiple R-squared: 0.1842, Adjusted R-squared: 0.1838
## F-statistic: 447.5 on 4 and 7927 DF, p-value: < 2.2e-16
plot_model(model3, type = "int")

# Please interpret the result.
## The interactive effect is significant.
## We see how the two lines differ, which points us to the confirmation of the hypothesis.
## With age, people who have a choice are happier than those
## who believe they don't have a choice.
# Now select one or two variables (from "wvs.ext" dataset),
# add interactive effect in model2,
# build a plot and interpret a new result.
wvs.ext$age <- as.numeric(wvs.ext$age)
wvs.ext$trust1 <- as.numeric(wvs.ext$trust1)
wvs.ext$satisf1 <- as.numeric(wvs.ext$satisf1)
wvs.ext$Family0 <- as.numeric(wvs.ext$Family0)
wvs.ext$marital1 <- as.numeric(wvs.ext$marital1)
model4 <- lm(wvs.ext$happyINDscale~ as.numeric(wvs.ext$age) +
as.numeric(wvs.ext$satisf1) + as.numeric(wvs.ext$Family0))
summary(model4)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ as.numeric(wvs.ext$age) +
## as.numeric(wvs.ext$satisf1) + as.numeric(wvs.ext$Family0))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83874 -0.14880 -0.01463 0.11122 2.25284
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.2145500 0.0251821 -87.942 < 2e-16 ***
## as.numeric(wvs.ext$age) -0.0023145 0.0001769 -13.087 < 2e-16 ***
## as.numeric(wvs.ext$satisf1) 0.3744924 0.0011276 332.122 < 2e-16 ***
## as.numeric(wvs.ext$Family0) 0.0339059 0.0061979 5.471 4.6e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2636 on 9288 degrees of freedom
## (1489 observations deleted due to missingness)
## Multiple R-squared: 0.9267, Adjusted R-squared: 0.9266
## F-statistic: 3.912e+04 on 3 and 9288 DF, p-value: < 2.2e-16
## The intercept is -2.21,means that if age, satisf1 and Family0 are egual to 0, the level of happy is egual to -2.21.
## If an age changes on 1, the variable happy changes on -0,002;
## If a satisf1 varible changes on 1, the happy variable changes on 0.38;
## If an Family0 varible changes on 1, the happy variable changes on 0.03.
## Hypothesis: if older people think that family is very important to them in life,
## are they happier than those older people who think that family is not important in life?
model5 <- lm(wvs.ext$happyINDscale~ satisf1 + age * Family0 ,
data= wvs.ext)
summary(model5)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ satisf1 + age * Family0,
## data = wvs.ext)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83597 -0.14877 -0.01522 0.11148 2.26986
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.1360318 0.0473611 -45.101 < 2e-16 ***
## satisf1 0.3744586 0.0011275 332.103 < 2e-16 ***
## age -0.0047269 0.0012451 -3.796 0.000148 ***
## Family0 0.0132933 0.0122187 1.088 0.276648
## age:Family0 0.0006406 0.0003273 1.957 0.050333 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2636 on 9287 degrees of freedom
## (1489 observations deleted due to missingness)
## Multiple R-squared: 0.9267, Adjusted R-squared: 0.9267
## F-statistic: 2.935e+04 on 4 and 9287 DF, p-value: < 2.2e-16
plot_model(model5, type = "int")

##We see that with age, the closer and more important a family for a person,
## the happier they are comparing to older people who do not think a family is important.
## OR another variant
model6 <- lm(wvs.ext$happyINDscale~ as.numeric(wvs.ext$age) +
as.numeric(wvs.ext$satisf1) + as.numeric(wvs.ext$marital1))
summary(model6)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ as.numeric(wvs.ext$age) +
## as.numeric(wvs.ext$satisf1) + as.numeric(wvs.ext$marital1))
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.84139 -0.16090 -0.02608 0.10268 2.25360
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.1353558 0.0100012 -213.51 <2e-16 ***
## as.numeric(wvs.ext$age) -0.0023389 0.0001807 -12.94 <2e-16 ***
## as.numeric(wvs.ext$satisf1) 0.3761502 0.0011581 324.80 <2e-16 ***
## as.numeric(wvs.ext$marital1) 0.0068477 0.0006748 10.15 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2929 on 10514 degrees of freedom
## (263 observations deleted due to missingness)
## Multiple R-squared: 0.9137, Adjusted R-squared: 0.9137
## F-statistic: 3.71e+04 on 3 and 10514 DF, p-value: < 2.2e-16
## The intercept is -2.14,means that if age, satisf1 and marital1 are egual to 0, the level of happy is egual to -2.14.
## If an age changes on 1, the variable happy changes on -0,002;
## If a satisf1 varible changes on 1, the happy variable changes on 0.38;
## If an marital1 varible changes on 1, the happy variable changes on 0.006.
## Hypothesis: Older people who have relationships,
## are happier than those older people who are single.
model7 <- lm(wvs.ext$happyINDscale~ satisf1 + age * marital1 ,
data= wvs.ext)
summary(model7)
##
## Call:
## lm(formula = wvs.ext$happyINDscale ~ satisf1 + age * marital1,
## data = wvs.ext)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.83448 -0.15885 -0.02953 0.10225 2.28667
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -2.109e+00 1.171e-02 -180.073 < 2e-16 ***
## satisf1 3.758e-01 1.159e-03 324.130 < 2e-16 ***
## age -3.277e-03 2.795e-04 -11.723 < 2e-16 ***
## marital1 2.098e-03 1.274e-03 1.647 0.0995 .
## age:marital1 1.748e-04 3.978e-05 4.395 1.12e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2927 on 10513 degrees of freedom
## (263 observations deleted due to missingness)
## Multiple R-squared: 0.9139, Adjusted R-squared: 0.9138
## F-statistic: 2.788e+04 on 4 and 10513 DF, p-value: < 2.2e-16
plot_model(model7, type = "int")

##We see that with age, people who are married/live together with a partner,
## are happier comparing to older people who do not have a parther.