Error message
Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home3/gardeoi3/public_html/iamrandom/includes/common.inc).
R
By tholscla on Tue, 05/03/2016 - 16:09
Retrieving information from the table function:
x=c("river", "stream","stream","stream","river","river","river","stream","stream","stream", "flood")
y= table(x)
names(y)
as.vector(y)
sort(y,decreasing=TRUE)
By tholscla on Mon, 03/28/2016 - 13:44
Here is a quick example of how to recreate weighted regression without needing the weights=... part of lm(). It also shows how to set up your own intercept in R.
set.seed(50)
x0=rep(1,100) #specify the intercept because they multiply by the weights
x=round(runif(100),2)*100
w=(runif(100,1,10))^2
y=round(3*x+rnorm(100,0,10),2)
plot(x,y)
X=cbind(x0,x)
By tholscla on Mon, 06/16/2014 - 11:49
Download R from CRAN. Open R and at the prompt start installing packages. install.packages("Rcpp") install.packages("msm") install.packages("MCMCpack") install.packages("BayesLogit"). Place the NHMM folder (link below) in the same directory where the new libraries were just installed.
Open R and at the prompt use the library(NHMM). It contains the modeling functions: NHMM and HMM and NHMM_MVN, and output functions: OBIC, Oz, Oemparams, OWcoef, OXcoef, and OQQ. For the help files just put ?NHMM or ?OBIC
By tholscla on Wed, 06/11/2014 - 11:31
This code computes the probability that three (and possibly more) people in a group have the same birthday.
By tholscla on Mon, 05/05/2014 - 16:07
I usually use a print() statement within for loops but this progress bar seems better. I wish packages had this included.
Q = 10000
pb = txtProgressBar(min = 0, max = Q, style = 3)
for(i in 1:Q)
{
Sys.sleep(0.01)
setTxtProgressBar(pb, i)
}
close(pb)
By tholscla on Thu, 02/27/2014 - 22:27
Rcpp works well with Unix/Linux. Setting it up on Windows takes some work. Use the standard settings on all of these installs. (updated 2/2014)
By tholscla on Thu, 12/05/2013 - 15:57
I hate loading whole libraries for quick one line distributions.
dinvgamma=function(x,a,b){exp(a*log(b) - lgamma(a) - (a+1)*log(x) - b*1.0/x)}
rinvgamma=function(n,a,b){1/rgamma(n,a,b)} #at one point the MCMCpack library has this function with different parameters for Windows and Unix
By tholscla on Mon, 11/25/2013 - 10:59
Occasionally, I need to open .nc files. The names command does not work quite as I expected. Instead there is a names command to see all of the variables in the dataset.
library(ncdf)
data = open.ncdf(filename.nc)
print(data) #gives an overview of some of the contents of the netcdf file
names(data$var) #gives the actual variable names
var1_R=get.var.ncdf(data, "var1") ## assume var1 is one of the variables in the dataset
By tholscla on Mon, 11/25/2013 - 10:51
On occassion I have need to open Matlab files, usually cotaining data. library(R.matlab) and library(R.utils) are needed. The quick command is data=readMat(filename.mat).
By tholscla on Thu, 11/21/2013 - 11:47
I typicallly work with models and MCMC algorithms with many unknown parameters. At the end of the algorithm, all I really want is the mean and 95% PI. Here is some code that only saves the extreme 5% (2.5%,97.5%) of the posterior draws for a parameter. This cuts down on memory space if there are a lot of unknown parameters.
Pages