Hi everyone, I am new to R and keep getting the message Error in as.vector(x, mode) while trying to run nlsystemfit. Below is my exact code. The data is in Stata format because I only recently swapped to R and am trying to compare results from Stata to make sure I know what is going on. I have searched google and read sever R-help articles with this error. They all say the problem is to do with attach(). I haven't used attach() as far as I can tell. However it does seem to be a problem with reading the data. I sometimes get a problem with "masking". Finally, when I ran the example in the systemfit documentation for nlsystemfit everything went fine. The major structural difference I can see between the codes is they use data() where as I do not. Any advice would be truly appreciated. library(systemfit) library(foreign) auto74 <- read.dta("auto74.dta") eqWeight <- weight ~ a0 + a1*mpg + a2*price + a3*trunk eqLength <- length ~ b0 + b1*mpg + b2*price + b3*trunk model <- list(eqWeight, eqLength) start.values <- c(a0=0, a1=0, a2=0, a3=0, b0=0, b1=0, b2=0, b3=0) nlsystemfit("OLS", model, start.values, data = auto) Error in as.vector(x, mode) : cannot coerce type 'builtin' to vector of type 'any' Kind regards, Alex Olssen
Hi Alex! On 10 March 2011 09:46, Alex Olssen <alex.olssen at gmail.com> wrote:> Hi everyone, > > I am new to R and keep getting the message > Error in as.vector(x, mode) > while trying to run nlsystemfit. > > Below is my exact code. ?The data is in Stata format because I only > recently swapped to R and am trying to compare results from Stata to > make sure I know what is going on. > I have searched google and read sever R-help articles with this error. > ?They all say the problem is to do with attach(). ?I haven't used > attach() as far as I can tell. ?However it does seem to be a problem > with reading the data. ?I sometimes get a problem with "masking". > Finally, when I ran the example in the systemfit documentation for > nlsystemfit everything went fine. ?The major structural difference I > can see between the codes is they use data() where as I do not. > > Any advice would be truly appreciated. > > library(systemfit) > library(foreign) > auto74 <- read.dta("auto74.dta")Please provide a *reproducible* example. We cannot reproduce your example, because we do not have the file "auto74.dta".> eqWeight <- weight ~ a0 + a1*mpg + a2*price + a3*trunk > eqLength <- length ~ b0 + b1*mpg + b2*price + b3*trunk > model <- list(eqWeight, eqLength) > start.values <- c(a0=0, a1=0, a2=0, a3=0, b0=0, b1=0, b2=0, b3=0) > nlsystemfit("OLS", model, start.values, data = auto) > > Error in as.vector(x, mode) : > ?cannot coerce type 'builtin' to vector of type 'any'I guess that the starting values cause this error. The documentation says: "startvals: a list of starting values for the coefficients." Note, it should be a *list*. Please note that the nlsystemfit() function (in contrast to the systemfit() function) is still under development and has convergence problems rather often. Best regards, Arne -- Arne Henningsen http://www.arne-henningsen.name
Dear Alex On 10 March 2011 20:31, Alex Olssen <alex.olssen at gmail.com> wrote:> I find it hard to provide a reproducible version of this error. > When I use the exact same procedure but get data from data() > everything works fine. > I.e., I do not think the startvals are the problem - in fact I copied > the syntax for the startvals directly from the example in the > documentation which does work. > > The following code is very similar to my code above. > The important difference is the way the data is obtained. > This code works. > > library(systemfit) > library(foreign) > data("mtcars") > eqDrat <- drat ~ a0 + a1*mpg + a2*qsec > eqWt <- wt ~ b0 + b1*mpg + b2*qsec > model <- list(eqDrat, eqWt) > start.values <- c(a0=0.5, a1=0.5, a2=0, b0=0.5, b1=0.5, b2=0) > nlsystemfit("OLS", model, start.values, data = mtcars) > > I think I could solve my problem if I could use my data through data() > instead of through read.table() > Does anyone know if this is possible?So, the problem seems to come from your data set. As we do not have your data file, we cannot really help you with this. The command for reading the data (e.g. read.dta(), read.table(), or read.csv()) -- of course -- depends on the file format. /Arne -- Arne Henningsen http://www.arne-henningsen.name