Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: R:R:st Mata question


From   Christian Bustamante <[email protected]>
To   [email protected]
Subject   Re: st: R:R:st Mata question
Date   Sun, 5 Jul 2009 18:52:38 -0500

Hi Carlo,
Thanks for your help, but I apparently it doesn't works for what I
need because I have vector with means a sds, not "observarions", thing
that is not trivial. I've continued my tryings whit this:

forvalues i=1/52 {
		scalar m1=dy04[1,`i']
		scalar s1=S04[1,`i']
		scalar m2=dy07[1,`i']
		scalar s2=S07[1,`i']
		ttesti N04 m1 s2 N07 m2 s2
		mat tvalues[1,`i']=r(t)
		mat pvalues[1,`i']=r(p)
	}

But stata propmt says: "'N04' found where integer expected" and "'m1'
found where number expected", so i ask: there is a way to convert an
scalar in a "integer" or in a "number"?

Bests regards


On Sun, Jul 5, 2009 at 5:26 AM, Carlo
Lazzaro<[email protected]> wrote:
> Dear Christian,
> the following is a a fine-tuning of my yesterday's temptative answer to your
> query, again not in Mata language.
> Let's assume we have 20 + 20 sample means and sds (sample size: 10
> observations each) drawn from 2 different populations (I mean, 20 from
> population1 and 20 from population 2). Sample means and sds drawn from
> population 1 are now labelled mean_alfa and sd_alfa. Sample means and sds
> drawn from population 2 are now labelled mean_beta and sd_beta. Ttests are
> performed under the equal variance assumption; hence, I have plugged in
> pooled_variance formula (please, see v`i' line of the beneath reported Stata
> 9.2/Se .do file), as from Pagano M, Gavreau K. Principles of Biostatistics.
> 2nd edition. Brooks/Cole, 2000 (p 206 of the Italian edition).
> Example now includes retrieving and storing two-sided p-value.
>
> set obs 20
> g mean_alfa=2*uniform()
> g mean_beta=1*uniform()
> g sd_alfa=.03*uniform()
> g sd_beta=.02*uniform()
> g double var_pooled=.
> g double student_t=.
> g double p_value=.
> qui forval i = 1/20 {
> qui g v`i'=((10-1)*sd_alfa[`i']^2+(10-1)*sd_beta[`i']^2)/(10+10-2)
> sum v`i', meanonly
> replace var_pooled=r(mean) in `i'
> qui g t`i' = (mean_alfa[`i']-mean_beta[`i'])/(v`i'*(1/10+1/10))^.5
> sum t`i', meanonly
> replace student_t=r(mean) in `i'
> qui g w`i'=ttail(18,abs(t`i'))
> sum w`i', meanonly
> replace p_value=r(mean) in `i'
> drop v`i'
> drop t`i'
> drop w`i'
> }
>
> Again, not that elegant, but I do hope this help.
>
> Kind Regards,
> Carlo
> -----Messaggio originale-----
> Da: Carlo Lazzaro [mailto:[email protected]]
> Inviato: sabato 4 luglio 2009 10.46
> A: '[email protected]'
> Cc: 'Christian Bustamante'
> Oggetto: R: Mata question
>
> Dear Christian,
> the following is a temptative answer to your query, not in Mata language.
> Let's assume we have 20 + 20 sample means and sds (sample size: 10
> observations each) drawn from 2 different populations (I mean, 20 from
> population1 and 20 from population 2). Sample means and sds drawn from
> population 1 are labelled a and c. Sample means and sds drawn from
> population 2 are labelled b and d. Ttests are performed under the equal
> variance assumption. Example stops at Student t retrieving and storing for
> each ttest performed (two-sided p-value was not included in the Stata .do
> file).
>
> set obs 20
> g a==2*uniform()
> g b=1*uniform()
> g  c=.03*uniform()
> g d =.03*uniform()
> g double student_t=.
> qui forval i = 1/20 {
> g t`i' = (a[`i']-b[`i'])/(c[`i']^2/10+d[`i']^2/10)^.5
> sum t`i', meanonly
> replace  student_t=r(mean) in `i'
> drop t`i'
> }
>
> Not that elegant, but I do hope this help.
>
> Kind Regards,
> Carlo
> -----Messaggio originale-----
> Da: [email protected]
> [mailto:[email protected]] Per conto di Christian
> Bustamante
> Inviato: sabato 4 luglio 2009 9.15
> A: Statalist
> Oggetto: st: Mata question
>
> Hi all
>
> I'm trying to do a loot with a nested -ttesti- but I couldn't do it. I
> have two vector with different means (m1 and m2) and another two with
> each mean's standard deviation (s1 and s2). This vectors are quite
> large, so do -ttesti- element for element could be very costly. Also,
> I have each sample's size on two variables: n1 and n2. All this values
> are obtained from a logistic regresion. After run -ttesti- I want to
> save the t-statistic -r(t)- and the probability for two-sided p-value
> -r(p)-. I'm doing something like this:
>
> forvalues i=1/size(m1) {    /* how can i get vector's size? */
>                ttesti n1 m1[1,`i'] s1[1,`i'] n1 m1[1,`i'] s1[1,`i']
>                mat tvalues[1,`i']=r(t)
>                mat pvalues[1,`i']=r(p)
>        }
>
> But appears a lot of errors: 1) n1 should be integer. 2) 'm1' found
> where number expected. 3) varlist not allowed.
> How can I solve this?
>
> Thanks
>
>
>
> --
> CdeB
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>



-- 
CdeB

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index