[R] bayesian HLM random effects/ problem with base package

Nicole Ford nicoleford74 at gmail.com
Thu Mar 28 16:54:44 CET 2013


my data was deleted, i supposed i uploaded it wrong.  that's fine i found the problem...

it's with the base package, actually.

please see below:


R version 2.15.3 (2013-03-01) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or '()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[R.app GUI 1.53 (6451) i386-apple-darwin9.8.0]

[History restored from /Users/nicoleford/.Rhistory]

> library(car)
Loading required package: MASS
Loading required package: nnet
> library(foreign)
> install.packages("base")
--- Please select a CRAN mirror for use in this session ---
Warning message:
package ‘base’ is not available (for R version 2.15.3) 
> library(base)

it is odd because everything was workign just fine yesterday.

the rest of my code below and i stop at the problem.

---
options(useFancyQuotes=F)
dat <- read.dta(file.choose())
####____________________________________________________________________________________________
tmp <- rep(NA, nrow(dat))
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "not very much" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "no trust at all")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "not very much" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "not very much")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "not very much" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "not very much" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "trust completely")] <- "generalized"
tmp <- factor(tmp, levels=c("particular", "generalized", "other"))
dat$trust <- tmp
dat$dem <- as.numeric(dat$v162)-5
dat$educ <- dat$v238

> ls(wvsAB)
 [1] "age"        "country"    "cpi"        "dem"        "diversity"  "educ"       "gender"     "income"    
 [9] "net"        "numcountry" "trust"     
> 

clearly, 'uncountry' is not here, and it should be.
dat$income <- dat$v253
dat$age <- dat$v237
dat$gender <- dat$v235
dat$country <- dat$v2
dat$net <- as.factor(as.character(dat$v228))
dat$diversity <- as.numeric(dat$v221)-5




wvsA <- na.omit(dat[,c("trust", "dem", "gender", "educ", "income", "age", "country", "net", "diversity")])
#####
dat <- read.dta(file.choose())
####____________________________________________________________________________________________
tmp <- rep(NA, nrow(dat))
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "not very much" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "no trust at all")] <- "other"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "no trust at all")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "not very much" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "not very much")] <- "other"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "not very much")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "not very much" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "somewhat")] <- "particular"
tmp[which(dat$v128 == "no trust at all" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "not very much" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "somewhat" & dat$v127 == "trust completely")] <- "particular"
tmp[which(dat$v128 == "trust completely" & dat$v127 == "trust completely")] <- "generalized"
tmp <- factor(tmp, levels=c("particular", "generalized", "other"))
dat$trust <- tmp
dat$dem <- as.numeric(dat$v162)-5
dat$educ <- dat$v238
dat$income <- dat$v253
dat$age <- dat$v237
dat$gender <- dat$v235
dat$country <- dat$v2
dat$net <- as.factor(as.character(dat$v228))
dat$diversity <- as.numeric(dat$v221)-5




##makes russia go away!!!!!  =((( ##### 

## I was able to get plots and almost all the way done without using na.omit for wvsB.####

#wvsB <- na.omit(dat[,c("trust", "dem", "gender", "educ", "income", "age", "country", "net", "diversity")])#


wvsB <- dat[,c("trust", "dem", "gender", "educ", "income", "age", "country", "net", "diversity")]


wvsA$country <- as.character(wvsA$country)
wvsB$country <- as.character(wvsB$country)


norway <- wvsA[which(wvsA$country == "norway"), ]

russia <- wvsB[which(wvsB$country == "russia"), ]

ukraine <- wvsA[which(wvsA$country == "ukraine"), ]

moldova <- wvsA[which(wvsA$country == "moldova"), ]

georgia <- wvsA[which(wvsA$country == "georgia"), ]

poland <- wvsA[which(wvsA$country == "poland"), ]

serbia <- wvsA[which(wvsA$country == "serbia"), ]

slovenia <- wvsA[which(wvsA$country == "slovenia"), ]

bulgaria <- wvsA[which(wvsA$country == "bulgaria"), ]

turkey <- wvsA[which(wvsA$country == "turkey"), ]



wvsAB1 <- rbind(norway, russia)

wvsAB2 <- rbind(wvsAB1, ukraine)

wvsAB3 <- rbind(wvsAB2, moldova)

wvsAB4 <- rbind(wvsAB3, georgia)

wvsAB5 <- rbind(wvsAB4, poland)

wvsAB6 <- rbind(wvsAB5, serbia)

wvsAB7 <- rbind(wvsAB6, bulgaria)

wvsAB8 <- rbind(wvsAB7, turkey)

wvsAB9 <- rbind(wvsAB8, slovenia)

wvsAB <- wvsAB9


########
###-----
dat <- data.frame(country = rep(c("norway", "ukraine", "serbia", "turkey", "slovenia","poland", "russia", "bulgaria", "georgia", "moldova"), c(1,2,3,4,5,6,7,8,9,10)), var = 1:55)
cpi <- data.frame(country = c("norway", "ukraine", "serbia", "turkey", "slovenia","poland", "russia", "bulgaria", "georgia", "moldova"), cpi=c(8.7, 2.4, 3.5,4.4,6.4,5.3,2.1, 3.6, 3.8, 2.9))
newdat <- cbind(dat, cpi[match(dat$country, cpi$country), "cpi"])
colnames(newdat)[ncol(newdat)] <- "cpi"
######
cpi <- read.csv("~/Desktop/cpi2010.csv", header=T)
tmp <- wvsAB[which(!is.na(wvsAB$dem)), ]
wvsAB$cpi <- cpi[match(tolower(as.character(wvsAB$country)), tolower(as.character(cpi[,2]))), "cpi"]


#########

uncountry <- unique(wvsAB[,7])

wvsAB$numcountry <- match(wvsAB$country, uncountry)

> ls(wvsAB)
 [1] "age"        "country"    "cpi"        "dem"        "diversity"  "educ"       "gender"     "income"    
 [9] "net"        "numcountry" "trust" 

any direction is appreciated.

thanks.

~n


On Mar 28, 2013, at 9:48 AM, Nicole Ford wrote:

> Hello, all.
> 
> I've been working on this for sometime and was almost at the end/ last chunk of code i would need....  When I received an error.  Rather than go to bed and think about it in the morning, I messed with my data and now I am not getting anything.  I was up until 4am trying to fix this.  
> 
> Zip files of my data are attached (the data which ends in 'a' matches with wvsA  and the data which ends in 'b' matches with my data code wvsB).  my code is below.
> 
> I can't even get plots, now.  If i can just get to that point, i would be eternally grateful for any help.
> 
> please find my code attached, as well.
> -----
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list