jomo imputation_error

Hi,

I am trying to run jomo imputation with clustered data and I am getting error message (see below). My dataset is test_impute which is open in the R environment, but still the error message below says object not found. Could you please help me? I have a tight deadline.

library(jomo)

Y<-test_impute[,c("gait","peakflow")]
#> Error in eval(expr, envir, enclos): object 'test_impute' not found
clus<-test_impute[,c("country")]
#> Error in eval(expr, envir, enclos): object 'test_impute' not found
v<- test_impute[,c("sex", "ability","grip","bmic")]
#> Error in eval(expr, envir, enclos): object 'test_impute' not found
cov<-na.omit(v)
#> Error in na.omit(v): object 'v' not found
X=data.frame(rep(1,117982),cov[,c("sex", "ability","grip","bmic")])
#> Error in cov[, c("sex", "ability", "grip", "bmic")]: object of type 'closure' is not subsettable
colnames(X)<-c("sex", "ability","grip","bmic")
#> Error in colnames(X) <- c("sex", "ability", "grip", "bmic"): object 'X' not found
Z<-data.frame(rep(1,117982))
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-matrix(diag(1,2),20,2,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(50);
nbetween=as.integer(20);
nimp=as.integer(5);
l2cov.prior=diag(1,5);
a=3

Finally we run either the model with fixed or random cluster-specific covariance matrices:

imp<-jomo1ranconhr(Y,X,Z,clus,beta.start,u.start,l1cov.start, l2cov.start,
l1cov.prior,l2cov.prior,nburn,nbetween,nimp,meth="fixed")
#> Error in jomo1ranconhr(Y, X, Z, clus, beta.start, u.start, l1cov.start, : object 'X' not found

1 Like

Thanks for the complete code. For the future, the preferred format is a reproducible example, called a reprex.

The error messages tell the story: X isn't found because you can't subset a closure (i.e)., function).

cov[, c("sex", "ability", "grip", "bmic")]

will never work. This is why you should never use reserved names like cov. Always check by just entering it

cov

before trying to assign an object to it.

cov<-na.omit(v)

If v had been found, you might have been able to skate by.

The troubles begin, however, with test_impute. How have you satisfied yourself that it actually is in the namespace?

Dear sir, thank you for a quick feedback. How do I fix the object not found error?

1 Like
ls()

will show you all the objects in your current environment and

sessionInfo()

will show you all the packages you have loaded.

Hi sir, I am able to see my dataset with I type in Is(). But I have no clue about why this package s showing the error message.

library(jomo)
data(share)
#> Warning in data(share): data set 'share' not found
Y<-data.frame(share[,c("gait","peakflow")])
#> Error in data.frame(share[, c("gait", "peakflow")]): object 'share' not found
clus<-share[,c("country")]
#> Error in eval(expr, envir, enclos): object 'share' not found
X=data.frame(rep(1,206932),share[,c("sex", "ability","grip","bmic")])
#> Error in data.frame(rep(1, 206932), share[, c("sex", "ability", "grip", : object 'share' not found
colnames(X)<-c("sex", "ability","grip","bmic")
#> Error in colnames(X) <- c("sex", "ability", "grip", "bmic"): object 'X' not found
Z<-data.frame(rep(1,117982))
beta.start<-matrix(0,2,2)
u.start<-matrix(0,10,2)
l1cov.start<-matrix(diag(1,2),20,2,2)
l2cov.start<-diag(1,2)
l1cov.prior=diag(1,2);
nburn=as.integer(50);
nbetween=as.integer(20);
nimp=as.integer(5);
l2cov.prior=diag(1,5);
a=3

Finally we run either the model with fixed or random cluster-specific covariance matrices:

imp<-jomo1ranconhr(Y,X,Z,clus,beta.start,u.start,l1cov.start, l2cov.start,
l1cov.prior,l2cov.prior,nburn,nbetween,nimp,meth="fixed")
#> Error in jomo1ranconhr(Y, X, Z, clus, beta.start, u.start, l1cov.start, : object 'X' not found

Can you see share

data(share)
#> Warning in data(share): data set 'share' not found

Yes, I can see the dataset. But the command is showing error message that object is not found

yes, I can see share

What happens when you just type

share

I get the view of the dataset as displayed below

share

A tibble: 206,932 x 68

mergeid hhid1 country wave_id agew1 agew2 agew3 agew4 agew5 agew6 agew7 sex
<dbl+lb>
1 AT-000~ AT-0~ 11 [Aus~ 1 52 55 NA NA NA NA NA 1
2 AT-000~ AT-0~ 11 [Aus~ 1 49 52 NA NA NA NA NA 2
3 AT-000~ "" 11 [Aus~ 1 NA NA NA NA 80 NA NA 2
4 AT-000~ "" 11 [Aus~ 4 NA NA NA 59 61 63 NA 2
5 AT-001~ "" 11 [Aus~ 4 NA NA NA 72 74 76 78 2
6 AT-001~ "" 11 [Aus~ 4 NA NA NA 59 61 63 65 2
7 AT-001~ "" 11 [Aus~ 4 NA NA NA 60 62 64 66 1
8 AT-001~ AT-0~ 11 [Aus~ 1 61 64 NA NA NA NA NA 2
9 AT-001~ AT-0~ 11 [Aus~ 1 56 59 NA NA NA NA NA 1
10 AT-001~ "" 11 [Aus~ 1 NA 49 NA NA NA NA NA 2

Great, making progress.

The data() function is used to open a built in data set.

Does

Y<-data.frame(share[,c("gait","peakflow")])

now work?

Thanks a lot. It worked :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.