2011-11-15 9 views
2

나는이 예제를 사용하여 R2WinBUGS를 사용하는 것을 시도하고있다 :R2WinBUGS - 경고 메시지

code

은 (부분 만 고려하시기 바랍니다 : ### 5.4 분석 사용의 Winbugs.)

나는이 무엇입니까 오류 메시지 :

Error in file(con, "wb") : cannot open the connection 
In addition: Warning messages: 
1: In file.create(to[okay]) : 
    cannot create file 'c:/Program Files/WinBUGS14//System/Rsrc/Registry_Rsave.odc', reason 'Permission denied' 
2: In file(con, "wb") : 
    cannot open file 'c:/Program Files/WinBUGS14//System/Rsrc/Registry.odc': Permission denied 
Warning message: 
running command '"c:/Program Files/WinBUGS14//WinBUGS14.exe" /par "D:/R2WinBUGS/normal/script.txt"' had status 1 
> 

나는이 올바른 기능에 대한 중요한인지 확실하지 않다는 (다른 모든 확인을 보는 것 같다). 이걸 없애는 방법이 있습니까?

감사합니다.

기독교

추신 :

library(R2WinBUGS) 
setwd("D:/R2WinBUGS/normal") 

y10 <- rnorm(n = 10, mean = 600, sd = 30) # Sample of 10 birds 
y1000 <- rnorm(n = 1000, mean = 600, sd = 30) # Sample of 1000 birds 

# Save BUGS description of the model to working directory 
sink("model.txt") 
cat(" 
model { 

# Priors 
population.mean ~ dunif(0,5000)  # Normal parameterized by precision 
precision <- 1/population.variance # Precision = 1/variance 
population.variance <- population.sd * population.sd 
population.sd ~ dunif(0,100) 

# Likelihood 
for(i in 1:nobs){ 
    mass[i] ~ dnorm(population.mean, precision) 
} 
} 
",fill=TRUE) 
sink() 

# Package all the stuff to be handed over to WinBUGS 
# Bundle data 
win.data <- list(mass = y1000, nobs = length(y1000)) 

# Function to generate starting values 
inits <- function() 
    list (population.mean = rnorm(1,600), population.sd = runif(1, 1, 30)) 

# Parameters to be monitored (= to estimate) 
params <- c("population.mean", "population.sd", "population.variance") 

# MCMC settings 
nc <- 3     # Number of chains 
ni <- 1000    # Number of draws from posterior (for each chain) 
nb <- 1     # Number of draws to discard as burn-in 
nt <- 1     # Thinning rate 

# Start Gibbs sampler: Run model in WinBUGS and save results in object called out 
out <- bugs(data = win.data, inits = inits, parameters.to.save = params, model.file = "model.txt", 
n.thin = nt, n.chains = nc, n.burnin = nb, n.iter = ni, debug = TRUE, DIC = TRUE, working.directory = getwd()) 

ls() 

out     # Produces a summary of the object 

names(out) 

str(out) 

hist(out$summary[,8])   # Rhat values in the eighth column of the summary 
which(out$summary[,8] > 1.1)  # None in this case 

par(mfrow = c(3,1)) 
matplot(out$sims.array[1:999,1:3,1], type = "l") 
matplot(out$sims.array[,,2] , type = "l") 
matplot(out$sims.array[,,3] , type = "l") 

par(mfrow = c(3,1)) 
matplot(out$sims.array[1:20,1:3,1], type = "l") 
matplot(out$sims.array[1:20,,2] , type = "l") 
matplot(out$sims.array[1:20,,3] , type = "l") 

par(mfrow = c(3,1)) 
hist(out$sims.list$population.mean, col = "grey") 
hist(out$sims.list$population.sd, col = "blue") 
hist(out$sims.list$population.variance, col = "green") 

par(mfrow = c(1,1)) 
plot(out$sims.list$population.mean, out$sims.list$population.sd) 

pairs(cbind(out$sims.list$population.mean, out$sims.list$population.sd, out$sims.list$population.variance)) 

summary(out$sims.list$population.mean) 
summary(out$sims.list$population.sd) 
sd(out$sims.list$population.mean) 
sd(out$sims.list$population.sd) 

summary(lm(y1000 ~ 1)) 
+0

Windows Vista 또는 7을 실행 중입니까? 감사합니다. –

+0

. windows 7. 권한 문제 일 수 있습니까? – cs0815

+0

아마, 기본적으로 UAC는 사용자의 폴더를 제외한 거의 모든 프로그램에 프로그램을 작성할 수 없습니다. R을 관리자로 실행하여 변경할 수 있습니다. 그러나 그것이 Renviron.site에서 하드 코드되지 않는 한 라이브러리 폴더가 변경 될 것이라고 생각하지만 100 % 확신 할 수는 없습니다. –

답변

7

아마 Windows UAC 오류입니다. 기본적으로 UAC는 사용자의 폴더를 제외한 거의 모든 프로그램에서 프로그램을 작성할 수 없습니다. R을 관리자로 실행하여 변경할 수 있습니다. 하지만 그것은 Renviron.site (R \ etc 폴더 내부)에 하드 코드되어 있지 않으면 라이브러리 폴더가 변경 될 것이라고 생각하지만, 100 % 확실하지는 않습니다.

+0

단순히 R을 admin으로 실행하면 나를위한 트릭을 만들었습니다 –

1

귀하의 링크가 책의 여러 장에 걸쳐있는 큰 파일 외출 :

이것은 R 코드입니다. 댓글 섹션에 다음과 같이 표시됩니다.

# You may have to add a 'working.directory' argument to calls to 
# the function bugs(). 

아직 완료 했습니까?

setwd("C:/_Marc Kery/_WinBUGS book/Naked code") # May have to adapt that 

당신이 적절하게 해당 항목을 수정 한 : 같은 사용자 별 잔뜩도있다?

+0

죄송합니다. 저는 이것을 깨닫지 못했습니다. 나는이 부분에 관심이있다 : 임대 부분 만 고려해 보라 : ### 5.4. WinBUGS를 사용한 분석 – cs0815

+0

첫 번째 인용구는 전체 프로그램 세트에 적용되며 두 번째 인용문은 문제가있는 섹션의 인용구입니다. –

+0

나는 setwd 비트를했다. 첫 번째 비트 (working.directory)에 대해서는 잘 모르겠습니다. 이것은 R의 일부인 버그 기능을 나타내지 만, winbugs가 문제를 일으키는 것으로 보입니다. 관리자로서 R을 실행하면 이러한 문제가 발생하지 않습니다. 그래서 당신의 제안이 '깨끗한'해결책이 될지 확신 할 수 없습니다. – cs0815

3

"bugs.directory"를 정의하여 문제를 해결할 수있었습니다.

< - 버그 (데이터 = win.data, inits = inits, parameters.to.save = params, model.file = "model.txt", n.thin = nt, n.chains = nc, n .burnin = nb, n.iter = ni, debug = FALSE, DIC = TRUE, working.directory = getwd(), bugs.directory = 'c :/WinBUGS14')

+0

안녕하세요, win8을 사용하고 "bugs.directory"를 정의하면 문제를 해결하기에 충분했습니다. – Rafael