[R] Incidence Function Model in R help
David Winsemius
dwinsemius at comcast.net
Sun Jul 5 01:47:24 CEST 2009
On Jul 4, 2009, at 6:15 PM, sjkimble wrote:
>
> R Help:
>
> Another question:
>
> My data are:
>
> x.crd y.crd A p
> 1 361762 1034052 3.414 0
> 2 361763 1034071 94.169 0
> 3 370325 1027277 127.642 1
> 4 370416 1027166 127.961 0
> 5 370471 1027148 1804.846 1
> 6 369050 1031312 1790.493 0
> 7 370799 1026557 103.994 0
> 8 370908 1026354 199.103 0
> 9 361562 1034311 2047.637 0
> 10 365437 1022188 1622678.961 0
> 11 347047 1025334 21.169 0
> 12 349186 1024441 408556.801 0
>
> and the code, complete with error message, is:
>
>> amphimedon_compressa<-read.table(file.choose(),header=T)
>> attach(amphimedon_compressa)
>> d<-dist(cbind(x.crd,y.crd))
>> alpha<-1
>> edis<-as.matrix(exp(-alpha*d))
>> edis<-sweep(edis,2,A,"*")
>> S<-rowSums(edis[,p>0])
>> mod<-glm(p~offset(2*log(S))+log(A),family=binomial)
> Error: NA/NaN/Inf in foreign function call (arg 4)
>>
>
> R Help tells me that argument 4 for glm is "weights an optional
> vector of
> ‘prior weights’ to be used in the fitting process. Should be NULL or a
> numeric vector." I am unsure why this optional vector needs to
> employed and
> how to correct the NA/NaN/Inf error if in fact it is necessary.
It is not the reason for your error; weights do not need to be
employed. When I look at the object S, I see about half of them are
zeroes. The "expectation" of a binomial model is for the LHS of the
formulat to be either a 1/0 vector or something of the form
cbind(events, non_events). You have satisfied that expectation with p
but there are only 2 such cases. It seems unreasonable to my thinking
to expect that a logistic regression model can deliver sensible output
from only 2 events. And that holds doubly (or perhaps infinitely?)
true when you are starting out with half of your covariates equal to
log(0) = -Inf.
--
DW
>
> Details:
> Reference: Incidence Function Model in R, J Oksanen, 2004, available
> at:
> cc.oulu.fi/~jarioksa/opetus/openmeta/metafit.pdf
> OS: Mac OS 10.5.7
> R version: 2.9.0
> GUI: 1.28 Tiger build 32-bit
> seesionInfo output:
> Error in system.file(package = pkg, lib.loc = lib.loc) :
> 'package' must be of length 1
> In addition: Warning messages:
> 1: In if (pkg == "base") pkgpath <- file.path(.Library, "base") else
> if
> ((envname <- paste("package:", :
> the condition has length > 1 and only the first element will be used
> 2: In if ((envname <- paste("package:", pkg, sep = "")) %in%
> search()) { :
> the condition has length > 1 and only the first element will be used
> 3: In if (file.access(file.path(lib, pkg), 5) == 0L) { :
> the condition has length > 1 and only the first element will be used
>
> Thanks,
> Steve Kimble
> Department of Forestry and Natural Resources
> Purdue University
> West Lafayette, IN 47907
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list