トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS

RMFD

by y --> by y -->
Top / RMFD

18/Jan/2010

sample R script

###############################################
# preparing data
###############################################

# load a library of handling 'foreign' data sets
library(foreign) 

# load a data file, and assign a name to that object
read.spss("issp00.sav") -> issp

# check variable names in issp
names(issp)

# specify missing values ( you may have to edit this list.)
nav3 <- c("RC","ZA","FLA","YV","BR","BD","CH","DK","CY","F","SK","IL-A","PL","SLO","IRL","I","H","AUS")
nagen <- c("NA,refused", "NA, refused", "Cant Choose, DK", "NAV", "Nap,nav", "Na","Cant Choose", "NAP, NAV", "Cant Choose, Dk","NA","Cant choose","NA,RP:none", "Cant choose,DK","Na, refused")
naall <- c(nav3,nagen)


###############################################
# univariate analysis
###############################################
#make a frequency table of age (continuous variable)
table(issp$AGE)
hist(issp$AGE)

#measure of central tendency and dispersion
mean(issp$AGE)
summary(issp$AGE)
var(issp$AGE)
sd(issp$AGE)
#make a frequency table of V3(country) (categorical variable)
table(issp$V3)

#you can exclude missing values from a table
table(issp$V3,exclude=naall)->tab1
tab1

#make a table of % by prop.table()
prop.table(tab1)
round(prop.table(tab1),2)
round(prop.table(tab1),2)*100


#make a graph of v3
barplot(tab1)
barplot(tab1, las=2) # you can change the direction of labels by "las"
barplot(tab1, las=2, col=rainbow(7)) # you can put colours by "col"
barplot(tab1, las=2, col="green", main="Country of Respondents") # you can put title texts by "main"
pie(tab1)

###############################################
# bivariate analysis
###############################################

# continuous X continuous
#  wrkhrs x age
plot(issp$WRKHRS,issp$AGE)
cor(issp$WRKHRS,issp$AGE)

# categorical X categorical
# marital X v3(country)
table(issp$V3,issp$MARITAL)
table(issp$V3,issp$MARITAL, exclude=naall) -> tab2
tab2
prop.table(tab2,2) -> tab2.1
tab2.1
round(tab2.1,2)
mosaicplot(tab2)
mosaicplot(tab2,shade=TRUE,las=2)
# continuous X categorical
# age X marital
by(issp$AGE,issp$MARITAL,mean)

practice 1

  1. find a relation between v4(q1a) and sex
    1. make univariate analysis on v4(q1a) and sex
    2. make bivariate analysis between v4 and sex

practice 2

  1. find a relation between variables you mentioned in assignment#6-1 [#v2aa1bbe]
    1. make univariate analysis on variables you are interested in.
    2. make bivariate analysis on variables you are interested in.

21/Dec/2009

please download a data file bellow.

http://www.soc-nakano.net/himalaya/issp00.sav

  • how to download
    • control + click
      • "save as"
      • issp00.sav
  • you need an ID and a PASSWD (T.B.A.)