Using R2winBUGS אודה לסיוע!!!

14 views
Skip to first unread message

Maya Hadar

unread,
Aug 12, 2015, 5:35:51 AM8/12/15
to Israel R User Group
היי כולם,

אני מנסה לעשות replication
 R2winBUGS לקוד שנכתב ב2010 באמצעות 

אני לא ממש מבינה למה הסופר השתמש בחבילה האמורה כי המטרה היא לבצע 
Bayesian analysis 
עם מודל של 14 יום

בכל אופן, כשאני מריצה את הקוד אר נתקע כשהוא לא מוצא קבצים מסויימים שלדעתי היו מותקנים על אר בגרסאות קודמות של החבילה האמורה אבל לא עוד. 

הפנתי את אר לספריה בה החבילה הותקנה ולמרות (בקוד) ולמרות זאת השגיאה שאני מקבלת היא
cannot open file 'C:/Users/Hiwi/Documents/R/Win-library/3.0/R2winBUGS/System/Rsrc/Registry.odc': No such file or directory
Error in bugs.run(n.burnin, bugs.directory, WINE = WINE, useWINE = useWINE,  : 
  WinBUGS executable does not exist in C:/Users/Hiwi/Documents/R/Win-library/3.0/R2winBUGS/


מצ"ב הקוד, הקובץ דייטה היחיד שלי שבקוד הוא jp.dta

אם מישהו מבין מה החבילה עושה, איך אני מוצאת את הקובץ שאר מבקש שהוא חלק מהחבילה בגרסה ישנה, או דרך אחרת לבצע את האנליזה- אהיה אסירת תודה על עזרתכם. יש לי את התוצאות של הניתוח ואני רק צריכה לוודא שהן נכונות.

אלפי תודות!!!!

מאיה


rm(list=ls(all=TRUE))      

setwd("C:/Users/Naomi/Documents/R/replication")
library(foreign)

rawdata <- read.dta("jp.dta",convert.factors = F)


library(MASS)
summary(glm.nb(rawdata$num_events_14 ~ rawdata$jp_num))


# WinBUGS code

library(R2WinBUGS)
nb.model <- function(){
for (i in 1:n){ # loop for all observations
      # stochastic component
      dv[i]~dnegbin( p[i], r)
      # link and linear predictor
      p[i] <- r/(r+lambda[i])
      log(lambda[i] ) <- b[1] + b[2] * iv[i]
}
#
# prior distributions
r <- exp(logr)
  logr ~ dnorm(0.0, 0.01)

    b[1]~dnorm(0,0.001)  # prior  (please note: second element is 1/variance)
    b[2]~dnorm(0,0.001)  # prior
}


write.model(nb.model, "negativebinomial.bug")


n <- dim(rawdata)[1] # number of observations


winbug.data <- list(dv = rawdata$num_events_14, 
                    iv = rawdata$jp_num,
                    n=n)

winbug.inits <- function(){list(logr = 0 ,b=c(2.46,-.37)
                                )} # Ausgangswerte aus der Uniformverteilung zwischen -1 und 1

bug.erg <- bugs(data=winbug.data,
    inits=winbug.inits, 
    #inits=NULL,
    parameters.to.save = c("b","r"),
    model.file="negativebinomial.bug",
    n.chains=3, n.iter=10000, n.burnin=5000,
    n.thin=1,
    codaPkg=T,
    debug=F,
    #bugs.directory="C:/Users/Naomi/Documents/R/WinBUGS14/" #כאן הבעיה זו הספריה המקורית בקוד שכמובן לא קיימת. כששיניתי לספריה בה הותקנה החבילה על המחשב שלי ראו לעיל, קיבלתי את הודעת השגיאה
    bugs.directory="C:/Users/Naomi/Documents/R/WinBUGS14/"
    )

tempdir()
setwd(tempdir())
file.rename("codaIndex.txt","simIndex.txt")
file.rename("coda1.txt","sim1.txt")
file.rename("coda2.txt","sim2.txt")
file.rename("coda3.txt","sim3.txt")

posterior <- rbind(read.coda("sim1.txt","simIndex.txt"),read.coda("sim2.txt","simIndex.txt"),read.coda("sim3.txt","simIndex.txt"))
post.df <- as.data.frame(posterior)
summary(post.df)
quantile(post.df[,2],probs=c(.025,.975))
quantile(post.df[,2],probs=c(.05,.95))
quantile(post.df[,2],probs=c(.10,.90))
tempdir()
jp.r
jp.dta

Tal Galili

unread,
Aug 12, 2015, 11:52:17 PM8/12/15
to israel-r-...@googlegroups.com
שלום מאיה,
אני ממש לא מומחה בנושא הזה, אבל אני רק שאלה - למה winbugs ולא משהו כמו 
stan
(היותר מודרני)
?



----------------Contact Details:-------------------------------------------------------
Contact me: Tal.G...@gmail.com
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English)
----------------------------------------------------------------------------------------------


--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maya Hadar

unread,
Aug 13, 2015, 4:16:46 AM8/13/15
to israel-r-...@googlegroups.com
היי ותודה על התשובה,

גם אני לא מומחית ומה שאני צריכה לעשות זה replication ולכן אני נצמדת לקוד המקורי.  

מה עושה   stan?

תודה!
You received this message because you are subscribed to a topic in the Google Groups "Israel R User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/israel-r-user-group/VKdXN3XAkV0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to israel-r-user-g...@googlegroups.com.

amit gal

unread,
Aug 13, 2015, 11:38:12 AM8/13/15
to israel-r-...@googlegroups.com
 סטאן עושה אותו דבר כמו ווינבאג. שניהם פותחו על ידי אנדרו גלמן והם דומים מאד. פשוט סטאן יותר טוב, הן מבחינה סטטיסטית (יותר מודלים וכו') והן מבחינה חישובית (יותר מהר, פחות שגיאות וכו')
ייתכן אפילו שעם מעט מאד מאמץ אפשר להתאים קוד ווינבאג לקוד סטאן

Reply all
Reply to author
Forward
0 new messages