Archive for July, 2010

h1

TeXworks with Sweave

July 31, 2010

Recently, I’ve started trying TeXworks for my LaTeX editing needs. It’s pretty basic but works well, is fast, cross-platform, open-source, and has a nice previewer. I didn’t find any information regarding how to set up Sweave to run with it, so I’ve decided to post how I’ve done it.

Do the following
Edit -> Preferences...

Under the Typesetting tab, in the Processing tools section look for the ‘+’ and click it. This will bring up a dialog box to add your own ‘tool’

I added the following.

In the Name field:
Sweave

In the Program field:
R

And I gave it 3 arguments, each is a separate argument and should not be on the same line!
CMD
Sweave
$fullname

Also, I deselected view PDF as it doesn’t make sense as you now need to run LaTeX.

Click OK, then OK, and now you’ll have Sweave available in the drop down box.

It should look like the screenshot below.

texworks

h1

WinBUGS on Ubuntu and R2WinBUGS with Wine

July 27, 2010

The following is a how-to for setting up WinBUGS on the latest version of Ubuntu 10.04 LTS Lucid Lynx.

1. Install wine-1.0 not wine-1.2 (wine-1.2 will seg fault!)
sudo apt-get install wine-1.0

2. Download WinBUGS from here.

3. Navigate to the directory where you downloaded WinBUGS, I’ll assume it was /home/user/Downloads, and run the following:
wine WinBUGS14.exe

4. Launch WinBUGS
wine ~/.wine/drive_c/Program Files/WinBUGS14/WinBUGS14.exe

5. Patch WinBUGS with the following patch – available here. Apply that patch as described on the WinBUGS website. Then close WinBUGS and launch it again as previously described.

6. Add the immortality key – available here. Apply it the same way you did the patch!

7. Launch R and install R2WinBUGS
R
install.packages("R2WinBUGS")

8. Load R2WinBUGS and run the Gelman example to check that it worked
library(R2WinBUGS)
model.file <- system.file(package="R2WinBUGS","model",
"schools.txt")
data(schools)
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function(){
list(theta=rnorm(J, 0, 100), mu.theta=rnorm(1, 0, 100),
sigma.theta=runif(1, 0, 100))
}
parameters <- c("theta", "mu.theta", "sigma.theta")
schools.sim <- bugs(data, inits, parameters, model.file, n.chains=3, n.iter=5000)
print(schools.sim)
plot(schools.sim)

You will get a couple of messages from Wine, but I believe you can ignore these. I have not thoroughly tested this but I can corroborate that it gives similar estimates to R2WinBUGS from Windows (see below gnome-terminal vs. Windows XP in VirtualBox). I still recommend JAGS but if you need to use WinBUGS here is how.

Also this should work on any Linux distribution or Mac OS X provided that you can get Wine 1.0 as the latest Wine versions do not work with WinBUGS. Let me know if you have troubles.

r2winbugs

9. Add a desktop launcher (OPTIONAL)
Right Click gnome-panel
Click 'Add to Panel ...'
Click 'Custom Application Launcher'

Add the following to the Name field
WinBUGS14

Add the following to the Command field (do include the quotes!)
wine '/home/USER/.wine/drive_c/Program Files/WinBUGS14/WinBUGS14.exe'

Finally, if you want to add the WinBUGS icon, click here. Right click the image and select:
Save image as ...

Save it to /home/user/Downloads/ and then add it by clicking the Wine icon, navigating to the directory where you downloaded it and finally selecting the icon. Then close the Custom Application Launcher dialog box by clicking Close.

h1

Rgedit plugin (32 bit + 64 bit) and JAGS 2.1.0 (64 bit) for Ubuntu 10.04

July 26, 2010

I’ve rolled my own .deb package for Ubuntu 10.04 of Rgedit. This is a plugin for gedit that makes it act as an IDE for R in a similar fashion to ESS or TINN-R. To download the .deb file which is platform independent click here.

Also, I’ve recently updated to JAGS 2.1.0 and have rolled my own Ubuntu 10.04 64 bit packages. I will continue to keep JAGS updated by rebuilding Dirk’s packages from Debian Sid while 10.04 is supported (unless I move back to Debian once Squeeze is released). I will not roll packages for Ubuntu releases that are not LTS. You can get JAGS by clicking here. If anyone is willing to roll 32 bit package I am happy to host it here. Please let me know.