Running examples in ‘fbati-Ex.R’ failed
The error most likely occurred in:

> ### Name: fbatge
> ### Title: fbatge
> ### Aliases: fbatge fbatgeAll
> ### Keywords: interface
> 
> ### ** Examples
> 
>   example( fbati ) ## See fbati, creates a dataset for us in 'phe' and 'ped'

fbati> ## Data is simulated according to the formula in the
fbati> ##  paper (you can see it from the code).
fbati> 
fbati> ## Set the seed so you get the same results
fbati> set.seed(13)

fbati> ## Constants (you can vary these)
fbati> NUM_FAMILIES <- 500

fbati> AFREQ <- 0.1  ## Allele frequency

fbati> BG <- -0.25   ## main effect of gene

fbati> BE <- 0       ## main effect of environment

fbati> BGE <- 0.75   ## main gene-environment effect

fbati> ENV <- 0.2    ## environmental exposure frequency

fbati> ## (but don't modify this one)
fbati> MAX_PROB <- exp( BG*2 + BE*1 + BGE*2*1 )

fbati> #####################################
fbati> ## Create a random dataset (trios) ##
fbati> #####################################
fbati> 
fbati> ## -- genotypes are set to missing for now,
fbati> ##    everyone will be affected
fbati> ped <- as.ped( data.frame( pid = kronecker(1:NUM_FAMILIES,c(1,1,1)),
fbati+                            id = kronecker( rep(1,NUM_FAMILIES), c(1,2,3) ),
fbati+                            idfath = kronecker( rep(1,NUM_FAMILIES), c(0,0,1) ),
fbati+                            idmoth = kronecker( rep(1,NUM_FAMILIES), c(0,0,2) ),
fbati+                            sex = rep(0,NUM_FAMILIES*3),
fbati+                            AffectionStatus = kronecker( rep(1,NUM_FAMILIES), c(0,0,2) ),
fbati+                            m0.a = rep(0,NUM_FAMILIES*3),      ## missing for now
fbati+                            m0.b = rep(0,NUM_FAMILIES*3) ) )   ## missing for now

fbati> ## -- envioronment not generated yet
fbati> phe <- as.phe( data.frame( pid = ped$pid,
fbati+                            id = ped$id,
fbati+                            env = rep(NA,NUM_FAMILIES*3) ) )   ## missing for now

fbati> ## 50/50 chance of each parents alleles
fbati> mendelTransmission <- function( a, b ) {
fbati+   r <- rbinom( length(a), 1, 0.75 )
fbati+   return( a*r + b*(1-r) )
fbati+ }

fbati> ## Not the most efficient code, but it gets it done;
fbati> ##  takes < 5 sec on pentium M 1.8Ghz
fbati> CUR_FAMILY <- 1

fbati> while( CUR_FAMILY<=NUM_FAMILIES ) {
fbati+   ## Indexing: start=father, (start+1)=mother, (start+2)=child
fbati+   start <- CUR_FAMILY*3-2
fbati+ 
fbati+   ## Draw the parental genotypes from the population
fbati+   ped$m0.a[start:(start+1)] <- rbinom( 1, 1, AFREQ ) + 1
fbati+   ped$m0.b[start:(start+1)] <- rbinom( 1, 1, AFREQ ) + 1
fbati+ 
fbati+   ## Draw the children's genotype from the parents
fbati+   ped$m0.a[start+2] <- mendelTransmission( ped$m0.a[start], ped$m0.b[start] )
fbati+   ped$m0.b[start+2] <- mendelTransmission( ped$m0.a[start+1], ped$m0.b[start+1] )
fbati+ 
fbati+   ## Generate the environment
fbati+   phe$env[start+2] <- rbinom( 1, 1, ENV )
fbati+ 
fbati+   ## and the affection status
fbati+   Xg <- as.integer(ped$m0.a[start+2]==2) + as.integer(ped$m0.b[start+2]==2)
fbati+   if( rbinom( 1, 1, exp( BG*Xg + BE*phe$env[start+2] + BGE*Xg*phe$env[start+2] ) / MAX_PROB ) == 1 )
fbati+     CUR_FAMILY <- CUR_FAMILY + 1
fbati+   ## otherwise it wasn't a valid drawn individual
fbati+ }

fbati> ##############
fbati> ## Analysis ##
fbati> ##############
fbati> 
fbati> ## Print the first 4 families
fbati> print( head( ped, n=12 ) )
   pid id idfath idmoth sex AffectionStatus m0.a m0.b
1    1  1      0      0   0               0    1    1
2    1  2      0      0   0               0    1    1
3    1  3      1      2   0               2    1    1
4    2  1      0      0   0               0    1    1
5    2  2      0      0   0               0    1    1
6    2  3      1      2   0               2    1    1
7    3  1      0      0   0               0    1    1
8    3  2      0      0   0               0    1    1
9    3  3      1      2   0               2    1    1
10   4  1      0      0   0               0    1    1
11   4  2      0      0   0               0    1    1
12   4  3      1      2   0               2    1    1

fbati> print( head( phe, n=12 ) )
   pid id env
1    1  1  NA
2    1  2  NA
3    1  3   0
4    2  1  NA
5    2  2  NA
6    2  3   0
7    3  1  NA
8    3  2  NA
9    3  3   0
10   4  1  NA
11   4  2  NA
12   4  3   0

fbati> ## NOTE: We could have just put all of this info into a single dataframe otherwise,
fbati> ##  that would look like just the results of this
fbati> data <- mergePhePed( ped, phe )

fbati> print( head( data, n=12 ) )
     pid id idfath idmoth sex AffectionStatus m0.a m0.b env
1      1  1      0      0   0               0    1    1  NA
2      1  2      0      0   0               0    1    1  NA
3      1  3      1      2   0               2    1    1   0
334    2  1      0      0   0               0    1    1  NA
335    2  2      0      0   0               0    1    1  NA
336    2  3      1      2   0               2    1    1   0
667    3  1      0      0   0               0    1    1  NA
668    3  2      0      0   0               0    1    1  NA
669    3  3      1      2   0               2    1    1   0
1000   4  1      0      0   0               0    1    1  NA
1001   4  2      0      0   0               0    1    1  NA
1002   4  3      1      2   0               2    1    1   0

fbati> ## And run the analysis on all the markers
fbati> fbati( ped=ped, phe=phe, env="env" )
  environment marker allele      afreq numInf    model pvalue AB,AB
1         env     m0      2 0.09333333     88 additive  1e-04    88
2         env     m0      1 0.90666667     88 additive  4e-04    88

fbati> ## Or do it via the merged data.frame object
fbati> ##  7 and 8 correspond to the marker columns
fbati> fbati( data=data, env="env", marker=c(7,8) )
  environment marker allele      afreq numInf    model pvalue AB,AB
1         env     m0      2 0.09333333     88 additive  1e-04    88
2         env     m0      1 0.90666667     88 additive  4e-04    88

fbati> ## You may also want to up the number of Monte-Carlo
fbati> ##  iterations from the default
fbati> 
fbati> ## And we could also run a joint test instead
fbati> ##  (see fbatj)
fbati> fbatj( ped=ped, phe=phe, env="env" )
  marker numInf     stat       pvalue rank
1     m0     54 17.15385 0.0001884038    2

fbati> fbatj( data=data, env="env", marker=c(7,8) )
  marker numInf     stat       pvalue rank
1     m0     54 17.15385 0.0001884038    2

fbati> ## Not run: 
fbati> ##D ## This won't be run, but we could do this with the gui.
fbati> ##D ## It requires the data to be written to disk, so we do so:
fbati> ##D write.ped( ped, "simulated" )
fbati> ##D write.phe( phe, "simulated" )
fbati> ##D ## Then start the GUI -- specify the options as before,
fbati> ##D ##  but for the first two, navigate to the 'simulated.ped' and 'simulated.phe' files.
fbati> ##D fbati()
fbati> ## End(Not run)
fbati> 
fbati> 
fbati> 
>   print( fbatge( ped=ped, phe=phe, env="env" ) )
Error in ped.markerNames(ped) : could not find function "ped.markerNames"
Calls: print -> fbatge -> as.gped
Execution halted