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

From |
"Carlo Lazzaro" <carlo.lazzaro@tiscalinet.it> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
R: st: R:R:st Mata question |

Date |
Mon, 6 Jul 2009 09:32:16 +0200 |

Dear Christina, thanks a lot for your kind reply. My temptative answer was admittedly not in Mata language, since I am not a Mata expert: my intent was to give a little contribution about different paths for solving your problem. Besides: - I might have been unclear in my previous pots but the .do file generates mean and sds (and not observations) of 20 different samples (10 observations each) drawn from two population, supposed to have the same variance; - more important: the seventh line of the .do file from the bottom qui g w`i'=ttail(18,abs(t`i')) should be qui g w`i'=2*ttail(18,abs(t`i')) As an acid test for testing the results obtained with the .do file is to compare them to those obtained via - ttesti - command, invoked from within Stata 9.2/SE. Considering mean_alfa[1](= .27396816), sd_alfa[1] ](= .02923826), mean_beta[1] ](= .2769154) and sd_beta[1] ](= .01790745), I get the following student_t[1]= -.271828263998; p_value[1]= .788847386837. Switching to -ttesti-: ttesti 10 .27396816 . 02923826 10 .2769154 .01790745 Two-sample t test with equal variances ---------------------------------------------------------------------------- -- | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+------------------------------------------------------------------ -- x | 10 .2739682 .0092459 .0292383 .2530524 .294884 y | 10 .2769154 .0056628 .0179074 .2641052 .2897256 ---------+------------------------------------------------------------------ -- combined | 20 .2754418 .0052874 .0236459 .2643752 .2865084 ---------+------------------------------------------------------------------ -- diff | -.0029472 .0108423 -.025726 .0198316 ---------------------------------------------------------------------------- -- diff = mean(x) - mean(y) t = -0.2718 Ho: diff = 0 degrees of freedom = 18 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = 0.3944 Pr(|T| > |t|) = 0.7888 Pr(T > t) = 0.6056 . return list scalars: r(sd) = .0236458571402653 r(sd_2) = .01790745 r(sd_1) = .02923826 r(se) = .0108422904099185 r(p_u) = .6055762826325284 r(p_l) = .3944237173674716 r(p) = .7888474347349431 r(t) = -.2718281736213082 r(df_t) = 18 r(mu_2) = .2769154 r(N_2) = 10 r(mu_1) = .27396816 r(N_1) = 10 All the Best for your research project, hoping that some Mata guru can provide you with more helpful hints. Kind Regards, Carlo -----Messaggio originale----- Da: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di Christian Bustamante Inviato: lunedì 6 luglio 2009 1.53 A: statalist@hsphsun2.harvard.edu Oggetto: Re: st: R:R:st Mata question 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<carlo.lazzaro@tiscalinet.it> 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:carlo.lazzaro@tiscalinet.it] > Inviato: sabato 4 luglio 2009 10.46 > A: 'statalist@hsphsun2.harvard.edu' > 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: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu] 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/ * * 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/

**Follow-Ups**:**R: st: R:R:st Mata question***From:*"Carlo Lazzaro" <carlo.lazzaro@tiscalinet.it>

**References**:**Re: st: R:R:st Mata question***From:*Christian Bustamante <cdeb77@gmail.com>

- Prev by Date:
**Re: st: Stata 11** - Next by Date:
**R: st: R:R:st Mata question** - Previous by thread:
**Re: st: R:R:st Mata question** - Next by thread:
**R: st: R:R:st Mata question** - Index(es):

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