Skip to content

random effects model

10 messages · arun, Usha Gurunathan, rex2013

#
HI,

I think I mentioned to you before that when you reshape the 
columns excluding the response variable, response variable gets repeated
(in this case hibp14 or hibp21) and creates the error"


I run your code, there are obvious problems in the code so I didn't reach up to BP.gee

BP_2b<-read.csv("BP_2b.csv",sep="\t")
BP.stack3 <- reshape(BP_2b,idvar="CODEA",timevar="time",sep="_",varying=list(c("Obese14","Obese21"),c("Overweight14","Overweight21")),v.names=c("Obese","Overweight"),times=factor(c(1,2)),direction="long")

BP.stack3 <- transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c("Male","Female")),MaternalAge=factor(MaternalAge,labels=c("39years or less","40-49 years","50 years or older")),Education=factor(Education,labels=c("Primary/special","Started secondary","Completed grade10", "Completed grade12", "College","University")),Birthplace=factor(Birthplace,labels=c("Australia","Other English-speaking","Other")))
?BP.stack3$Sex <- factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)]) 
?BP.sub3a <-? subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na(Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21)))?? 
?nrow(BP.sub3a)
#[1] 3364
?BP.sub5a <- BP.sub3a[order(BP.sub3a$CODEA),] # your code was BP.sub5a <- BP.sub3a[order(BP.sub5a$CODEA),]? 
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ^^^^^ was not defined before
#Next line
BPsub3$Categ[BPsub6$Overweight==1&BPsub3$time==1&BPsub3$Obese==0]<- "Overweight14"? #It should be BP.sub3 and what is BPsub6, it was not defined previously.
#Error in BPsub3$Categ[BPsub6$Overweight == 1 & BPsub3$time == 1 & BPsub3$Obese ==? : 
? #object 'BPsub3' not found






A.K.
#
Hi,

I get the error message.
BP.gee8<- gee(hibp14~time*Categ,data=BPsub7,id=CODEA,family=binomial,corstr="exchangeable",na.action=na.omit)
#Beginning Cgee S-function, @(#) geeformula.q 4.13 98/01/27
#Error in gee(hibp14 ~ time * Categ, data = BPsub7, id = CODEA, family = binomial,? : 
?# rank-deficient model matrix
#Reason I mentioned before.

If you want to see what is happening, you could check this:
dat1<-structure(list(CODEA = c(3L, 7L, 8L), IntScore = c(0L, 0L, 0L
), Obese14 = c(1L, 0L, 1L), Overweight14 = c(1L, 1L, 1L), Obese21 = c(1L, 
1L, 0L), Overweight21 = c(1L, 1L, 0L), hibp14 = c(1L, 0L, 1L), 
??? hibp21 = c(0L, 1L, 0L)), .Names = c("CODEA", "IntScore", 
"Obese14", "Overweight14", "Obese21", "Overweight21", "hibp14", 
"hibp21"), class = "data.frame", row.names = c(NA, -3L))
reshape(dat1,idvar="CODEA",timevar="time",sep="_",varying=list(c("Obese14","Obese21"),c("Overweight14","Overweight21")),v.names=c("Obese","Overweight"),times=factor(c(1,2)),direction="long") #your code
#??? CODEA IntScore hibp14 hibp21 time Obese Overweight?? #here hibp14/hibp21 (response variable) gets replicated i.e. hibp14 values are the same for time==1 and time==2 whereas Obese, Overweigh #values change
#3.1???? 3??????? 0????? 1????? 0??? 1???? 1????????? 1
#7.1???? 7??????? 0????? 0????? 1??? 1???? 0????????? 1
#8.1???? 8??????? 0????? 1????? 0??? 1???? 1????????? 1
#3.2???? 3??????? 0????? 1????? 0??? 2???? 1????????? 1
#7.2???? 7??????? 0????? 0????? 1??? 2???? 1????????? 1
#8.2???? 8??????? 0????? 1????? 0??? 2???? 0????????? 0
A.K.




----- Original Message -----
From: rex2013 <usha.nathan at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, January 14, 2013 3:04 AM
Subject: Re: [R] random effects model

Sorry

I have corrected the mistakes:

BP.stack3 <-
reshape(Copy.of.BP_2,idvar="CODEA",timevar="time",sep="_",varying=list(c("Obese14","Obese21"),c("Overweight14","Overweight21")),v.names=c("Obese","Overweight"),times=factor(c(1,2)),direction="long")
BP.stack3

head(BP.stack3)
tail(BP.stack3)
names(BP.stack3)[c(2,3,4,5,6,7)] <-
c("Sex","MaternalAge","Education","Birthplace","AggScore","IntScore")
names(BP.stack3)[1:7]
BP.stack3 <-
transform(BP.stack3,CODEA=factor(CODEA),Sex=factor(Sex,labels=c("Male","Female")),MaternalAge=factor(MaternalAge,labels=c("39years
or less","40-49 years","50 years or
older")),Education=factor(Education,labels=c("Primary/special","Started
secondary","Completed grade10", "Completed grade12",
"College","University")),Birthplace=factor(Birthplace,labels=c("Australia","Other
English-speaking","Other")))
str(BP.stack3)

table(BP.stack3$Sex)
BP.stack3$Sex <- factor(BP.stack3$Sex,levels=levels(BP.stack3$Sex)[c(2,1)])
levels(BP.stack3$Sex)

BPsub6 <-? subset(BP.stack3,subset=!(is.na(Sex)| is.na(Education)|is.na
(Birthplace)|is.na(Education)|is.na(hibp14)| is.na(hibp21)))
summary(BPsub6)
BPsub6$Categ[BPsub6$Overweight==1&BPsub6$time==1&BPsub6$Obese==0] <-
"Overweight14"
BPsub6$Categ[BPsub6$Overweight==1&BPsub6$time==2&BPsub6$Obese==0] <-
"Overweight21"
BPsub6$Categ[BPsub6$Obese==1&BPsub6$time==1&BPsub6$Overweight==0|BPsub6$Obese==1&BPsub6$time==1&BPsub6$Overweight==1
] <- "Obese14"
BPsub6$Categ[BPsub6$Obese==0&BPsub6$time==1&BPsub6$Overweight==0] <-
"Normal14"
BPsub6$Categ[BPsub6$Obese==0&BPsub6$time==2&BPsub6$Overweight==0] <-
"Normal21"
BPsub6$Categ[BPsub6$Obese==1&BPsub6$time==2&BPsub6$Overweight==0|BPsub6$Obese==1&BPsub6$time==2&BPsub6$Overweight==1]
<- "Obese21"

BPsub6$Categ <- factor(BPsub6$Categ)
BPsub6$time <- factor(BPsub6$time)
summary(BPsub6$Categ)
BPsub7 <- subset(BPsub6,subset=!(is.na(Categ)))
BPsub7 <- BPsub7[order(BPsub7$CODEA),]

BPsub7$hibp14 <- factor(BPsub7$hibp14)
levels(BPsub7$hibp14)
levels(BPsub7$Categ)
names(BPsub7)
head(BPsub7)
tail(BPsub7)
str(BPsub7)

library(gee)
BP.gee8 <- gee(hibp14~ time*Categ, data=BPsub7,id=CODEA,family=binomial,
corstr="exchangeable",na.action=na.omit)
summary(BP.gee8)


## Can you try this out please?? I am not clear where the? defect is with
model? One other previous model had no correlation between obese 14 and
time. With this one, i cannot find anything wrong as such, but still wont
work.

Thanks








On Mon, Jan 14, 2013 at 10:30 AM, arun kirshna [via R] <
ml-node+s789695n4655440h67 at n4.nabble.com> wrote:

            
--
View this message in context: http://r.789695.n4.nabble.com/random-effects-model-tp4654346p4655456.html
Sent from the R help mailing list archive at Nabble.com.
??? [[alternative HTML version deleted]]

______________________________________________
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.
#
HI,

BP_2b<-read.csv("BP_2b.csv",sep="\t")
BP_2bNM<-na.omit(BP_2b)

BP.stack3 <- reshape(BP_2bNM,idvar="CODEA",timevar="time",sep="",varying=list(c("Obese14","Obese21"),c("Overweight14","Overweight21"),c("hibp14","hibp21")),v.names=c("Obese","Overweight","HiBP"),times=factor(c(1,2)),direction="long")
library(car)
BP.stack3$Obese<- recode(BP.stack3$Obese,"1='Obese';0='Not Obese'")
BP.stack3$Overweight<- recode(BP.stack3$Overweight,"1='Overweight';0='Not Overweight'")

library(ggplot2)
ggplot(BP.stack3,aes(x=factor(HiBP),fill=Obese))+geom_bar(position="fill")
ggplot(BP.stack3,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position="fill")

You could try lmer() from lme4.? 
library(lme4)
fm1<-lmer(HiBP~time+(1|CODEA), family=binomial,data=BP.stack3) #check codes, not sure
print(dotplot(ranef(fm1,post=TRUE), 
????????????? scales = list(x = list(relation = "free")))[[1]])
qmt1<- qqmath(ranef(fm1, postVar=TRUE)) 
print(qmt1[[1]])

A.K.
#
Hi AK

Got an error message with

library(ggplot2)>
ggplot(BP.stack1,aes(x=factor(HiBP),fill=Obese))+geom_bar(position="fill")Error
in rename(x, .base_to_ggplot, warn_missing = FALSE) :
  could not find function "revalue">
ggplot(BP.stack1,aes(x=factor(HiBP),fill=Overweight))+geom_bar(position="fill")Error
in rename(x, .base_to_ggplot, warn_missing = FALSE) :
  could not find function "revalue"
I got the dot plot, thanks for that.

I have attached some plots, not sure how to interpret, they had
unusual patterns.Is it because of missing data? I tried removing the
missing data too. They still appeared the same. Do I need to transform
the data?


Thanks in advance.
On Tue, Jan 15, 2013 at 8:54 AM, arun <smartpink111 at yahoo.com> wrote:

            
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QQ plot HIBP ~Overweight.png
Type: image/png
Size: 3452 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130115/7bda764a/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Fitted vs residuals HiBP ~time+Sex+Maternal Age, random intercept.png
Type: image/png
Size: 3470 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130115/7bda764a/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QQ plot hibp21 BP.sub4.png
Type: image/png
Size: 1883 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130115/7bda764a/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: HiBP ~Overweight qq plots residuals,random effects.png
Type: image/png
Size: 3425 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130115/7bda764a/attachment-0003.png>
#
Hi,
Check these links:
http://comments.gmane.org/gmane.comp.lang.r.ggplot2/6527
https://groups.google.com/forum/#!msg/ggplot2/nfVjxL0DXnY/5zf50zCeZuMJ
A.K.
#
HI,

In the same link at the bottom of the page,

"

All is well now after updating all packages with the following:
update.packages()"

It may or may not solve your problem.

I got your attachments.  You should post those questions in (r-sig-mixed-models at r-project.org).  I suggest you to read lme4 book (http://lme4.r-forge.r-project.org/lMMwR/)
#lrgprt.pdf

A.K.







----- Original Message -----
From: rex2013 <usha.nathan at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, January 16, 2013 5:06 AM
Subject: Re: [R] random effects model

Hi

I tried removing the missing values and installing "plyr". Still error
message appears with ggplot2

Btw, did you get the attachments with my earlier mail?

Ta.

On Wed, Jan 16, 2013 at 3:16 AM, arun kirshna [via R] <
ml-node+s789695n4655612h99 at n4.nabble.com> wrote:

            
        
--
View this message in context: http://r.789695.n4.nabble.com/random-effects-model-tp4654346p4655704.html
Sent from the R help mailing list archive at Nabble.com.
??? [[alternative HTML version deleted]]

______________________________________________
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.
2 days later