Friday, May 16, 2014

Sample uniformly within a fixed radius.

I was asked how to do this today and thought that I would share the answer:
## Sample points uniformly within a fixed radius

nrand=1000
maxstep=10

## Sample data  
## NB: To get a truly uniform sample over the circle, you must 
##     sample the square of the distance and then transform back.
tempdat<-data.frame(X0=0,Y0=0, bearing0=0, 
                    bad.dist= runif(nrand)*maxstep, 
                    dist2=sqrt(runif(nrand)*maxstep^2),
                    turningangle=runif(nrand)*2*pi-pi)

##convert Turning angle to bearing (in this case no change)
tempdat$bearing=tempdat$bearing0+tempdat$turningangle

## Convert from polar to cartesian coordinates
tempdat$X<-tempdat$X0+tempdat$dist2*sin(tempdat$bearing)
tempdat$Y<-tempdat$Y0+tempdat$dist2*cos(tempdat$bearing)

tempdat$Xbad<-tempdat$X0+tempdat$bad.dist*sin(tempdat$bearing)
tempdat$Ybad<-tempdat$Y0+tempdat$bad.dist*cos(tempdat$bearing)


##make plots
png(filename="sampleplots.png",width=500,height=1000)
par(mfrow=c(2,1))
plot(Ybad~Xbad, data=tempdat, asp=1, main="Center is oversampled")
plot(Y~X, data=tempdat, asp=1, main="Uniform across space")
dev.off()

Monday, April 28, 2014

RStudio and X2Go

After a recent system upgrade (to Linux Mint LMDE), I was no longer able to run RStudio through the remote desktop application X2Go. It turns out that this is due to a problem with the Qt libraries (see this website). As suggested here, I just deleted all the Qt libraries used by RStudio:

sudo rm  /usr/lib/rstudio/bin/libQt* 
 

and all was well. (NB, the specific link to these files will vary depending on the flavor of Linux you use.)

**EDIT: If you are installing this on pure Debian (I just confirmed this with a new Jessie install) you will need to install appropriate libraries too:

sudo aptitude install libqtwebkit4