[R] phantom NA/NaN/Inf in foreign function call (or something altogether different?)
R. Michael Weylandt
michael.weylandt at gmail.com
Tue Jul 31 16:23:11 CEST 2012
On Tue, Jul 31, 2012 at 5:26 AM, Cecile De Cat <c.decat at leeds.ac.uk> wrote:
> Dear experts,
>
> Please forgive the puzzled title and the length of this message - I
> thought it would be best to be as complete as possible and to show the
> avenues I have explored.
>
> I'm trying to fit a linear model to data with a binary dependent
> variable (i.e. Target.ACC: accuracy of response) using lrm, and
> thought I would start from the most complex model (of which
> "sample1.lrm1" is a trimmed version). I got the error shown below.
> (sample1 is available at http://tinyurl.com/bwqq7ya)
>
> For info:
>
>> str(sample1)
> 'data.frame': 14022 obs. of 5 variables:
> $ Target.ACC : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
> $ Word.Order : Factor w/ 2 levels "HeadMod*","ModHead": 1 1 1 1 1 1 1 1 1 1 ...
> $ Target.RESP: Factor w/ 2 levels "1","2": 2 2 2 2 2 2 2 2 2 2 ...
> $ L1 : Factor w/ 3 levels "English","German",..: 2 2 2 2 2 2
> 2 2 2 2 ...
> $ Relation : Factor w/ 4 levels "For","From","MadeOf",..: 1 1 1 1 1
> 1 1 1 1 1 ...
>
> Commands and error message:
>
>> sample1.dd = datadist(sample1)
>> options(datadist="sample1.dd")
>> sample1.lrm = lrm(Target.ACC ~ (L1 + Relation + Target.RESP + Word.Order)^2, sample1, x=T, y=T)
> Error in lrm(Target.ACC ~ (L1 + Relation + Target.RESP + Word.Order)^2, :
> Unable to fit model using “lrm.fit”
>
> So I tried to narrow down the error by looking at all the combinations
> manually, and the problem appears to be specifically with the
> interaction between Word.Order and Target.RESP. Models including
> interaction of these variables with other variables (e.g. L1,
> Relation) can be fitted without problem.
>
>> sample1.lrm = lrm(Target.ACC ~ (Target.RESP + Word.Order)^2, sample1, x=T, y=T)
> Error in lrm(Target.ACC ~ (Target.RESP + Word.Order)^2, dat, x = T, y = T) :
> Unable to fit model using “lrm.fit”
>
> unproblematic:
>> sample1.lrm1 = lrm(Target.ACC ~ (L1 + Relation + Target.RESP)^2, sample1, x=T, y=T)
>> sample1.lrm2 = lrm(Target.ACC ~ (L1 + Relation + Word.Order)^2, sample1, x=T, y=T)
>
> When running the problematic analysis on a smaller sample of the same
> data, I get a different (more precise?) error message:
>
>> sample2 <- sample1[1:500,]
>> sample2.lrm = lrm(Target.ACC ~ (Target.RESP + Word.Order)^2, sample2, x=T, y=T)
> Error in fitter(X, Y, penalty.matrix = penalty.matrix, tol = tol,
> weights = weights, :
> NA/NaN/Inf in foreign function call (arg 1)
>
> But I cannot find any NA in the data:
>> table(complete.cases(sample2))
> TRUE
> 500
Not a complete answer, but complete.cases() won't pick up +/- Inf.
x <- data.frame(1:5, letters[1:5], c(NA, NaN, Inf, -Inf, 0))
x[complete.cases(x),]
You could perhaps use something like
sapply(x, is.finite)
with any()/all() to hunt them down (is.finite requires "real" numbers:
it gives false for NA, NaN, Inf, and -Inf).
Best,
Michael
>
> Some portions of the data don't appear to contain any of the offending "bit":
>> sample3 <- sample1[12500:13000,]
>> sample3.lrm = lrm(Target.ACC ~ (Target.RESP + Word.Order)^2, sample3, x=T, y=T)
>
>
> Could one of your shine your light on this puzzle, please? If that
> includes pointing me towards some background reading, that would be
> great too.
>
> Many thanks in advance.
>
> Cecile De Cat
> Linguistics - University of Leeds
>
> ______________________________________________
> R-help at r-project.org 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.
More information about the R-help
mailing list