augPred and missing data error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

augPred and missing data error

PIKAL Petr
Dear all

I would like to ask if augPred is able to handle missing values. Here is
example with below data "test".  I read augPred documentation and nothing is
mentioned that fitted object from data with missing values cannot be used in
augPred. Maybe it would be worth to add something.

Or I just did not read it correctly and with some special setting augPred
can handle such objects?

Cheers
Petr Pikal

test data below

test.g <- groupedData(vodivnorm~cas|variable, data=test)
fit <- nlsList(vodivnorm ~ SSbiexp(cas, Al, lrc1, A2, lrc2), data=test.g)
Error in na.fail.default(data) : missing values in object

na.exclude (or na.omit) works as expected

fit <- nlsList(vodivnorm ~ SSbiexp(cas, Al, lrc1, A2, lrc2), data=test.g,
na.action=na.exclude)

However augPred results in error
plot(augPred(fit))
Error in tapply(object[[nm]], groups, FUN[["numeric"]], ...) :
  arguments must have same length

The workaround is to discard missing values **before** the fit.

test.gs <- test.g[complete.cases(test.g),]
fit <- nlsList(vodivnorm ~ SSbiexp(cas, Al, lrc1, A2, lrc2), data=test.gs)
plot(augPred(fit))

test <- structure(list(cas = c(0L, 10L, 20L, 30L, 40L, 50L, 60L, 65L,
70L, 72L, 76L, 80L, 90L, 100L, 110L, 120L, 123L, 130L, 140L,
146L, 0L, 10L, 20L, 30L, 40L, 50L, 60L, 65L, 70L, 72L, 76L, 80L,
90L, 100L, 110L, 120L, 123L, 130L, 140L, 146L, 0L, 10L, 20L,
30L, 40L, 50L, 60L, 65L, 70L, 72L, 76L, 80L, 90L, 100L, 110L,
120L, 123L, 130L, 140L, 146L), variable = structure(c(9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L), .Label = c("vod02", "vod03", "vod04", "vod10",
"vod11", "vod12", "vod08", "vod09", "vod05", "vod06", "vod07"
), class = "factor"), value = c(45.78, 9.404, 3.915, 2.074, 1.049,
0.502, 0.248, NA, 0.159, NA, NA, 0.124, 0.11, 0.104, 0.098, NA,
NA, NA, NA, NA, 45.75, 12.56, 4.125, 2.204, 1.158, 0.653, 0.381,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 47.22, 15.45,
6.337, 2.736, 1.107, 0.475, 0.241, NA, 0.187, NA, NA, 0.167,
0.154, 0.147, 0.134, 0.124, NA, 0.114, 0.103, 0.098), vodivnorm = c(1,
0.205417212756662, 0.0855176933158585, 0.045303626037571,
0.0229139362166885,
0.0109654871122761, 0.0054172127566623, NA, 0.00347313237221494,
NA, NA, 0.00270860637833115, 0.00240279598077763, 0.00227173438182612,
0.00214067278287462, NA, NA, NA, NA, NA, 1, 0.274535519125683,
0.0901639344262295, 0.0481748633879781, 0.0253114754098361,
0.0142732240437158,
0.00832786885245902, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, 1, 0.327191867852605, 0.134201609487505, 0.0579415501905972,
0.0234434561626429, 0.0100592969080898, 0.00510376958915714,
NA, 0.00396018636171114, NA, NA, 0.00353663701821262, 0.00326132994493859,
0.0031130876747141, 0.00283778060144007, 0.00262600592969081,
NA, 0.00241423125794155, 0.00218127911901737, 0.00207539178314274
)), row.names = c("vod05.161", "vod05.162", "vod05.163", "vod05.164",
"vod05.165", "vod05.166", "vod05.167", "vod05.168", "vod05.169",
"vod05.170", "vod05.171", "vod05.172", "vod05.173", "vod05.174",
"vod05.175", "vod05.176", "vod05.177", "vod05.178", "vod05.179",
"vod05.180", "vod06.181", "vod06.182", "vod06.183", "vod06.184",
"vod06.185", "vod06.186", "vod06.187", "vod06.188", "vod06.189",
"vod06.190", "vod06.191", "vod06.192", "vod06.193", "vod06.194",
"vod06.195", "vod06.196", "vod06.197", "vod06.198", "vod06.199",
"vod06.200", "vod07.201", "vod07.202", "vod07.203", "vod07.204",
"vod07.205", "vod07.206", "vod07.207", "vod07.208", "vod07.209",
"vod07.210", "vod07.211", "vod07.212", "vod07.213", "vod07.214",
"vod07.215", "vod07.216", "vod07.217", "vod07.218", "vod07.219",
"vod07.220"), class = "data.frame")

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.