Hi,

I had a problem with the lmekin() in kinship package: 
lmekin() can not be wrapped into another function

library(kinship)
#creat an example dataset
xx<-rnorm(100)
yy<-rnorm(100)
id<-1:100  
test.dat<-as.data.frame(cbind(xx,yy,id))
rm(xx,yy,id)
a<-bdsmatrix(rep(10,10),rep(block,10),dimnames=list(c(1:100),c(1:100)))  
#100x100 block (n=10) diagonal matrix to indicate the correlation between the 
100 observations

#this works, call lmekin directly
lmekin(yy~xx,random=~1|id,data=test.dat,varlist=a,na.action=na.omit)

#this doesn't work, wrap into another function

fo<-function(x,y,z,data)lmekin(y~x,random=~1|z,data=test.dat,varlist=a,na.action=na.omit)
fo(xx,yy,id)

Error in eval(expr, envir, enclos) : Object "y" not found

I did line by line debug within lmekin(). I found the problem was from 
line #25
m <- eval(m, sys.parent())

Here is the print(m) result before this line
[1] model.frame(data = data, na.action = na.omit, formula = y ~ x +z)

I will appreciate anyone help me figure out why data cannot be passed 
to the arguments when lmekin() is wrapped into another function? And what can 
be done
to fix it? 


Thanks

Qiong

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to