[R] Simulation in R - Part 2

Alexander Geisler alexander.geisler at gmail.com
Thu Dec 7 22:33:05 CET 2006


Hello!

So, the simulation works (drawing 100 samples and then calculate the
model for each sample). Here is the code:

--snip--
# sample size n=200
ergebnisse200 <- rep(0, each=100)
stichproben200 <- vector(“list”, 100)
default200 <- rep(0, each=100)

for (i in seq(1:100)) {
n <- dim(daten)[1]  	
ix <- sample(n,200) 	
samp_i <- daten[ix,]  	# draw samples
y <- sum(samp_i$y)     # number of defaults
stichproben200[[i]] <- samp_i  # saving the samples
default200[i] <- y   # saving the number of defaults

# Modell berechnen:
posterior_i <- MCMClogit(y ~ fbl.ind + fekq3 + febitda4 + fuvs + fkru +
fzd + fur3, data=samp_i, b0=prior, B0=precision, tune=0.5) # calculation
ergebnisse200[i] <- summary(posterior_i)  # saving the results
}

# write out the solutions into an excel-file
write.csv2(ergebnisse200, "ergebnisse.csv")
--snip--

My solution has the following form:

http://img296.imageshack.us/my.php?image=ergebnissewa0.jpg

write.csv2 makes the right thing, but in the excel-file, if I open the
csv-file in excel, several objects are next to each other (I'm missing
the line break after each object of the array); look at
http://img67.imageshack.us/my.php?image=ergebnisseexcelbg7.jpg
The problem is that there is an error message by importing the csv in 
excel, because there are to many columns needed to import the 100 objects.

So, my question:
Is it possible to write the 100 objects of the array among each other.
Like as it can be seen in R 
(http://img296.imageshack.us/my.php?image=ergebnissewa0.jpg)?
Another way is to produce 50 samples in a first turn and then produce 50 
samples again in another turn, but this can not be a "clean" solution 
(and surely not the only one).

Hopefully you can help me and this is the last question for my simulation.

Thanks for your efforts
Alex

-- 
Alexander Geisler * Kaltenbach 151 * A-6272 Kaltenbach
email: alexander.geisler at gmx.at | alexander.geisler at gmail.com
phone: +43 650 / 811 61 90 | skpye: al1405ex




More information about the R-help mailing list