Re: [R] How to compute time interval?

2011-11-10 Thread Lao Meng
as.numeric() is work

Settled!

2011/11/11 Lao Meng 

> t2-t1 is ok,but only can get"Time difference of 786 days",but I wanna get
> the "786" only.How can I do then?
>
> Thanks!
>
>
> 2011/11/11 Lao Meng 
>
>> time1 = 2008-03-09
>> time2 = 2010-9-10
>>
>> How to compute how many years between time1 and time2?
>>
>> Thanks!
>>
>> best
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How to compute time interval?

2011-11-10 Thread Lao Meng
t2-t1 is ok,but only can get"Time difference of 786 days",but I wanna get
the "786" only.How can I do then?

Thanks!

2011/11/11 Lao Meng 

> time1 = 2008-03-09
> time2 = 2010-9-10
>
> How to compute how many years between time1 and time2?
>
> Thanks!
>
> best
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to compute time interval?

2011-11-10 Thread Lao Meng
time1 = 2008-03-09
time2 = 2010-9-10

How to compute how many years between time1 and time2?

Thanks!

best

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about lm on t-test.

2011-08-17 Thread Lao Meng
Well,since the intercept is the same as mean of group1,I take it for granted
that the 1-sample ttest must test based on group==1...

If the intercept is estimated from the whole sample,why does the intercept
is the same as mean of group1?




2011/8/17 Eik Vettorazzi 

> Hi Lao,
> thats not the same test. The concept of linear regression applies here
> (and you might take any introductory at your hand to refresh that
> concept). The intercept is estimated from the whole sample not just
> group==1, dfs are 20-2, not sum(group==1)-1!
>
> best regards
>
> Am 17.08.2011 09:57, schrieb Lao Meng:
> > Thanks Eik.
> > As to your words:"The intercept in lm is tested against 0 (one sample
> > t-test)"
> >
> > So, I perform the following test:
> > t.test(extra[group==1],mu=0)
> >
> > Since goup1 is regarded as reference,I do the 1-sample ttest based on
> > group1's mean vs 0.
> > But the result:
> > t value= 1.3257
> > p-value = 0.2176
> >
> > And t value and p value of s1 is:
> > t value= 1.249
> > p value= 0.2276
> >
> > So the t value and p value are different between 1-sample ttest of
> > group1'mean vs 0  and s1(lm's result).
> >
> > What's the reason for the difference then?
> >
> > Thanks a lot for your help.
> >
> > My best.
> >
> >
> > 2011/8/16 Eik Vettorazzi  > <mailto:e.vettora...@uke.uni-hamburg.de>>
> >
> > Hi,
> > you may have noticed, that your t-test and lm had not the same
> p-values
> > for the difference in means, which is calculated for group2 when you
> use
> > treatment contrasts and that is what R does by default (see
> > ?contr.treatment). This is because R uses Welsh test by default. Pros
> > and cons are beyond this post, but look at
> >
> > (t1<-t.test(extra~group,data=sleep,var.equal=T))
> > (s1<-summary(lm(extra~group,data=sleep)))
> > all.equal(s1$coef["group2","Pr(>|t|)"],t1$p.value)
> >
> > The intercept in lm is tested against 0 (one sample t-test),
> > so the t-statistic is (mean-0)/sd, having n-k (sample size - number
> of
> > parameters) degrees of freedom.
> >
> > cc<-s1$coef["(Intercept)",1:2]
> > 2*(1-pt(cc[1]/cc[2],df=18))
> >
> >
> > hth.
> >
> > Am 16.08.2011 07:25, schrieb Lao Meng:
> > > Hi all:
> > > I have a question about lm on t-test.
> > >
> > > data(sleep)
> > >
> > > I wanna perform t-test to test the difference between the 2 groups:
> > >
> > > I can use:
> > > t.test(extra~group)
> > >
> > > The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
> > >
> > >
> > > But I still wanna use:
> > > summary(lm(extra~group))
> > >
> > > Intercept=0.75,which is mean1,just the same as t.test.
> > > group2=1.58 means the difference of the 2 groups,so
> > > mean2=1.58+0.75=2.33,just the same as t.test.
> > > And some parameters of group2(t value,Pr) are the same as
> t.test,since
> > > group2 is the difference of the 2 groups.
> > >
> > > My question is:
> > > How the "t value" of Intercept(group1 acturally) is calculated?
> > >
> > >
> > > Thanks a lot.
> > >
> > > My best
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org <mailto:R-help@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.
> >
> > --
> > Eik Vettorazzi
> > Institut für Medizinische Biometrie und Epidemiologie
> > Universitätsklinikum Hamburg-Eppendorf
> >
> > Martinistr. 52
> > 20246 Hamburg
> >
> > T ++49/40/7410-58243
> > F ++49/40/7410-57790
> >
> >
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to get the descriptive statistic of the whole dataframe?

2011-08-17 Thread Lao Meng
Hi all:
If I have a dataframe of N columns.If I wanna get the min(or max,or
mean...etc)of the whole dataframe,how to do it quickly?
What I can do is only:
min(data[,1:ncol(data)])

Any other suggestion?

Thanks!

best

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about lm on t-test.

2011-08-17 Thread Lao Meng
Thanks Eik.
As to your words:"The intercept in lm is tested against 0 (one sample
t-test)"

So, I perform the following test:
t.test(extra[group==1],mu=0)

Since goup1 is regarded as reference,I do the 1-sample ttest based on
group1's mean vs 0.
But the result:
t value= 1.3257
p-value = 0.2176

And t value and p value of s1 is:
t value= 1.249
p value= 0.2276

So the t value and p value are different between 1-sample ttest of
group1'mean vs 0  and s1(lm's result).

What's the reason for the difference then?

Thanks a lot for your help.

My best.


2011/8/16 Eik Vettorazzi 

> Hi,
> you may have noticed, that your t-test and lm had not the same p-values
> for the difference in means, which is calculated for group2 when you use
> treatment contrasts and that is what R does by default (see
> ?contr.treatment). This is because R uses Welsh test by default. Pros
> and cons are beyond this post, but look at
>
> (t1<-t.test(extra~group,data=sleep,var.equal=T))
> (s1<-summary(lm(extra~group,data=sleep)))
> all.equal(s1$coef["group2","Pr(>|t|)"],t1$p.value)
>
> The intercept in lm is tested against 0 (one sample t-test),
> so the t-statistic is (mean-0)/sd, having n-k (sample size - number of
> parameters) degrees of freedom.
>
> cc<-s1$coef["(Intercept)",1:2]
> 2*(1-pt(cc[1]/cc[2],df=18))
>
>
> hth.
>
> Am 16.08.2011 07:25, schrieb Lao Meng:
> > Hi all:
> > I have a question about lm on t-test.
> >
> > data(sleep)
> >
> > I wanna perform t-test to test the difference between the 2 groups:
> >
> > I can use:
> > t.test(extra~group)
> >
> > The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
> >
> >
> > But I still wanna use:
> > summary(lm(extra~group))
> >
> > Intercept=0.75,which is mean1,just the same as t.test.
> > group2=1.58 means the difference of the 2 groups,so
> > mean2=1.58+0.75=2.33,just the same as t.test.
> > And some parameters of group2(t value,Pr) are the same as t.test,since
> > group2 is the difference of the 2 groups.
> >
> > My question is:
> > How the "t value" of Intercept(group1 acturally) is calculated?
> >
> >
> > Thanks a lot.
> >
> > My best
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] how to get the result in "short cut" manner?

2011-08-17 Thread Lao Meng
Yes, you remind me of this!
Thanks!


2011/8/16 Eik Vettorazzi 

> Hi Lao,
> you tried to reinvent the wheel. Have a look at ?tapply
>
> tapply(sleep$extra,sleep$group,mean)
>
> Cheers
>
> Am 16.08.2011 09:41, schrieb Lao Meng:
> > Hi all:
> > My data:data(sleep)
> >
> > If I wanna calculate each group's extra,what I can do is:
> > #method1
> > attach(sleep)
> > mean(extra[group==1])
> > mean(extra[group==1])
> >
> >
> > #method2
> > result<-matrix(,0,2)
> > g<-split(sleep,sleep$group)
> > for(i in 1:length(g))
> > {
> > result<-rbind(result,data.frame(unique(g[[i]]$group),mean(g[[i]]$extra)))
> > }
> > colnames(result)<-c("name","mean")
> >
> > But the above 2 method is a little bit tedious.Is there a "short cut"
> manner
> > to get the same result?
> >
> > Thanks a lot!
> >
> > My best
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] how to get the result in "short cut" manner?

2011-08-16 Thread Lao Meng
Sorry,I miss a word:"If I wanna calculate each group's mean extra"


2011/8/16 Lao Meng 

> Hi all:
> My data:data(sleep)
>
> If I wanna calculate each group's extra,what I can do is:
> #method1
> attach(sleep)
> mean(extra[group==1])
> mean(extra[group==1])
>
>
> #method2
> result<-matrix(,0,2)
> g<-split(sleep,sleep$group)
> for(i in 1:length(g))
> {
> result<-rbind(result,data.frame(unique(g[[i]]$group),mean(g[[i]]$extra)))
> }
> colnames(result)<-c("name","mean")
>
> But the above 2 method is a little bit tedious.Is there a "short cut"
> manner to get the same result?
>
> Thanks a lot!
>
> My best
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] how to get the result in "short cut" manner?

2011-08-16 Thread Lao Meng
Hi all:
My data:data(sleep)

If I wanna calculate each group's extra,what I can do is:
#method1
attach(sleep)
mean(extra[group==1])
mean(extra[group==1])


#method2
result<-matrix(,0,2)
g<-split(sleep,sleep$group)
for(i in 1:length(g))
{
result<-rbind(result,data.frame(unique(g[[i]]$group),mean(g[[i]]$extra)))
}
colnames(result)<-c("name","mean")

But the above 2 method is a little bit tedious.Is there a "short cut" manner
to get the same result?

Thanks a lot!

My best

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about lm on t-test.

2011-08-15 Thread Lao Meng
In my first email,I wrote:

summary(lm(extra~group))

Maybe the same as your "summary.lm"



2011/8/16 Jeff Newmiller 

> ** Sorry, I missed the nature of the data.
>
> As to your original question, perhaps typing "summary.lm" at the R prompt
> can enlighten you?
>
> ---
> Jeff Newmiller The . . Go Live...
> DCN: Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---
>
> Sent from my phone. Please excuse my brevity.
>
> Lao Meng  wrote:
>>
>> The mean of group1 is  0.75,just the same as intercept.
>> Acturally,R treated group1 as reference,so intercept is just group1.
>>
>>
>> 2011/8/16 Jeff Newmiller 
>>
>>> Why would you assert that the mean is the same as the intercept? For data
>>> clustered far from the y axis this seems clearly unlikely to be true.
>>>
>>> ---
>>> Jeff Newmiller The . . Go Live...
>>> DCN: Basics: ##.#. ##.#. Live Go...
>>> Live: OO#.. Dead: OO#.. Playing
>>> Research Engineer (Solar/Batteries O.O#. #.O#. with
>>> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
>>> ---
>>>
>>> Sent from my phone. Please excuse my brevity.
>>>
>>> Lao Meng  wrote:
>>>
>>>> Hi all:
>>>> I have a question about lm on t-test.
>>>>
>>>> data(sleep)
>>>>
>>>> I wanna perform t-test to test the difference between the 2 groups:
>>>>
>>>> I can use:
>>>> t.test(extra~group)
>>>>
>>>> The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
>>>>
>>>>
>>>> But I still wanna use:
>>>> summary(lm(extra~group))
>>>>
>>>> Intercept=0.75,which is mean1,just the same as t.test.
>>>>
>>>> group2=1.58 means the difference of the 2 groups,so
>>>> mean2=1.58+0.75=2.33,just the same as t.test.
>>>> And some parameters of group2(t value,Pr) are the same as t.test,since
>>>> group2 is the difference of the 2 groups.
>>>>
>>>> My question is:
>>>> How the "t value" of Intercept(group1 acturally) is calculated?
>>>>
>>>>
>>>> Thanks a lot.
>>>>
>>>> My best
>>>>
>>>>[[alternative HTML version deleted]]
>>>>
>>>> --
>>>>
>>>> R-help@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.
>>>>
>>>>
>>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about lm on t-test.

2011-08-15 Thread Lao Meng
The mean of group1 is  0.75,just the same as intercept.
Acturally,R treated group1 as reference,so intercept is just group1.


2011/8/16 Jeff Newmiller 

> Why would you assert that the mean is the same as the intercept? For data
> clustered far from the y axis this seems clearly unlikely to be true.
> ---
> Jeff Newmiller The . . Go Live...
> DCN: Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---
>
> Sent from my phone. Please excuse my brevity.
>
> Lao Meng  wrote:
>
>> Hi all:
>> I have a question about lm on t-test.
>>
>> data(sleep)
>>
>> I wanna perform t-test to test the difference between the 2 groups:
>>
>> I can use:
>> t.test(extra~group)
>>
>> The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
>>
>>
>> But I still wanna use:
>> summary(lm(extra~group))
>>
>> Intercept=0.75,which is mean1,just the same as t.test.
>> group2=1.58 means the difference of the 2 groups,so
>> mean2=1.58+0.75=2.33,just the same as t.test.
>> And some parameters of group2(t value,Pr) are the same as t.test,since
>> group2 is the difference of the 2 groups.
>>
>> My question is:
>> How the "t value" of Intercept(group1 acturally) is calculated?
>>
>>
>> Thanks a lot.
>>
>> My best
>>
>>  [[alternative HTML version deleted]]
>>
>> --
>>
>> R-help@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.
>>
>>

[[alternative HTML version deleted]]

__
R-help@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.


[R] a question about lm on t-test.

2011-08-15 Thread Lao Meng
Hi all:
I have a question about lm on t-test.

data(sleep)

I wanna perform t-test to test the difference between the 2 groups:

I can use:
t.test(extra~group)

The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33


But I still wanna use:
summary(lm(extra~group))

Intercept=0.75,which is mean1,just the same as t.test.
group2=1.58 means the difference of the 2 groups,so
mean2=1.58+0.75=2.33,just the same as t.test.
And some parameters of group2(t value,Pr) are the same as t.test,since
group2 is the difference of the 2 groups.

My question is:
How the "t value" of Intercept(group1 acturally) is calculated?


Thanks a lot.

My best

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about glht function

2011-07-27 Thread Lao Meng
Here's another question:
What's kind of difference does glht tests?
In other words,
If I get 4 intercepts and 4 slopes for all levels of GROUP,then glht tests
for the difference of the 4 intercepts or 4 slopes,or something else?

Thanks.




2011/7/27 Lao Meng 

> Yes.
> According to your suggestion,I modified my code.It works well.
>
> Thanks you very much.
>
>
> My best.
>
>
>
> 2011/7/26 Peter Ehlers 
>
>> On 2011-07-26 00:16, Lao Meng wrote:
>>
>>> Hi all:
>>> There's a question about glht function.
>>>
>>> My data:data_ori,which inclue CD4, GROUP,time.
>>>
>>>
>>> f_GROUP<-factor(data_ori$**GROUP)
>>>
>>> f_GROUP is a factor of 3 levels(0,1,2,3)
>>>
>>>
>>> result<- lme(sqrt(CD4) ~ f_GROUP*time ,random = ~time|ID,data=data_ori)
>>>
>>> glht(result, linfct = mcp(f_GROUP="Tukey") )
>>> Error in `[.data.frame`(mf, nhypo[checknm]) : undefined columns selected
>>>
>>>
>>> I can't find out the reason for Error.
>>>
>>
>> I think glht() is looking for f_GROUP in data_ori.
>> You have defined f_GROUP in your global environment but
>> have not added it to your dataframe.
>>
>> Peter Ehlers
>>
>>
>>>
>>> Any help from you are welcome.
>>>
>>>
>>> Many thanks!
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __**
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] a question about glht function

2011-07-26 Thread Lao Meng
Yes.
According to your suggestion,I modified my code.It works well.

Thanks you very much.


My best.



2011/7/26 Peter Ehlers 

> On 2011-07-26 00:16, Lao Meng wrote:
>
>> Hi all:
>> There's a question about glht function.
>>
>> My data:data_ori,which inclue CD4, GROUP,time.
>>
>>
>> f_GROUP<-factor(data_ori$**GROUP)
>>
>> f_GROUP is a factor of 3 levels(0,1,2,3)
>>
>>
>> result<- lme(sqrt(CD4) ~ f_GROUP*time ,random = ~time|ID,data=data_ori)
>>
>> glht(result, linfct = mcp(f_GROUP="Tukey") )
>> Error in `[.data.frame`(mf, nhypo[checknm]) : undefined columns selected
>>
>>
>> I can't find out the reason for Error.
>>
>
> I think glht() is looking for f_GROUP in data_ori.
> You have defined f_GROUP in your global environment but
> have not added it to your dataframe.
>
> Peter Ehlers
>
>
>>
>> Any help from you are welcome.
>>
>>
>> Many thanks!
>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] a question about glht function

2011-07-26 Thread Lao Meng
Hi all:
There's a question about glht function.

My data:data_ori,which inclue CD4, GROUP,time.


f_GROUP<-factor(data_ori$GROUP)

f_GROUP is a factor of 3 levels(0,1,2,3)


result <- lme(sqrt(CD4) ~ f_GROUP*time ,random = ~time|ID,data=data_ori)

glht(result, linfct = mcp(f_GROUP="Tukey") )
Error in `[.data.frame`(mf, nhypo[checknm]) : undefined columns selected


I can't find out the reason for Error.


Any help from you are welcome.


Many thanks!

[[alternative HTML version deleted]]

__
R-help@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.


[R] question about linear mixed model

2011-07-17 Thread Lao Meng
Hi all:
I have a question about linear mixed model.

my linear mixed model with randomized slope and intercept with interaction
of time and group(g1,g2,g3):
model<- glmmPQL(log10(CD4) ~ time + factor(group)+ time:factor(group),
random = ~time|id)

What I get is only the main and interaction of time and group.My question
is:

1. How can I get the g1,g2,g3's slope respectively?In other words,how can I
get the slope of g1,the slope of g2,and the slope of g3?

2.How can I pair-wise compare the 3 slopes of g1,g2,g3?



Thanks a lot!


My best

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to compare ratio from multiple groups?

2011-07-05 Thread Lao Meng
If I have 3 groups,and for each group,I get the ratio(e.g. incidence rate).
Now I wanna compare 3 ratio pairwise,and get the corresponding p values,i.e:
group1 vs group2  ,p value=?
group1 vs group3 ,p value=?
group2 vs group3 ,p value=?

Which statistical test  should be used?

Thanks a lot for your help.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] About the covariant

2011-06-27 Thread Lao Meng
Thanks David for your reply.
You said "a single slope and intercept are estimated for each
variable".Actually I can only get one intercept no matter how many

variables exist,but a slope for each variable.

Since the regression is done via:lm(CD4 ~ time + gender + income)
It seems that the explanatory variable(time) and the two
covariants(gender,income) are treated in the same way,but I think
explanatory variable and covariant should be treated differently although I
don't know how to do it.
Also,they are not both numeric,if gender are F(Female) and M(Male),and
income are L(Low),M(median),H(High).



2011/6/28 David Winsemius 

>
> On Jun 27, 2011, at 10:02 PM, Lao Meng wrote:
>
>  Hi all,I have some questions about the covariants of regression.
>>
>> My target: To explore the trend of CD4 level through a period of time.
>>
>> Response variable: CD4 count
>> Explanatory variable:time
>>
>> Also, the demology information is available,such as
>> gender,occupation,income
>> level...
>>
>> Q1,Are these variables of demology information called covariant?
>> Q2,How can I correct the impact of "covariant" so that I can get the
>> "corrected result" of CD4's change through the time period?
>> Q3,How to treat the covariants in regression?I've looked up to many papers
>> of R on regression,which treat the covariant in the same
>>
>> way as the Explanatory variable,like following:
>> lm(CD4 ~ time + gender + income)
>>
>
> Yes that seems pretty standard practice. It does, of course, force the
> relationships to a) be linear and b) means that a single slope and intercept
> are estimated for each variable, neither of a} or b} assumptions may be
> true.
>
>
>>  From above expression of regression,it's obvious that the response
>>> variables
>>>
>> and covariants are treated the same way,
>>
>
> In what sense are you making that claim? True they are both numeric, but
> what else are you saying?
>
> --
> David
>
>  but acturally
>>
>> they are totally different.
>>
>>
>>
>> Thanks for your help.
>>
>> My best.
>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] About the covariant

2011-06-27 Thread Lao Meng
Hi all,I have some questions about the covariants of regression.

My target: To explore the trend of CD4 level through a period of time.

Response variable: CD4 count
Explanatory variable:time

Also, the demology information is available,such as gender,occupation,income
level...

Q1,Are these variables of demology information called covariant?
Q2,How can I correct the impact of "covariant" so that I can get the
"corrected result" of CD4's change through the time period?
Q3,How to treat the covariants in regression?I've looked up to many papers
of R on regression,which treat the covariant in the same

way as the Explanatory variable,like following:
lm(CD4 ~ time + gender + income)

>From above expression of regression,it's obvious that the response variables
and covariants are treated the same way,but acturally

they are totally different.



Thanks for your help.

My best.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] A better way to do this

2011-05-20 Thread Lao Meng
You may try "xyplot"


2011/5/20 1Rnwb 

> Hello gurus,
>
> I have a dataframe containing two groups viz., 'control' and 'case', each
> of
> these groups contains longitudinal data for 100 subjects. I have to plot
> all
> these subjects on a single chart and then put a regression line for each of
> the group for all the subjects. I have written a function to do the chart
> grpcharts<-function (dat, group,group2,molecule,cutoff){
> dat2<-dat[grep(group,dat$Group),]
> ylim=log2(c(min(dat2[,molecule],na.rm=T)+4,max(dat2[,molecule],na.rm=T)+1))
> all.sub.id<-dat2$Subject.ID
>  if (group=='control'){
> col=c('blue')
> }else{col=c('red')}
>
> if(group2=='case'){
>col2=c('red')
> }else{ col2=c('blue')}
> uniq.sub.id<-unique(all.sub.id)
> errcol<-c()
>for (i in 1: length(uniq.sub.id))
>{
> sub<-dat2[grep(uniq.sub.id[i],dat2$Subject.ID),]
> sub<- sub[order(sub$Age.at.Sample.Collection),]
> sub<-sub[sub[,molecule]>cutoff,]
> sub.id<-uniq.sub.id[i]
> if (dim(sub)[1]<=1) errcol<-c(errcol, sub.id)
> if (dim(sub)[1]>1)
>{
> par(new=TRUE)
>
> plot(log2(sub[,molecule])~sub$Age.at.Sample.Collection,
> ylab=paste('Log2_',molecule,sep=''),xlab="Age at Sample",pch=1, ylim=ylim,
> xlim=c(0,25),main=paste(group,'-',molecule))
>
> mod<-loess(log2(sub[,molecule])~Age.at.Sample.Collection,
> na.action=na.exclude, data=sub)
> pred<-predict(mod)
> lines(pred~Age.at.Sample.Collection,
> data=sub,lwd=1, lty=1)
> }
>}
>   dat2<-dat2[order(dat2$Age.at.Sample.Collection),]
>
> mod<-loess(log2(dat2[,molecule])~Age.at.Sample.Collection,
> na.action=na.exclude, data=dat2)
>   pred<-predict(mod)
>   lines(pred~Age.at.Sample.Collection, data=dat2,lwd=2,
> lty=1,col=col)
>   dat2<-dat[grep(group2,dat$Group),]
>   dat2<-dat2[order(dat2$Age.at.Sample.Collection),]
>
> mod<-loess(log2(dat2[,molecule])~Age.at.Sample.Collection,
> na.action=na.exclude, data=dat2)
>   pred<-predict(mod)
>   lines(pred~Age.at.Sample.Collection, data=dat2,lwd=2,
> lty=1,col=col2)
>   legend(c(20,20),c(ylim),c(group,group2),
> lty=1,lwd=2,col=c(col,col2),
> bty='n')
>  print('done')
>}
>
> the function subsets the data based on the 'group' and plots the datapoints
> currently I am using a loop to assign the colors under two conditions. I
> need some pointers to assign the colors to the regression lines for the two
> groups without using a loop.
> thanks
> sharad
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/A-better-way-to-do-this-tp3536576p3536576.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] "competitive risk model"

2011-04-28 Thread Lao Meng
Hi all:
Which function or package can perform "competitive risk model"?

Thanks a lot!

My best

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] is this an ANOVA ?

2011-04-12 Thread Lao Meng
You may try the following to perform anova:
 anova(lm(y~x))
or
summary(aov(y~x))




2011/4/13 Ubuntu Diego 

> Hi all,
>I have a very easy questions (I hope). I had measure a property of
> plants, growing in three different substrates (A, B and C). The rest of the
> conditions remained constant. There was very high variation on the results.
>I want to do address, whether there is any difference in the
> response (my measurement) from substrate to substrate?
>
> x<-c('A','A','A','A','A','B','B','B','B','B','C','C','C','C','C') #
> Substrate type
> y <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) # Results of the measurement
> MD<-data.frame(x,y)
>
>I wrote a linear model for this:
>
> summary(lm(y~x,data=MD))
>
>This is the output:
>
> Call:
> lm(formula = y ~ x, data = MD)
>
> Residuals:
>   Min 1Q Median 3QMax
> -2.000e+00 -1.000e+00  5.551e-17  1.000e+00  2.000e+00
>
> Coefficients:
>Estimate Std. Error t value Pr(>|t|)
> (Intercept)   3. 0.7071   4.243 0.001142 **
> xB5. 1.   5.000 0.000309 ***
> xC   10. 1.  10.000 3.58e-07 ***
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> Residual standard error: 1.581 on 12 degrees of freedom
> Multiple R-squared: 0.8929, Adjusted R-squared: 0.875
> F-statistic:50 on 2 and 12 DF,  p-value: 1.513e-06
>
>I conclude that there is an effect of substrate type (x).
>NOW the questions :
>1) Do the fact that the all p-values are significant means
> that all the groups are different from each other ?
>2) Is there a (easy) way to plot,  mean plus/minus 2*sd for
> each substrate type ? (with asterisks denoting significant differences ?)
>
>
>THANKS !
>
> version
> platform   x86_64-apple-darwin9.8.0
> arch   x86_64
> os darwin9.8.0
> system x86_64, darwin9.8.0
> status
> major  2
> minor  11.1
> year   2010
> month  05
> day31
> svn rev52157
> language   R
> version.string R version 2.11.1 (2010-05-31)
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] qcc.overdispersion-test

2011-04-06 Thread Lao Meng
hi:
Another question abour overdispersion test.

I wanna make sure that:
if p value<0.05,then the data is NOT overdispersion;
if p value>=0.05,then the data IS overdispersion.

I'm not sure whether it's true,just get the above conclusion from simulated
data.

Thanks for your help.



2011/4/2 

> Hi all,
>
> I have made an overdispersion test for a data set and get the following
> result
>
> Overdispersion test Obs.Var/Theor.Var Statistic p-value
>   poisson data  16.24267  47444.85   0
>
>
> after deleting the outliers from the data set I get the following result
>
>
> Overdispersion test Obs.Var/Theor.Var Statistic p-value
>   poisson data  16.27106 0   1
>
>
> The problem is that the overdispersion parameter does not really change,
> but how could the p-value and the statistic change so that the null
> hypothesis is accepted??
>
> I would be very grateful if someone could help me?
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Sample size of longitudinal and skewed data

2011-03-21 Thread Lao Meng
Hi all:
I have a question about the sample size calculation.

It's a pilot study,which includes 2 groups(low,high),3 time point(3,6,9
monthes).Each person has 3 results which according to the

3 time points.So it's a longitudinal study.

I want to calculate the minimum sample size from the pilot study, but can't
find the solution since the data is highly skewed and

it's a longitudinal study or multi-level model,which can't use common
algorithm.

Any suggestions from you are welcome.


The demo data is as follow:

id group time result
a low   3  0
a low  6   0
a low  9  3
b low 3   0
b low 6 0
b low 9 5
c high   3 0
c high   6   10
c high   9   80
d high   3   50
d high  6 65
d high  9 100
... ...


Thanks for your help.

My best.

[[alternative HTML version deleted]]

__
R-help@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.


[R] sample size of 2 groups of skewed data

2011-03-14 Thread Lao Meng
Hi all:
I have a question on sample size calculation of 2 groups of data. If 2
groups of data are all normal distribution, then I can use the function
"n.indep.t.test.eq" from samplesize package.But if 2 groups of data are all
skewed distribution, but not normal distribution,how can I calculate the
sample size then?
I've tried many transformation (e.g. log arcsin…) in order to transfer the
skewed distribution data into normal distribution data, but failed. So what
I can do is only find a calculation method to do with skewed data.

Any suggestions from you are welcome.
Thanks a lot for your help.

My best.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Boxplot problem

2011-03-09 Thread Lao Meng
No,even there's only one observation,boxplot can still be drawn.

x<-1
boxplot(x)

or
x<-1:3
boxplot(x)
...




2011/3/9 Dennis Murphy 

> Hi:
>
> A box plot is based on a five number summary, so you need at a minimum five
> observations (and preferably at least twice that) to make a box plot a
> viable summary measure for a continuous variable. Consider other graphical
> summaries for these data - perhaps a strip chart or a simple scatterplot.
>
> HTH,
> Dennis
>
> On Tue, Mar 8, 2011 at 9:26 PM, Gaurav Kumar 
> wrote:
>
> > Dear R-user,
> >
> > I'm facing problem to draw boxplot. I can draw my
> > boxplot but the space option is not working for me. I've no clues where
> > i'm doing wrong
> > my data is as matrix as shown below:
> > [,1] [,2]
> > [1,]   98  60
> > [2,]   96  70
> > [3,]   95  80
> >
> > and i'm plotting as
> > barplot(height=c(data[1,],data[2,],data[3,]),
> >   beside=TRUE,
> >   space=c(.1,1),
> >   border="black",
> >   col=c("blue","red") )
> >
> > Please help me where i'm doing wrong or some known issue is there with
> > boxplot.
> >
> > Thanks in advance.
> >
> > Gaurav Kumar
> > www.gauravkumar.org
> >
> > PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney,
> > Australia.
> > MS (Computational Biology), NCBS-TIFR, Bangalore, India.
> >
> >
> >[[alternative HTML version deleted]]
> >
> >
> > __
> > R-help@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.
> >
> >
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] regression with categorical nuisance variable

2011-02-28 Thread Lao Meng
You may try analysis of covariance.
But,as you say"There are no gender differences in age ",then why not combine
2 gender's age and ignore the gender?

2011/3/1 Jonathan DuBois 

> Hi,
>
> I am new to R, so I am unsure of the formula to set up this analysis.
> I would like to run a linear model with a continuous dependent
> variable (brain volume) and a continuous independent variable (age)
> while controlling for a categorical nuisance variable (gender).
>
> Age and brain volume are correlated.
> There are no gender differences in age but there are significant
> gender differences in brain volume.
> Therefore, I would like to control for gender when assessing the
> association between brain volume and age.
>
> Any help would be very much appreciated.
>
> Jon
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How to change dataframe to tables

2011-02-20 Thread Lao Meng
Well,it's my daily work on duty,not homework:)



2011/2/18 Dennis Murphy 

> This is a built-in dataset in R - see ?HairEyeColor and str() it.  I smell
> homework...
>
> Dennis
>
>   On Thu, Feb 17, 2011 at 11:50 PM, Lao Meng  wrote:
>
>>  The data is in the attachment.
>>
>> What I wanna get is:
>> , , Sex = Male
>>   Eye
>> HairBrown Blue Hazel Green
>>  Black32   1110 3
>>  Brown53   502515
>>  Red  10   10 7 7
>>  Blond 3   30 5 8
>> , , Sex = Female
>>   Eye
>> HairBrown Blue Hazel Green
>>  Black369 5 2
>>  Brown66   342914
>>  Red  167 7 7
>>  Blond 4   64 5 8
>>
>>
>> Then,how to change the dataframe to tables?
>>
>> Many thanks for your help.
>>
>> Best
>>
>> __
>> R-help@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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How to change dataframe to tables

2011-02-20 Thread Lao Meng
Thanks!
It works well.

2011/2/18 Henrique Dallazuanna 

> Try this:
>
>  xtabs(Freq ~ Hair + Eye + Sex, Dat)
>
> Using Dimitri's Dat example.
>
>   On Fri, Feb 18, 2011 at 5:50 AM, Lao Meng  wrote:
>
>>  The data is in the attachment.
>>
>> What I wanna get is:
>> , , Sex = Male
>>   Eye
>> HairBrown Blue Hazel Green
>>  Black32   1110 3
>>  Brown53   502515
>>  Red  10   10 7 7
>>  Blond 3   30 5 8
>> , , Sex = Female
>>   Eye
>> HairBrown Blue Hazel Green
>>  Black369 5 2
>>  Brown66   342914
>>  Red  167 7 7
>>  Blond 4   64 5 8
>>
>>
>> Then,how to change the dataframe to tables?
>>
>> Many thanks for your help.
>>
>> Best
>>
>> __
>> R-help@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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] How to change dataframe to tables

2011-02-20 Thread Lao Meng
Thanks!
It works well.



2011/2/18 Dimitris Rizopoulos 

> say, 'Dat' is your data frame, then one way to do it is:
>
> with(Dat, tapply(freq, list(hair, eye, sex), c))
>
>
> I hope it helps.
>
> Best,
> Dimitris
>
>
>
>
> On 2/18/2011 8:50 AM, Lao Meng wrote:
>
>>  The data is in the attachment.
>>
>> What I wanna get is:
>> , , Sex = Male
>>Eye
>> HairBrown Blue Hazel Green
>>   Black32   1110 3
>>   Brown53   502515
>>   Red  10   10 7 7
>>   Blond 3   30 5 8
>> , , Sex = Female
>>Eye
>> HairBrown Blue Hazel Green
>>   Black369 5 2
>>   Brown66   342914
>>   Red  167 7 7
>>   Blond 4   64 5 8
>>
>>
>> Then,how to change the dataframe to tables?
>>
>> Many thanks for your help.
>>
>> Best
>>
>>
>>
>> __
>> R-help@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<http://www.r-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
>
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: http://www.erasmusmc.nl/biostatistiek/
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] How to change dataframe to tables

2011-02-17 Thread Lao Meng
The data is in the attachment.

What I wanna get is:
, , Sex = Male
   Eye
HairBrown Blue Hazel Green
  Black32   1110 3
  Brown53   502515
  Red  10   10 7 7
  Blond 3   30 5 8
, , Sex = Female
   Eye
HairBrown Blue Hazel Green
  Black369 5 2
  Brown66   342914
  Red  167 7 7
  Blond 4   64 5 8


Then,how to change the dataframe to tables?

Many thanks for your help.

Best
"hair"  "eye"   "sex"   "freq"
"Black" "Brown" "Male"  32
"Black" "Blue"  "Male"  11
"Black" "Hazel" "Male"  10
"Black" "Green" "Male"  3
"Brown" "Brown" "Male"  38
"Brown" "Blue"  "Male"  50
"Brown" "Hazel" "Male"  25
"Brown" "Green" "Male"  15
"Red"   "Brown" "Male"  10
"Red"   "Blue"  "Male"  10
"Red"   "Hazel" "Male"  7
"Red"   "Green" "Male"  7
"Blond" "Brown" "Male"  3
"Blond" "Blue"  "Male"  30
"Blond" "Hazel" "Male"  5
"Blond" "Green" "Male"  8
"Black" "Brown" "Female"36
"Black" "Blue"  "Female"9
"Black" "Hazel" "Female"5
"Black" "Green" "Female"2
"Brown" "Brown" "Female"81
"Brown" "Blue"  "Female"34
"Brown" "Hazel" "Female"29
"Brown" "Green" "Female"14
"Red"   "Brown" "Female"16
"Red"   "Blue"  "Female"7
"Red"   "Hazel" "Female"7
"Red"   "Green" "Female"7
"Blond" "Brown" "Female"4
"Blond" "Blue"  "Female"64
"Blond" "Hazel" "Female"5
"Blond" "Green" "Female"8
__
R-help@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.


[R] 3 questions about the poisson regression of contingency table

2011-02-16 Thread Lao Meng
Hi all:
I have 3 questions about the poisson regression of contingency table.
Q1¡¢How to understand the "independent poisson process"as many books or paper
mentioned?
For instance:
   Table1
   ---
   treat  canernon-cancersum
   ---
   treat1 52(57.18)   19(13.82) 71
   treat2 39(33.82)   3 (8.18)  42
   ---
   sum   91  22113
   ---
   The numbers in parentheses are the expected frequency,which are computed
by(57.18 for instance):
   71*91/113=57.18

   But according to poisson distribution,the distribution function is:
   pr<-exp(-mu)*mu^x/x!.But I can't find this function in the computation of
expected frequency of Table1.
   In other words,how the underdstand the"independent poisson process" from
Table1?
Q2¡¢How to understand "zero-inflated"?
For instance:
 area nation frequency
 1 1 10
 1 2 0
 1 3 0
 1 4 0
 2 1 20
 2 2 0
 2 3 0
 2 4 5
 3 1 15
 3 2 6
 3 3 20
 3 4 0
Since most of the frequencies(6/12) are zero,so I can simply consider the
dataset is "zero-inflated"?
In other words, can I judge the dataset is "zero-inflated" simply by the
proportion of "zero frequency"?
Or,how to judge whether the dataset is "zero-inflated" or not?

Q3¡¢How to understand "over-dispersion"?
For instance:
 area nation frequency
 1 1 10
 1 2 0
 1 3 0
 1 4 0
 2 1 20
 2 2 0
 2 3 0
 2 4 5
 3 1 15
 3 2 6
 3 3 20
 3 4 0
Obviously, the frequencies' distribution is of great skewness.So can I judge
the dataset is "over-dispersion"?
In other words, can I judge the dataset is "over-dispersion" simply by the
distribution of all the frequencies?
Or,how to judge whether the dataset is "over-dispersion" or not?

Thanks a lot for your help.
My best.

[[alternative HTML version deleted]]

__
R-help@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.


[R] 3 questions about the poisson regression of contingency table

2011-02-16 Thread Lao Meng
Hi all:
I have 3 questions about the poisson regression of contingency table.

Q1¡¢How to understand the "independent poisson process"as many books or paper
mentioned?
For instance:

   Table1
   ---
   treat  canernon-cancersum
   ---
   treat1 52(57.18)   19(13.82) 71
   treat2 39(33.82)   3 (8.18)  42
   ---
   sum   91  22113
   ---
   The numbers in parentheses are the expected frequency,which are computed
by(57.18 for instance):
   71*91/113=57.18

   But according to poisson distribution,the distribution function is:
   pr<-exp(-mu)*mu^x/x!.But I can't find this function in the computation of
expected frequency of Table1.
   In other words,how the underdstand the"independent poisson process" from
Table1?

Q2¡¢How to understand "zero-inflated"?
For instance:
 area nation frequency
 1 1 10
 1 2 0
 1 3 0
 1 4 0
 2 1 20
 2 2 0
 2 3 0
 2 4 5
 3 1 15
 3 2 6
 3 3 20
 3 4 0

Since most of the frequencies(6/12) are zero,so I can simply consider the
dataset is "zero-inflated"?
In other words, can I judge the dataset is "zero-inflated" simply by the
proportion of "zero frequency"?
Or,how to judge whether the dataset is "zero-inflated" or not?


Q3¡¢How to understand "over-dispersion"?
For instance:
 area nation frequency
 1 1 10
 1 2 0
 1 3 0
 1 4 0
 2 1 20
 2 2 0
 2 3 0
 2 4 5
 3 1 15
 3 2 6
 3 3 20
 3 4 0

Obviously, the frequencies' distribution is of great skewness.So can I judge
the dataset is "over-dispersion"?
In other words, can I judge the dataset is "over-dispersion" simply by the
distribution of all the frequencies?
Or,how to judge whether the dataset is "over-dispersion" or not?


Thanks a lot for your help.

My best.

[[alternative HTML version deleted]]

__
R-help@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.


[R] Fwd: question about result of loglinear analysis

2011-01-18 Thread Lao Meng
-- Forwarded message --
From: Lao Meng 
Date: 2011/1/19
Subject: Re: [R] question about result of loglinear analysis
To: David Winsemius 


My command and result are :
 > result_sat<-summary(glm_sat)
> result_coe<-result_sat$coefficients
> result_coe
 Estimate Std. Error z value Pr(>|z|)
(Intercept)-26.3025850551 312167 -0.8425814674881
area2   -0.000391 441470 -0.08871
area3   27.9120229675 312167  0.8941384743461
area4   -0.000396 441470 -0.08971
area5   -0.000376 441470 -0.08521
area6   -0.000399 441470 -0.09031
area7   28.7874917049 312167  0.9221833882561
nation2 -0.000349 441470 -0.07901
nation3 30.7452363116 312167  0.9848981107911
nation4 26.9957322356 312167  0.8647858617451
nation5 -0.000231 441470 -0.05231
nation6 -0.000349 441470 -0.07901
nation7 -0.000286 441470 -0.06471
nation8 -0.000367 441470 -0.08321
nation9 26.3025850551 312167  0.8425814674841
nation10-0.000492 441470 -0.11151
nation11-0.000372 441470 -0.08421
area2:nation20.000364 624333  0.05841
area3:nation2  -27.9120229706 540689 -0.5162310807721
area4:nation20.000366 624333  0.05871
area5:nation20.000332 624333  0.05311
area6:nation20.000368 624333  0.05901
area7:nation20.000349 441470  0.07901
area2:nation31.0907382714 441470  0.0247069432261
area3:nation3  -25.2301959615 312167 -0.8082283735131
area4:nation31.2272297061 441470  0.0277986896501
area5:nation31.5027693897 441470  0.0340400983321
area6:nation30.3364722765 441470  0.0076216280781
area7:nation3  -27.3005538180 312167 -0.8745505679771
area2:nation40.000391 441470  0.08871
area3:nation4  -54.9077552406 441470 -0.00012437473109701
area4:nation4   -0.6931471409 441470 -0.0157008766631
area5:nation4  -26.9957322354 540689 -0.4992843417691
area6:nation42.9704145054 441470  0.0672845764151
area7:nation4  -27.8712009730 312167 -0.8928307756531
area2:nation50.000218 624333  0.03491
area3:nation5   -0.9162907088 441470 -0.0207554306621
area4:nation50.000248 624333  0.03971
area5:nation50.000228 624333  0.03651
area6:nation50.000250 624333  0.04011
area7:nation5   -0.4054650850 441470 -0.0091844240891
area2:nation6   28.6051702221 540689  0.5290507943861
area3:nation6  -27.9120229740 540689 -0.5162310804911
area4:nation60.000368 624333  0.05891
area5:nation60.000347 624333  0.05561
area6:nation60.000370 624333  0.05931
area7:nation6  -28.7874917077 540689 -0.5324228187721
area2:nation70.000300 624333  0.04811
area3:nation7   -1.6094378839 441470 -0.0364563081791
area4:nation70.000302 624333  0.04841
area5:nation7   27.4011974099 540689  0.5067833953131
area6:nation70.000304 624333  0.04881
area7:nation7   -0.1823215282 441470 -0.0041298703651
area2:nation80.000413 624333  0.06621
area3:nation8  -27.9120229714 540689 -0.5162310805531
area4:nation8   26.9957323120 540689  0.4992843434391
area5:nation8   28.2484952785 540689  0.5224541143501
area6:nation80.000387 624333  0.06201
area7:nation8   -0.2876820357 441470 -0.0065164521291
area2:nation90.000391 441470  0.08871
area3:nation9  -25.6094378745 312167 -0.8203770732241
area4:nation9  -26.3025850534 540689 -0.4864646289691
area5:nation9  -26.3025850556 540689 -0.4864646289751
area6:nation95.9480350291 441470  0.1347323805151
area7:nation9  -55.0900767979 441470 -0.00012478771819791
area2:nation10  26.9957323240 540689  0.4992843432031
area3:nation10   0.000

[R] question about result of loglinear analysis

2011-01-18 Thread Lao Meng
Hi all:
Here's a question about result of loglinear analysis.
There're 2 factors:area and nation.The raw data is in the attachment.

I fit the saturated model of loglinear with the command:
glm_sat<-glm(fre~area*nation, family=poisson, data=data_Analysis)

After that,I extract the coefficients:
result_sat<-summary(glm_sat)
result_coe<-result_sat$coefficients

I find that all the coeffients are 1 or very near to 1.

How does this happen?Why all the coeffients are 1 or very near to 1?

Thanks!

My best
areanation  fre
1   1   0
1   2   0
1   3   85
1   4   2
1   5   0
1   6   0
1   7   0
1   8   0
1   9   1
1   10  0
1   11  0
2   1   0
2   2   0
2   3   253
2   4   2
2   5   0
2   6   10
2   7   0
2   8   0
2   9   1
2   10  2
2   11  0
3   1   5
3   2   0
3   3   1242
3   4   0
3   5   2
3   6   0
3   7   1
3   8   0
3   9   10
3   10  5
3   11  3
4   1   0
4   2   0
4   3   290
4   4   1
4   5   0
4   6   0
4   7   0
4   8   2
4   9   0
4   10  0
4   11  62
5   1   0
5   2   0
5   3   382
5   4   0
5   5   0
5   6   0
5   7   3
5   8   7
5   9   0
5   10  0
5   11  0
6   1   0
6   2   0
6   3   119
6   4   39
6   5   0
6   6   0
6   7   0
6   8   0
6   9   383
6   10  1
6   11  0
7   1   12
7   2   12
7   3   376
7   4   5
7   5   8
7   6   0
7   7   10
7   8   9
7   9   0
7   10  52
7   11  0
__
R-help@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.


[R] How to find out the trend during a time period?

2010-10-27 Thread Lao Meng
Hi all:
I have a dataset which contains two variables: Y and time
y<-c(228,189,232,198,252,315)
time<-2003:2008

How can I find out the trend(increase/decrease) of y along the time period?

If I use:
lm(y~time)

The "lm" command treats time as natural number,but not date.
So maybe "lm" isn't appropriate.

Then,which function could be used?

Thanks a lot for your help.

My best

[[alternative HTML version deleted]]

__
R-help@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.