Thursday, December 29, 2011
vim virtualedit
Friday, December 9, 2011
jags data format and openbugs data format
Missing values are represented as NA.
The whole array must be specified in the file - it is not possible just to specify selected components. Any parts of the array you do not want to specify must be filled with NAs.
All variables in a data file must be defined in a model, even if just left unattached to the rest of the model.
S-Plus format: This allows scalars and arrays to be named and given values in a single structure headed by key-word list. There must be no space after list.
For example, in the Rats example, we need to specify a scalar xbar , dimensions N and T , a vector x and a two-dimensional array Y with 30 rows and 5 columns. This is achieved using the following format:
list(
xbar = 22, N = 30, T = 5,
x = c(8.0, 15.0, 22.0, 29.0, 36.0),
Y = structure(
.Data = c(
151, 199, 246, 283, 320,
145, 199, 249, 293, 354,
...................
...................
137, 180, 219, 258, 291,
153, 200, 244, 286, 324),
.Dim = c(30, 5)
)
)
OpenBUGS reads data into an array by filling the right-most index first, whereas the S-Plus program fills the left-most index first. Hence OpenBUGS reads the string of numbers c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) into a 2 * 5 dimensional matrix in the order
[i, j]th element of matrix value
[1, 1] 1
[1, 2] 2
[1, 3] 3
..... ..
[1, 5] 5
[2, 1] 6
..... ..
[2, 5] 10
whereas S-Plus reads the same string of numbers in the order
[i, j]th element of matrix value
[1, 1] 1
[2, 1] 2
[1, 2] 3
..... ..
[1, 3] 5
[2, 3] 6
..... ..
[2, 5] 10
Hence the ordering of the array dimensions must be reversed before using the S-Plus dput function to create a data file for input into OpenBUGS .
For example, consider the 2 * 5 dimensional matrix
1 2 3 4 5
6 7 8 9 10
This must be stored in S-Plus as a 5 * 2 dimensional matrix:
> M
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10
The S-Plus command
> dput(list(M=M), file="matrix.dat")
will then produce the following data file
list(M = structure(.Data = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), .Dim=c(5,2))
Edit the .Dim statement in this file from .Dim=c(5,2) to .Dim=c(2,5). The file is now in the correct format to input the required 2 * 5 dimensional matrix into OpenBUGS .
Now consider a 3 * 2 * 4 dimensional array
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
21 22 23 24
This must be stored in S-Plus as the 4 * 2 * 3 dimensional array:
> A
, , 1
[,1] [,2]
[1,] 1 5
[2,] 2 6
[3,] 3 7
[4,] 4 8
, , 2
[,1] [,2]
[1,] 9 13
[2,] 10 14
[3,] 11 15
[4,] 12 16
, , 3
[,1] [,2]
[1,] 17 21
[2,] 18 22
[3,] 19 23
[4,] 20 24
The command
> dput(list(A=A), file="array.dat")
will then produce the following data file
list(A = structure(.Data = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1 6, 17, 18, 19, 20, 21, 22, 23, 24), .Dim=c(4,2,3))
Edit the .Dim statement in this file from .Dim=c(4,2,3) to .Dim=c(3,2,4). The file is now in the correct format to input the required 3 * 2 * 4 dimensional array into OpenBUGS in the order
Friday, November 4, 2011
vim syntax support for JAGS
Tuesday, October 25, 2011
Wednesday, October 5, 2011
sqlite3 concatenate a column by group
group_concat(X) group_concat(X,Y) So we can easily from | The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X. A comma (",") is used as the separator if Y is omitted. The order of the concatenated elements is arbitrary. |
Friday, September 30, 2011
sqlite3 attach a database
vim search ignore case
Wednesday, September 28, 2011
sqlite3 describe table
Friday, September 16, 2011
rjags on ubuntu -- nonzero exit status
> I've not been able to install rjags successfully in Ubuntu 10.04 :
>
> ** testing if installed package can be loaded
> Error : .onLoad failed in loadNamespace() for 'rjags', details:
> call: dyn.load(file, DLLpath = DLLpath, ...)
> error: unable to load shared library
> '/home/scott/R/i486-pc-linux-gnu-library/2.11/rjags/libs/rjags.so':
> libjags.so.2: cannot open shared object file: No such file or directory
> ERROR: loading failed
>
> I've tried with different versions of both JAGS& rjags; lastly with R
> 2.11.0, JAGS 2.1.0,& rjags_2.1.0-4. Could anyone help ?
>
Scott,
I also had trouble installing rjags in 10.04. I got the same error you
did, even though I could see the .so files. The fix (I think, I tried
lots of things) was to run 'ldconfig', then launch R and install the
package. Apparently, my jags install did not update the libraries.
Hope this helps,
Michael
cd/dvd driver
OK now is the truth. This is the solution. I assume all of you is using USB drive to install. When Windows is asking for driver, just click Cancel. You will be brought back to the welcome screen. At the welcome screen, remove your USB drive, insert it back to DIFFERENT USB PORT. Click Install Now again. The installation process will be like usual.....Thanks,the problem fixed whit your methods...nice job :)
Wednesday, September 14, 2011
ubuntu maverick lib64
ubuntu sudo
old ubuntu (maverick), new R
Friday, September 9, 2011
grep --color=always
Monday, July 18, 2011
cpp lint by google
Monday, July 4, 2011
clang another good c compiler
Sunday, July 3, 2011
obtain a figure file list from a tex file using grep and sed: new version
tmpfile=`mktemp -p . exttmp.XXXX`grep includegraphics $1 > $tmpfilesed -e 's/includegraphics/ /' -e 's/[\\{}]//g' -e 's/\[.*\]//g' -e 's/[^ ]\+//' -e 's/^ \+//' < $tmpfileif [ -f "$tmpfile" ]thenrm "$tmpfile"fi## the includegraphics must be at the same line with the pdf or other figure files included.
R mathplot plotmath
Friday, July 1, 2011
Vim file type detection: only R for .r and .R
Vim includes syntax highlighting for two other languages that use the .r and .R file extensions. Vim searches up to the first 50 lines of a file and checks the comment syntax to determine whether it is R or Rexx. If no comments are found, it defaults to Rexx. This can be annoying for starting a new script. If you want .r and .R to ALWAYS be associated with R syntax, put au BufNewFile,BufRead .r,.R setf r
in your ~/.vim/filetype.vim
(alternatively, you can use the same line in~/.vim/ftdetect/r.vim
).
=====
Under ubuntu maverick, I would just change file /usr/share/vim/vim72/filetype.vim
Thursday, June 30, 2011
obtain a figure file list from a tex file using grep and sed
Sunday, May 29, 2011
Saturday, April 23, 2011
Saturday, March 12, 2011
grep files from results by find
find /var/ftp/mp3 -name "*.mp3" -type f -exec chmod 644 {} \;
This command changes the permissions of all files with a name ending in .mp3 in the directory /var/ftp/mp3. The action is carried out by specifying the option -exec chmod 644 {} \;
in the command. For every file whose name ends in .mp3
, the command chmod 644 {}
is executed replacing {}
with the name of the file. The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command. Permission 644
, usually shown as rw-r--r--
, gives the file owner full permission to read and write the file, while other users have read-only access. In some shells, the {}
must be quoted.
copied from http://en.wikipedia.org/wiki/Find
Saturday, March 5, 2011
Sunday, February 6, 2011
sqlite3 scripts comments notation
-- ********************************************************************
-- Creating a trigger for timeEnter
-- Run as follows:
-- $ sqlite3 test.db < trigger1
-- ********************************************************************
CREATE TRIGGER insert_t1_timeEnter AFTER INSERT ON t1
BEGIN
UPDATE t1 SET timeEnter = DATETIME('NOW') WHERE rowid = new.rowid;
END;
-- ********************************************************************
Sunday, January 30, 2011
sqlite dump
copied from http://stackoverflow.com/questions/75675/how-do-i-dump-the-data-of-some-sqlite3-tables
You don't say what you wish to do with the dumped file.
I would use the following to get a CSV file, which I can import into almost everything
.mode csv
.header on
.out file.dmp
select * from emp;
If you want to reinsert into a different SQLite database then:
.mode insert
.out file.sql
select * from em
compile sqlite3 to be a shared library
Wednesday, January 12, 2011
cd 2 iso on mac
hdiutil makehybrid -iso -joliet -o Master.is XXXX
XXXX is the folder that might show on the desktop