QuikStart R

From InterSciWiki
Jump to: navigation, search

R operators

R operators

Some reference material

Reference Card for R [1] Missing data in R [2] R cheat sheet [3] Data frame columns [4] Handling Text [5] Sample Session in R Sample session R base functions

What all of you need to do in using this page is to add what you find works, add new double-bracketed topics for topics you are exploring and put you findings theres, also add useful reference page. Build it up as an instructional and results and questions page.--Doug 20:19, 28 June 2007 (PDT)

After installation

Once R is installed (Default R packages)



updating HTML package listing V.1.6 V.2.5
updating HTML search index V.2.5
If nothing happens, you should open 'C:\PROGRA~1\R\R-22~1.0\doc\html\rwin.html' yourself

or open: http://eclectic.ss.uci.edu/~drwhite/R/doc/rwin.html go get all this help, Doug dated 07:43, 2 July 2007 (PDT)


Lists objects in the R workspace

Comparative research R tutorial

Final crosstab instructions

New instructions, Go to: R CrossTab, gmodels package -- (replaces also Using R for cross-cultural Research)

This module is for Comparative research tools, go there to for other options


Obsolete section (inspired the final crosstab instructions)

Reason for obsolescence is that the update Spss *.sav 15.0 file used here cannot be read directly into R, but had to be converted into a *.dta (Stata) format, but it no longer contains text in the format used by Dow. It took about 4 hours to figure out how to do the data conversion, which then also gives more options for cross-tabs. We can now update the Spss file, convert to Stata SE, and grow the cumulative SCCS file.

James W.Dow 2004 Using R for cross-cultural Research World Cultures 14(2):144-154.

Using R for cross-cultural Research

This module is for Comparative research tools, go there to for other options

Right click to download data and R routines download, all in the same R folder: named sccs.RData (data and R programs).

Once sccs.RData is downloaded to your directory, JUST DOUBLE CLICK ON sccs.RData to start R (the file has programs and data).

To see R objects and library programs type:

> ls()

"find.cname" "sccs" "scpl" "scrc" "scxt" "vlabel"

> library()

For a James Dow crosstab (are some of these --Dow's R-- commands from an earlier R version or need to be rewritten in later R version?):

> scxt ("V891", "V892") # Produces output

"V891 Frequency of Internal War"

"V892 Frequency of External War - Attacking"

 ContentsV891  Infrequent Frequent Continual
 Infrequent         40       27        17
 Frequent           17       21         7
 Continual           3        8         6

Number of cases in table: 146 Number of factors: 2 Test for independence of all factors:

       Chisq = 7.605, df = 4, p-value = 0.1072
       Chi-squared approximation may be incorrect
[1] Cramers V is      0.161383604703659

The advantage of this routine by James Dow is that it puts the labels in the Spss file together with the frequencies.

Further conversion Spss *.sav to *.dbf DOES NOT WORK

DOES NOT WORK On Sunday 11 October 2009 08:42:01 pm scott w wrote:

I don't know. CC'ing my friend Philipp who has been studying R lately to
see if he knows. Philipp, if you have time to take a look, any ideas?
On Sun, Oct 11, 2009 at 9:09 AM, <drwhite@uci.edu:wrote:
If you know R and I have an Spss.sav file "xxx.sav" what R commands would
I use to call and run the R program at
to convert my Spss.sav file to *.dbf.
any clue?

If the ConvertData.R file is in the current directory, then you should simply be able to: 1) start R 2) issue the command "source( 'ConvertData.R' )"

       at the R prompt to load the file

3) call the function "convertData()" at the R prompt

However, when I do that, it loads the file just fine, but when I try to run the function, R complains about

       Error in convertData() : object "functionsftIndex" not found

I have not tried to trace down where this error comes from.

More advanced statistics

For more advanced statistics we need to read in a new Spss file, SCCSvar1-2008Map.sav, which you can download from http://eclectic.ss.uci.edu/~drwhite/sccs/SCCSvar1-2008Map.sav

copy it to the file where the program resides and then to use read.spss type

> library(foreign)

sccs<-read.spss("SCCSvar1-2008Map.sav")      @or, better yet:

(Doesnt work for R1.6 but does work for R2.5 where sccs=SCCSvar1-2008Map.sav works too)


       The following object(s) are masked from sccs ( position 3 ) :
        ACHIEVEM AGGRESSI AGRICS_A AGRICSYS BUDDHIST CHRISTIA COMPETIV COMPLEX EXTERN_A EXTERN_B EXTERNAL EXTWARFA FACT_1 FACT_2 FACT_3 FACT_4 FACT_5 FACT_6 FACT_7 FACT_8 FEMALE_A FEMALEPO FOCYEAR FORTITUD FRATIN_A FRATINTG GAMESO_A GAMESOFC GAMESOFS HINDU HINDUBUD ID66 INDUSTRY INTERR_A INTERRNA INTWARFA ISLAM LATITUDE LONGITUD MALEAG_A MALEAGGR MODERN_A MODERNIZ NAME NOMAFROE NOMEUR_A NOMEURAS NOMNEWWO NOMOLDWO NUMBER OBEDIENC OUTLINEF OWC POLITI_A POLITICA RESPONSI SCCS SCCS# SCCSNUM SELFRELY SELFREST SEXRESTR SHAMAN2 SOCIETY SOCNAME STATEHOO TOTSEXLA V0_STATE V1 V10 V100 V1000 V1001 V1002 V1003 V1004 V1005 V1006 V1007 V1008 V1009 V101 V1010 V1011 V1012 V1013 V1014 V1015 V1016 V1017 V1018 V1019 V102 V1020 V1021 V1022 V1023 V1025 V1026 V1027 V1028 V1029 V103 V1030 V1031 V1032 V1033 V1034 V1035 V1036 V1037 V1038 V1039 V104 V1040 V1042 V1043 V1044 V1045 V1046 V1047 V1048 V1049 V105 V1050 V1051 V1052 V1053 V1054 V1055 V1056 V1057 V1058 V1059 V106 V1060 V1061 V1062 V1063 V1064 V1065 V1066 V107 V1072 V1073 V1074 V1075 V1076 V1077 V1078 V1079 V108 V1080 V1081 V1082 V1083 V1084 V1085 V1086 V1087 V1088 V1089 V109 V1090 V1091 V1092 V1093 V1094 V1095 V1096 V1097 V11 V110 V1100 V1101 V1102 V1103 V1104 V1105 V1106 V1107 V1108 V111 V1110 V1111 V1112 V1116 V1117 V1118 V1119 V112 V1120 V1121 V1122 V1123 V1124 V1125 V1126 V1127 V1128 V1129 V113 V1130 V1131 V1132 V1133 V1134 V1135 V1136 V1137 V1138 V1139 V114 V1140 V1141 V1142 V1143 V1144 V1145 V1146 V1147 V1148 V1149 V115 V1150 V1151 V1152 V1153 V1154 V1155 V1156 V1157 V1158 V1159 V116 V1160 V1161 V1162 V1163 V1164 V1165 V1166 V1167 V1168 V1169 V117 V1170 V1171 V1172 V1173 V1174 V1175 V1176 V1177 V1178 V118 V1188 V1189 V119 V1190 V1191 V1192 V1193 V1194 V1195 V1196 V1197 V1198 V1199 V12 V120 V1200 V1201 V1202 V1203 V1204 V1205 V1206 V1207 V1208 V1209 V121 V1210 V1211 V1212 V1213 V1214 V1215 V1216 V1217 V1218 V1219 V122 V1220 V1221 V1222 V1223 V1224 V1225 V1226 V1227 V1228 V1229 V123 V1230 V1231 V1232 V1233 V1234 V1235 V1236 V1237 V124 V1248 V1249 V125 V1250 V1251 V1253 V1254 V1255 V1256 V1257 V1258 V1259 V126 V1260 V1261 V1262 V1263 V1264 V1265 V1266 V1267 V1268 V1269 V127 V1270 V1271 V1272 V1273 V1274 V1275 V1276 V1277 V1278 V1279 V128 V1280 V1281 V1282 V1283 V1284 V1285 V1286 V1287 V1288 V1289 V129 V1290 V1291 V1292 V1293 V1294 V1295 V1296 V1297 V1298 V1299 V13 V130 V1300 V1301 V1302 V1303 V1304 V1305 V1306 V1307 V1308 V1309 V131 V1310 V1311 V1312 V1313 V1314 V1315 V1316 V1317 V1318 V1319 V132 V1320 V1321 V1322 V1323 V1324 V1325 V1326 V1327 V1328 V1329 V133 V1330 V1331 V1332 V1333 V1334 V1335 V1336 V1337 V1338 V1339 V134 V1340 V1341 V1342 V1343 V1344 V1345 V1346 V1347 V1348 V1349 V135 V1350 V1351 V1352 V1353 V1354 V1355 V1356 V1357 V1358 V1359 V136 V1360 V1361 V1362 V1363 V1364 V1365 V1366 V1367 V1368 V1369 V137 V1370 V1371 V1372 V1373 V1374 V1375 V1376 V1377 V1378 V1379 V138 V1380 V1381 V1382 V1383 V1384 V1385 V1386 V1387 V1388 V1389 V139 V1390 V1391 V1392 V1393 V1394 V1395 V1396 V1397 V1398 V1399 V14 V140 V1400 V1401 V1402 V1403 V1404 V1405 V1406 V1407 V1408 V1409 V141 V1410 V1411 V1412 V1413 V1414 V1415 V1416 V1417 V1418 V1419 V142 V1420 V1421 V1422 V1423 V1424 V1425 V1426 V1427 V1428 V1429 V143 V1430 V1431 V1432 V1433 V1434 V1435 V1436 V1437 V1438 V1439 V144 V1440 V1441 V1442 V1443 V1444 V1445 V1446 V1447 V1448 V1449 V145 V1450 V1451 V1452 V1453 V1454 V1455 V1456 V1457 V1458 V1459 V146 V1460 V1461 V1462 V1463 V1464 V1465 V1466 V1467 V1468 V1469 V147 V1470 V1471 V1472 V1473 V1474 V1475 V1476 V1477 V1478 V1479 V148 V1480 V1481 V1482 V1483 V1484 V1485 V1486 V1487 V1488 V1489 V149 V1490 V1491 V1492 V1493 V1494 V1495 V1496 V1497 V1498 V1499 V15 V150 V1500 V1501 V1502 V1503 V1504 V1505 V1506 V1507 V1508 V1509 V151 V1510 V1511 V1512 V1513 V1514 V1515 V1516 V1517 V1518 V1519 V152 V1520 V1521 V1522 V1523 V1524 V1525 V1526 V1527 V1528 V1529 V153 V1530 V1531 V1532 V1533 V1534 V1535 V1536 V1537 V1538 V1539 V154 V1540 V1541 V1542 V1543 V1544 V1545 V1546 V1547 V1548 V1549 V155 V1550 V1551 V1552 V1553 V1554 V1555 V1556 V1557 V156 V157 V158 V158.1MO V159 V159_177 V1592 V1593 V1594 V1595 V1596 V1597 V1598 V1599 V16 V160 V1600 V1601 V1602 V1603 V1604 V1605 V1606 V1607 V1608 V1609 V161 V1610 V1611 V1612 V1613 V1614 V1615 V1616 V1617 V1618 V1619 V162 V1620 V1621 V1622 V1623 V1624 V1625 V1626 V1627 V1628 V1629 V163 V1630 V1631 V1632 V1633 V1634 V1635 V1636 V1637 V1638 V1639 V164 V1640 V1641 V1642 V1643 V1644 V1645 V1646 V1647 V1648 V1649 V165 V1650 V1651 V1652 V1653 V1654 V1655 V1656 V1657 V1658 V1659 V166 V1660 V1661 V1662 V1663 V1664 V1665 V1666 V1667 V1668 V1669 V167 V1670 V1671 V1672 V1673 V1674 V1675 V1676 V1677 V1678 V1679 V168 V1680 V1681 V1682 V1683 V1684 V1685 V1686 V1687 V1688 V1689 V169 V1691 V1692 V1693 V1694 V1695 V1696 V1697 V1698 V1699 V17 V170 V1700 V1701 V1702 V1703 V1704 V1705 V1706 V1707 V1708 V1709 V171 V1710 V1711 V1712 V1713 V1714 V1715 V1716 V1717 V1718 V1719 V172 V1720 V1721 V1722 V1723 V1724 V1725 V1726 V1727 V1728 V1729 V173 V1730 V1731 V1732 V1733 V1734 V1735 V1736 V1737 V1738 V1739 V174 V1740 V1741 V1742 V1743 V1744 V1745 V1746 V1747 V1748 V1749 V175 V1750 V1751 V1752 V1753 V1754 V1755 V1756 V1757 V1758 V1759 V176 V1760 V1761 V1762 V1763 V1764 V1765 V1766 V1767 V1768 V1769 V177 V1770 V1771 V1772 V1773 V1774 V1775 V1776 V1777 V1778 V1779 V178 V1780 V1781 V1782 V1783 V1784 V1785 V1786 V1787 V1788 V1789 V179 V1790 V1791 V1792 V1793 V1794 V1795 V1796 V1797 V1798 V1799 V18 V180 V1800 V1801 V1802 V1803 V1804 V1805 V1806TRA V1807TRA V1808TRA V1809TEC V181 V1810TEC V1811TEC V1812AGR V1813AGR V1814AGR V1815TRA V1816TRA V1817TRA V1818GOV V1819GOV V182 V1820GOV V1821GOV V1822FAM V1823FAM V1824FAM V1825FAM V1826TOL V1827TOL V1828BEH V1829BEH V183 V1830EDU V1831EDU V1832EDU V1833HEA V1834HEA V1835HEA V1836REL V1837REL V1838REL V1839SUM V184 V1840SUM V1841SUM V1842SUM V1843S_A V1843SUM V1844SUM V1845SUM V1846SUM V1847SUM V1848SUM V1849SUM V185 V1850 V1851 V1852 V1853 V1854 V1855 V1856 V1857 V1858 V1859 V186 V1860 V1861 V1862 V1863 V1864 V1865 V1866 V1867 V1868 V1869 V187 V1870 V1871 V1872 V1874 V1875 V1876 V1877 V1878 V188 V1880 V1882 V1884 V1886 V1888 V1889 V189 V1890 V1891 V1892 V1893 V1894 V1895 V1896 V1897 V1898 V1899 V19 V19_22 V190 V1900 V1901 V1902 V1903 V1905 V1907 V1908 V1909 V191 V1910 V1911 V1912 V1913 V1914 V1915 V1916 V1917 V192 V193 V194 V195 V196 V197 V198 V199 V2 V20 V200 V2001_18 V2002_18 V201 V202 V203 V204 V205 V206 V207 V208 V209 V21 V210 V211 V212 V213 V214 V215 V216 V217 V218 V219 V22 V220 V221 V222 V223 V224 V225 V226 V227 V228 V229 V23 V230 V231 V232 V233 V234 V235 V236 V237 V238 V239 V24 V24_25 V240 V241 V242 V243 V244 V245 V246 V247 V248 V249 V25 V250 V251 V252 V253 V254 V255 V256 V257 V258 V259 V26 V26_27 V260 V261 V262 V263 V264 V265 V266 V267 V268 V269 V27 V270 V271 V272 V273 V274 V275 V276 V277 V278 V279 V28 V280 V281 V282 V283 V284 V285 V286 V287 V288 V289 V29 V290 V291 V292 V293 V294 V295 V296 V297 V298 V299 V3 V30 V300 V301 V302 V303 V304 V305 V306 V307 V308 V309 V31 V310 V311 V312 V313 V314 V315 V316 V317 V318 V319 V32 V320 V321 V322 V323 V324 V325 V326 V327 V328 V329 V33 V330 V331 V332 V333 V334 V335 V336 V337 V338 V339 V34 V340 V341 V342 V343 V344 V345 V346 V347 V348 V349 V35 V350 V351 V352 V353 V354 V355 V356 V357 V358 V359 V36 V360 V361 V362 V363 V364 V365 V366 V367 V368 V369 V37 V370 V371 V372 V373 V374 V375 V376 V377 V378 V379 V38 V380 V381 V382 V383 V384 V385 V386 V387 V388 V389 V39 V390 V391 V392 V393 V394 V395 V396 V397 V398 V399 V4 V40 V400 V401 V402 V403 V404 V405 V406 V407 V408 V409 V41 V410 V411 V412 V413 V414 V415 V416 V417 V418 V419 V42 V420 V421 V422 V423 V424 V425 V426 V427 V428 V429 V43 V430 V431 V432 V433 V434 V435 V436 V437 V438 V439 V44 V440 V441 V442 V443 V444 V445 V446 V447 V448 V449 V45 V450 V451 V452 V453 V454 V455 V456 V457 V458 V459 V46 V460 V461 V462 V463 V464 V465 V466 V467 V468 V469 V47 V470 V471 V472 V473 V474 V475 V476 V477 V478 V479 V48 V480 V481 V482 V483 V484 V485 V486 V487 V488 V489 V49 V490 V491 V492 V493 V494 V495 V496 V497 V498 V499 V5 V50 V500 V501 V502 V503 V504 V505 V506 V507 V508 V509 V51 V510 V511 V512 V513 V514 V515 V516 V517 V518 V519 V52 V520 V521 V522 V523 V524 V525 V526 V527 V528 V529 V53 V53_54 V530 V531 V532 V533 V534 V535 V536 V537 V538 V539 V54 V540 V541 V542 V543 V544 V545 V546 V547 V548 V549 V55 V550 V551 V552 V553 V554 V555 V556 V557 V558 V559 V56 V560 V561 V562 V563 V564 V565 V566 V567 V568 V569 V57 V570 V571 V572 V573 V574 V575 V576 V577 V578 V579 V58 V580 V581 V582 V583 V584 V585 V586 V587 V588 V589 V59 V590 V591 V592 V593 V594 V595 V596 V597 V598 V599 V6 V60 V600 V601 V602 V603 V604 V605 V606 V607 V608 V609 V61 V610 V611 V612 V613 V614 V615 V616 V617 V618 V619 V62 V620 V621 V622 V623 V624 V625 V626 V627 V628 V629 V63 V630 V631 V632 V633 V634 V635 V636 V637 V638 V639 V64 V640 V641 V642 V643 V644 V645 V646 V647 V648 V649 V65 V650 V651 V652 V653 V654 V655 V656 V657 V658 V659 V66 V660 V661 V662 V663 V664 V665 V666 V667 V668 V669 V67 V670 V671 V672 V673 V674 V675 V676 V677 V678 V679 V68 V680 V681 V682 V683 V684 V685 V686 V687 V688 V689 V69 V690 V691 V692 V693 V694 V695 V696 V697 V698 V699 V7 V70 V700 V701 V702 V703 V704 V705 V706 V707 V708 V709 V71 V710 V711 V712 V713 V713REV V714 V715 V716 V717 V718 V719 V72 V720 V721 V722 V723 V724 V725 V726 V727 V728 V729 V73 V730 V731 V732 V733 V734 V735 V736 V737 V738 V739 V74 V740 V741 V742 V743 V744 V745 V746 V747 V748 V749 V75 V750 V751 V752 V753 V754 V755 V756 V757 V758 V759 V76 V760 V761 V762 V763 V764 V765 V766 V767 V768 V769 V77 V770 V771 V772 V773 V774 V775 V776 V777 V778 V779 V78 V780 V781 V782 V783 V784 V785 V786 V787 V788 V789 V79 V790 V791 V792 V793 V794 V795 V796 V797 V798 V799 V8 V80 V800 V801 V802 V803 V804 V805 V806 V807 V808 V809 V81 V810 V811 V812 V813 V814 V815 V816 V817 V818 V819 V82 V820 V821 V822 V823 V824 V825 V826 V827 V828 V829 V83 V830 V831 V832 V833 V833.1 V833.2 V834 V835 V836 V837 V838 V84 V840 V841 V842 V843 V844 V85 V854 V855 V856 V857 V858 V859 V859.1 V86 V860 V861 V862 V863 V864 V865 V866 V867 V868 V869 V87 V870 V871 V872 V873 V874 V875 V876 V877 V878 V879 V88 V880 V881 V882 V883 V884 V885 V886 V887 V888 V889 V89 V890 V891 V892 V893 V894 V895 V896 V897 V898 V899 V9 V90 V900 V901 V902 V903 V904 V905 V906 V907 V908 V909 V91 V910 V911 V912 V913 V914 V915 V916 V917 V918 V919 V92 V920 V921 V922 V923 V924 V925 V926 V927 V928 V929 V93 V930 V931 V932 V933 V934 V935 V936 V937 V938 V939 V94 V940 V941 V942 V943 V944 V945 V946 V947 V948 V949 V95 V950 V951 V952 V953 V954 V955 V956 V957 V958 V959 V96 V960 V961 V962 V963 V964 V965 V966 V967 V968 V969 V97 V970 V971 V972 V973 V974 V975 V976 V977 V978 V979 V98 V980 V981 V982 V983 V984 V985 V986 V987 V988 V989 V99 V990 V991 V992 V993 V994 V995 V996 V997 V998 V999 VA875

Those excluded labels don't mean you can't use them, e.g., now to do plots:


> load(graphics)



> library(stats)


Up to here the functions have handled missing data. But R as open source (thats why its free) has advanced routies that dont want to bother with this and they want you to preprocess. e.g., if you have columns or matrices,

> cols<-na.exclude(data.frame(V891,V892,V893))

puts the data in a frame and omits na=missing data (see[2])





note now that


x1   1  2  3
  1  6  8  3
  2  7 21 17
  3 17 27 40

> plot(x1,y)

Correlation and Regression

but these are alphanumeric variables, so convert them to numeric

 [1] 0.1593972

Now regress y on x1 and x2 (independent)

fit<-lm(y ~ x1+x2)


lm(formula = y ~ x1+x2)
(Intercept)          x1           x2  
   0.55990      0.06098      0.67005  

> summary(fit)

lm(formula = y ~ x1 + x2)
     Min       1Q   Median       3Q      Max 
-1.75298 -0.35190  0.03902  0.26226  1.03902 
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.55990    0.23334   2.399   0.0178 *  
x1           0.06098    0.07292   0.836   0.4045    
x2           0.67005    0.07024   9.539   <2e-16 ***
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
Residual standard error: 0.5892 on 133 degrees of freedom
Multiple R-Squared: 0.4142,     Adjusted R-squared: 0.4054 
F-statistic: 47.02 on 2 and 133 DF,  p-value: 3.584e-16

There is no causal test here but predicting V892 External war (attacking) it is V893 "being attacked" that is the significant independent variable, not V891 "internal war" as argued by "propensity to war" theorists such as Marc Ross.

Regression with autocorrelation

The problem of nonindependence of cases was first known in the social sciences and extensively discussed as Galton's problem. Without statistical solutions for this problem, statistical inferences from all forms of survey research are suspect. Anthon Eff and Doug White have developed a tutorial for Regression with autocorrelation using R and SCCS data.

Factor Analysis

Missing data in R might provide help with pairwise correlation as input to factor analysis. There are options here for categorical variables but also for matrices of normally distributed (interval) variables, etcetera. Probabilistic methods are used to get error bounds on the missing data estimates. This can help to expand the sample size and allow full use of your cases that have one or more missing values in the data matrix.

Final factor analysis instructions

GO TO: External war factor analysis with SCCS - using the *.dta SCCS file

FOR HELP! Here is a link to a 2-page document entitled "A Non Mathematical Explanation of Factor Analysis": [6] Another helpful link (that's much more in-depth) comes from a psychology professor at Cornell University: [7]

Obsolete section (inspired the final crosstab instructions)


Right click to download data and R routines download, all in the same R folder: named sccs.RData (data and R programs): then click on your hard drive.

Review Factor analysis in R as part of this exercise and the - External War variable lists for factors.

The earlier functions in this page have handled missing data using James Dow's commands. Here we use open source advanced routines in R that don't want to bother with such intricate handling of test. These routines want you to preprocess the data to obtain numeric columns or data matrices, with "na.exclude" to exclude missing data.

We start with alphanumeric variables, found in the <SCCS variable codebook> and the first task after selecting variables e.g. from this list will be to convert them to numeric.

SCCS factors for analytic study]

  5. V895 DECISION TO ENGAGE IN WAR N=134 p=.001
  1. V896 COMMENCEMENT OF WAR N=113 p=.24
  2. V897 CONCLUSION OF WAR N=113 p=.27
  4. V774 (Low)R External Warfare
  5. V783 //Un//Acceptability of violence toward people in other societies
  6. V780 Hostility toward other societies
  7. V775+ Compliance of individuals w/ community norms (see SCCS_test_of_hypotheses#Sample_table for a very interesting cross-tabulation result for this variable with external war)
  1. sccs<-read.spss(source("http://intersci.ss.uci.edu/wiki/pub/SCCSvar1-2008Map.sav")) #OUGHT TO WORK BUT DOESNT
  2. sccs<-read.spss("sccs_R/SCCSvar1-2008Map.sav") #OUGHT TO WORK BUT DOESNT
  3. library(foreign)
  4. sccs<-read.spss("SCCSvar1-2008NoMap.sav") #New test
  5. RINNER Heinrich http://r-help.com/msg/53107.html says the problem is Spss 15.0 see http://wiki.math.yorku.ca/index.php/R:_Data_conversion_from_SPSS -- sccs<-spss.get("SCCSvar1-2008NoMap.sav") Still errors
#sccs<-read.spss("SCCSvar1-2008Map.sav")                                              #OUGHT TO WORK BUT DOESNT
cols<-na.exclude(data.frame(V891,V892,V893,V894,V897)) #categorical 

The goal is to try to find some combination of variables -- initially categorical -- put them in a data frame with cases excluded with any missing data, then define variables x1-x6 as numeric variables, then bind these together into a matrix ml with some subset of these variables, then correlate the matrix, and finally factanal (factor analyze) the ml matrix, reducing the factors to 1 to test the single factor model. The results will give a significance test for the null hypothesis.

cols<-na.exclude(data.frame(V774,V903,V783,V780,V775,V891,V893,V894,V896,V892)) #categorical 
cols<-na.exclude(data.frame(V774,V783,V780,V775)) #categorical 
cols<-na.exclude(data.frame(V893,V894,V892,V891)) #categorical N=130 p=.78
cols<-na.exclude(data.frame(V893,V894,V892,V896)) #categorical N=134 p=.24
cols<-na.exclude(data.frame(V893,V894,V892,V897)) #categorical N=134 p=.27
cols<-na.exclude(data.frame(V893,V894,V892,V896)) #categorical N=134 p=.27
cols<-na.exclude(data.frame(V893,V894,V892)) #categorical N=134 p=.002
cols<-na.exclude(data.frame(V893,V894,V892,V900)) #categorical N=128 p=.002 2 factors is too many for 4 variables
cols<-na.exclude(data.frame(V893,V894,V892,V900,V895)) #categorical N=134 p=.001 2-factor p=.06
m1 <- cbind(x1,x2,x3,x4,x5) #,x6)
#factanal(m1,factors=3) #numeric; *Verimax is the default

  1. Factor Analysis in R http://stat.ethz.ch/R-manual/R-patched/library/stats/html/factanal.html http://dataninja.wordpress.com/2006/02/18/basic-factor-analysis-in-r/
  2. Factor Analysis in R http://rss.acs.unt.edu/Rdoc/library/stats/html/factanal.html

This works:

v1 <- c(1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,4,5,6)
v2 <- c(1,2,1,1,1,1,2,1,2,1,3,4,3,3,3,4,6,5)
v3 <- c(3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,5,4,6)
v4 <- c(3,3,4,3,3,1,1,2,1,1,1,1,2,1,1,5,6,4)
v5 <- c(1,1,1,1,1,3,3,3,3,3,1,1,1,1,1,6,4,5)
v6 <- c(1,1,1,2,1,3,3,3,4,3,1,1,1,2,1,6,5,4)
m1 <- cbind(v1,v2,v3,v4,v5,v6)
factanal(m1, factors=3) # varimax is the default





http://dataninja.wordpress.com/2006/02/18/basic-factor-analysis-in-r/ (also sells help), or http://rss.acs.unt.edu/Rdoc/library/stats/html/factanal.html, e.g.

> factors = factanal(cols,factors,scores=c(”regression”),rotation=”varimax”)

where “cols” is our dataframe containing the appropriate variables, with no missing values, and “factors” is the number of factors to be extracted.

socres=”…” and rotation=”…” are optional, and varimax is the default rotation.

If you are doing factor analysis using the Standard Cross-Cultural Sample from any of the problem sets, consult the Index of Variables for a current factor list.

Ethnographic Atlas

Codebooks, see: Codebook [8]


(There is a standard critique of the Atlas, answered in the SCCS" http://unauthorised.org/anthropology/anthro-l/april-1996/0099.html)

Once R is installed (Default R packages)

> help.start()













V34                                                         missing data No agriculture Casual agriculture
 missing data                                                       103             83                 12
 Absent or not reported                                               0             94                 11
 Not active in human affairs                                          0             38                  2
 Active in human affairs, not supportive of human morality            0              9                  3
 Supportive of human morality                                         0              9                 15
V34                                                         Extensive or shifting agriculture Horticulture
 missing data                                                                            195           39
 Absent or not reported                                                                   67           51
 Not active in human affairs                                                             147            7
 Active in human affairs, not supportive of human morality                                21            0
 Supportive of human morality                                                             40            2
V34                                                         Intensive agriculture Intensive irrigated agriculture
 missing data                                                                 60                              27
 Absent or not reported                                                       20                              34
 Not active in human affairs                                                  41                              13
 Active in human affairs, not supportive of human morality                     8                               1
 Supportive of human morality                                                 64                              51