[R] Incidence Function Model in R help
David Winsemius
dwinsemius at comcast.net
Sun Jun 21 23:55:48 CEST 2009
On Jun 21, 2009, at 2:47 PM, steve kimble wrote:
> All:
> Though I am fairly new to R, I am trying to work my way through J
> Oksanen's
> "Incidence Function Model in R" and can't get past some error with
> my glm
> arguments. I'm getting through
>
>> attach(amphimedon_compressa)
>>
> plot(x.crd,y.crd,asp=1,xlab="Easting",ylab="Northing",pch=21,col=p
> +1,bg=5*p)
>> d<-dist(cbind(x.crd,y.crd))
>> alpha<-1
>> edis<-as.matrix(exp(-alpha*d))
>> diag(edis)<-0
That line may be unnecessary. I think as.matrix already did that:
> x <- matrix(rnorm(9), nrow=3)
> m <- as.matrix(dist(x))
> m
1 2 3
1 0.000000 3.287444 2.271032
2 3.287444 0.000000 2.459300
3 2.271032 2.459300 0.000000
>> edis<-sweep(edis,2,A,"*")
>> S<-rowSums(edis[,p>0])
>> mod<-glm( p~offset(2*log(S)) + log(A), family=binomial)
>
> before I get the error message
>
> Error: NA/NaN/Inf in foreign function call (arg 4)
Can't you see that asking people to guess what might be the problem
when the data is left as an unknown is an unreasonable request. This
part of the "Standard Message" ...
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
... means that not just the commands but also data need to be
provided, either as a toy dataset, or a small sample, or at a location
where it can be accessed.
>
> which is an argument concerning weights, an optional vector, whose
> choices
> are NULL or a numeric vector. When I define weights=1, I get
>
> Error in model.frame.default(formula = p ~ offset(2 * log(S)) +
> log(A), :
> variable lengths differ (found for '(weights)')
Just a guess, weights needs to be as long as the other vectors being
given to the model?
>
> and when I define weights<=1, I get
That one is easy. You are using a comparison operator "<=", thinking
it is the assignment operator "<-"
>
> Error in weights <= 1 :
> comparison (4) is possible only for atomic and list types
>
> Any suggestions?
>
> Thanks!
> Steve
>
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list