Dear list members. I have problems with the usage of cv.glm from the boot package. Here are some parts of the script I wanted to use: data <- read.table("selected_2D.csv", header=TRUE, sep=",") ? glm.fitted <- glm("ydata$ y ~ 1 + density + vsurf_ID6 + vsurf_S ", data=data) error <- cv.glm(data=data, glm.fitted, K=6) ydata$y is a separate data set, where I take my independent data from. I build an equation with some of the columns in data. Then I generate the generalized linear model, which works. But when I try to run the last line ? the cv.glm function, I get the following error message: Error in model.frame.default(formula = eqfull, data = list(vsurf_ID6 = c(2.4599824, : variable lengths differ (found for 'density') I fear I don't get the meaning of the error message at all. The length of the data columns are all equal. Any help would be kindly appreciated! Best wishes, Markus
Who said the variables were all in the data frame? See this All the variables in 'formula', 'subset' and in '...' are looked for first in 'data' and then in the environment of 'formula' (see the help for 'formula()' for further details) and collected into a data frame. Now ydata$y is not in the data frame ... so try putting it there. On Tue, 20 Jan 2009, Markus M?hlbacher wrote:> Dear list members. > > I have problems with the usage of cv.glm from the boot package. Here are some parts of the script I wanted to use: > > data <- read.table("selected_2D.csv", header=TRUE, sep=",") > ? > glm.fitted <- glm("ydata$ y ~ 1 + density + vsurf_ID6 + vsurf_S ", data=data) > error <- cv.glm(data=data, glm.fitted, K=6) > > ydata$y is a separate data set, where I take my independent data from. I build an equation with some of the columns in data. Then I generate the generalized linear model, which works. But when I try to run the last line ? the cv.glm function, I get the following error message: > > Error in model.frame.default(formula = eqfull, data = list(vsurf_ID6 = c(2.4599824, : > variable lengths differ (found for 'density') > > I fear I don't get the meaning of the error message at all. The length of the data columns are all equal. Any help would be kindly appreciated! > > Best wishes, > Markus > > > > > ______________________________________________ > 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
> I have problems with the usage of cv.glm from the boot package. Here are some parts of the script I wanted to use: > > data <- read.table("selected_2D.csv", header=TRUE, sep=",") > ? > glm.fitted <- glm("ydata$ y ~ 1 + density + vsurf_ID6 + vsurf_S ", data=data) > error <- cv.glm(data=data, glm.fitted, K=6) > > ydata$y is a separate data set, where I take my independent data from. I build an equation with some of the columns in data. Then I generate the generalized linear model, which works. But when I try to run the last line ? the cv.glm function, I get the following error message:You are going to have to merge that variable into "data". The formula interface can't really cope with it otherwise. As an alternative, the train function in caret can do the same thing as cv.glm (with a few more options). See http://www.jstatsoft.org/v28/i05 for more information. Max
Hi all, How would you create a list of data.frames within a loop, then bind all the elements of the list using rbind? take this example of matrices with differing numbers of rows for(i in 1:3){ assign(paste("s",i, sep=""),matrix(data = NA, nrow = i, ncol = 3, byrow = FALSE, dimnames = NULL)) } s1 s2 s3 I want to bind all the matrices at the end with do.call(rbind...) rather than listing all the elements manually with rbind(s1,s2,s3...) and so on. thanks in advance. Simon.
On 1/20/2009 11:34 AM, Simon Pickett wrote:> Hi all, > > How would you create a list of data.frames within a loop, then bind all > the elements of the list using rbind? > > take this example of matrices with differing numbers of rows > > for(i in 1:3){ > assign(paste("s",i, sep=""),matrix(data = NA, nrow = i, ncol = 3, byrow > = FALSE, dimnames = NULL)) > } > s1 > s2 > s3 > > I want to bind all the matrices at the end with do.call(rbind...) > rather than listing all the elements manually with rbind(s1,s2,s3...) > and so on. > > thanks in advance.df.list <- vector("list", 3) # create list for(i in 1:3){df.list[[i]] <- matrix(data = NA, nrow = i, ncol = 3, byrow = FALSE, dimnames = NULL)} do.call(rbind, df.list) # rbind list elements> Simon. > > ______________________________________________ > 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.-- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
On Tue, Jan 20, 2009 at 10:34 AM, Simon Pickett <simon.pickett at bto.org> wrote:> Hi all, > > How would you create a list of data.frames within a loop, then bind all the > elements of the list using rbind? > > take this example of matrices with differing numbers of rows > > for(i in 1:3){ > assign(paste("s",i, sep=""),matrix(data = NA, nrow = i, ncol = 3, byrow > FALSE, dimnames = NULL)) > } > s1 > s2 > s3 > > I want to bind all the matrices at the end with do.call(rbind...) rather > than listing all the elements manually with rbind(s1,s2,s3...) and so on.You might also want to have a look at the plyr package, http://had.co.nz/plyr, which provides general tools for performing these sorts of operations. Hadley -- http://had.co.nz/