1

I am using MCMCglmm package for generalized linear models. Here are my codes and Final_KIRC_met_act includes pathway scores.

> g<-factor(g, levels=c("MALE","FEMALE"), labels=c(0,1))

> data<-cbind(Final_KIRC_met_act, g)

> data2<-as.data.frame(data)

> head(data2)

             M00001_C00022 M00002_C00022 M00003_C05345 M00004_R02739 M00006_C00199 M00007_C00117 M00009_R00342,R00361
TCGA-6D-AA2E  0.0001438301   0.004029765  0.0002290721  0.0004104972    0.02246794     0.1467008         1.703306e-04
TCGA-A3-3306  0.0001619469   0.003969637  0.0001457640  0.0003494476    0.02197964     0.1260309         9.222817e-05
TCGA-A3-3307  0.0001403204   0.003569992  0.0002373946  0.0003091625    0.02021713     0.1249811         8.646219e-05
TCGA-A3-3308  0.0001105221   0.002883832  0.0001282293  0.0003436197    0.02256994     0.1214749         9.128686e-05
TCGA-A3-3311  0.0001468475   0.003847826  0.0001714674  0.0003078584    0.02247165     0.1173292         9.803733e-05
TCGA-A3-3313  0.0001223408   0.003363544  0.0002314604  0.0002821620    0.01696295     0.1273991         1.616942e-04
...

When I applied the MCMCglmm I will get the error below:

> model<-MCMCglmm(Final_KIRC_met_act~g,data=data2)

Error in `[<-.data.frame`(`*tmp*`, , response.names, value = c(0.000143830145988399,  : 
  missing values are not allowed in subscripted assignments of data frames

But when I control my data there is no missing values

> table(is.na(Final_KIRC_met_act))

FALSE 
50496

> table(is.na(g))

FALSE 
  526 

 table(is.na(data2))

FALSE 
51022 

Can anyone help me?

Roland
  • 127,288
  • 10
  • 191
  • 288
Elen
  • 21
  • 1
  • 2
  • 8
  • 1
    From the documentation: "multiple responses are passed as a matrix using `cbind`". I don't see `cbind` in your formula. – Roland Aug 21 '17 at 09:01
  • Thank you Roland. I have tried using cbind for some variables from Final_KIRC_met act but unfortunately I get the same error – Elen Aug 21 '17 at 09:14
  • 1
    Without a minimal reproducible example we can't help you. See https://stackoverflow.com/a/5963610/1412059. – Roland Aug 21 '17 at 09:27
  • 1
    The problem is not with missing values in your data but in indices that are used to access a subset of the data in the function – F. Privé Aug 21 '17 at 09:28

2 Answers2

1

When you use the MCMCglmm, you have to attach your dataset first, then, build your model.

For example: When I don't use the attach command, I get:

bayes_reg <- MCMCglmm(train$SalePrice ~-train$PoolQC ,data=train)

Error in [<-.data.frame(*tmp*, , response.names, value = c(12.247694320221, : missing values are not allowed in subscripted assignments of data frames

Then, I use the attach:

attach(train) bayes_reg <- MCMCglmm(SalePrice ~-PoolQC ,data=train)

The code runs successfully.

Diego Wang
  • 21
  • 5
0

As @Roland pointed out in his comment, "multiple responses are passed as a matrix using cbind", due to R's non-standard evaluation this is not the same as supplying just the response matrix as a variable. However, you can use this language feature yourself to construct an appropriate call:

responses = parse(text=paste0("cbind(",paste(colnames(Final_KIRC_met_act ), collapse = ","),")"))[[1]]

model <- eval(substitute(
    MCMCglmm(responses ~ g, data = data2), 
    list(responses=responses)
))

There might be more problems with your call, e.g. I think you also need to supply vector for the family parameter. But for them there will be more informative error messages. A minimal working example would have allowed to resolve these too.

jan-glx
  • 7,611
  • 2
  • 43
  • 63