Thursday, February 23, 2012

create variables in a created environment inside global environment inside a function

# create an environment inside the global 
# environment and create variables inside
# that environment 

# ref: http://goo.gl/GCQhZ
foofun <- function() {
   assign("env1", new.env(parent = globalenv()),  envir = globalenv()) 

   # this would not work 
   # env1 <- new.env(parent = globalenv());
   assign("tmpv", "tmpv", envir = globalenv()$env1) 
} 

foofun() 

ls() 

ls(envir = globalenv()$env1) 

rm("env1", envir = globalenv()) 
ls() 

#

Friday, February 17, 2012

lme4 nested example

http://lme4.r-forge.r-project.org/book/
chapter 2, we have example of nested factors

cask is nested in batch

so
strength ~ 1 + (1 | cask) + (1 | batch)
is problematic,

the correct one is
strength ~ 1 + (1 | cask) + (1 | batch:cask)
though
it is equivalent to
strength ~ 1 + (1 | batch / cask).

Saturday, February 11, 2012

symbolic description of factorial models for analysis of variance

Symbolic Description of Factorial Models for Analysis of Variance

G. N. Wilkinson and C. E. Rogers


Y_ij = m + a_i + b_j + (ab)_ij

A + B + A : B

Y_ij = m + a_i + (ab)_ij

A + A : B

---
A * B = A + B + A : B
A / B = A + A : B

blocks / plots 
nitrate * density 

Friday, February 10, 2012

sftp by shell script

though sftp is not used nowadays, it is still needed, 

copied from somewhere cannot quite remember

#! /bin/sh
ftp -n ftp.ftp.com <<_FTPEND
quote USER anonymous
quote PASS aa 
bin
cd incoming
put file.tar 
quit
_FTPEND

Thursday, February 9, 2012

R code to fit varying intercepts with nested structure linear model


## sim some data and fit an varying intercept model
##

<- 1:3
<- 1:4

intercepts <- rnorm(12) 
intnames <- outer(a, b, FUN = function(x, y) { paste(x, y, sep = ':')} )
names(intercepts) <- as.vector(t(intnames)) 

<- 10000; 
<- round(abs(rnorm(N)) * 10, 2)
noise <- rnorm(N); 
ai <- sample(a, N, replace = TRUE) 
bi <- sample(b, N, replace = TRUE) 
beta <- 4; 
<- intercepts[ai * 4 + bi - 4] + x * beta + noise 

ai <- as.factor(ai)
bi <- as.factor(bi)
table(ai:bi) 
print(intercepts) 
# varying intercepts model specification
fita <- lm(y ~ -1 + ai : bi + x) 
# in R lm and lmer's model specification, A * B = A + B + A : B
# where A : B is the interaction of A and B. So in the above,
# ai : bi is used to specify varying intercepts and -1 to
# get rid of the global intercept. 

short name for host under ssh

ssh config:
http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&sektion=5

for example, file ~/.ssh/config, we have 

Host  google