3
$\begingroup$

As the R very beginner I'd like to ask if anyone could help me with the following problem?

library(foreign)
reg1 <- read.spss("URL of the spss file")
library(nlme)
model1 <- gls(v1 ~ x1 + x2 + x3 + x4 + x5 + x6, correlation=corARMA(p=1), data=reg1)

Error in eval(expr, envir, enclos) : object 'v1' not found

All the variables v1 to x6 are present in the spss file. Thanks in advance for help.

Thanks Nick. I can't share the file. I tried the procedure, but I got the similar result:

library(foreign)

library(nlme)

reg1 <- read.spss("URL", to.data.frame=TRUE)

class(reg1) #check that it is indeed a data.frame [1] "data.frame"

colnames(reg1) #check that all column names are properly imported ....

[17] "x1" "x2" "x3" "x4"
[21] "x5" "x6"

....

[97] "...." "v1" "...." "...."

....

model1 <- gls(v1 ~ x1 + x2 + x3 + x4 + x5 + x6, correlation=corARMA(p=1), data=reg1)

Error in eval(expr, envir, enclos) : object 'img4' not found

$\endgroup$
  • $\begingroup$ The error has indeed changed (v1 -> img4). It is not clear where this last error comes from, but: re-run your code, and right after you get the error, run traceback(). This might give you/us a hint on what's wrong (as it displays the call stack at the time of the error). $\endgroup$ – Nick Sabbe Jul 12 '11 at 12:32
  • $\begingroup$ Well, actually I've 'debranded' the variables' names (so as the brands were impossible to identify). img4 is not a brand, but I also substituted the name of this variable for v1 writing my post. I just forgot to change it in the message about error. So, basically, the error has not changed. $\endgroup$ – robo Jul 12 '11 at 14:11
  • 1
    $\begingroup$ It may be better to either show the actual code you ran, to avoid these kinds of confusions (all too often, an assumption during the 'translation' turns out to be the real culprit). Either way: I cannot debug this since I can't run it, so your only option is to use the traceback, or do actual debugging. $\endgroup$ – Nick Sabbe Jul 12 '11 at 14:27
6
$\begingroup$

From the documentation of ?gls: data: an optional data frame

In relation, the documentation of ?read.spss shows a parameter to.data.frame, whose default is FALSE, so typically reg1 will be a list instead of a data.frame.

The code you provided is not useful for testing on my system (as you do not provide the actual dataset), but this will probably work (disregarding library statements):

reg1 <- read.spss("URL of the spss file", to.data.frame=TRUE)
class(reg1) #check that it is indeed a data.frame
colnames(reg1) #check that all column names are properly imported
model1 <- gls(v1 ~ x1 + x2 + x3 + x4 + x5 + x6, correlation=corARMA(p=1), data=reg1)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.