Re: [R] Problems with basic loop

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Fri, 20 Jun 2008 13:46:24 +0200

Michael Pearmain wrote:
> Thanks for the reply Peter,
>
>
>> I did just see that i had put the first error message,(agreed rather an
>> obvious error) in and not the second i received
>>
>> Warning message:
>> In asin(sqrt(yF[i])) : NaNs produced
>>
Ah. Notwithstanding other remarks, that one would be due to

yT<-x[,"True"]/colSums(x)

The divisor here is a vector of length two!! So every 2nd time you are dividing with the wrong thing and in one case that gets you a relative frequency bigger than 1...

>> The reason i'm looking at this is advert exposure True and False.
>>
>> I'm inspecting age to asses weather or not to weight data in order to
>> normalise groups for later questions,
>> The questions that i am looking at later on are not scale based questions
>> so i cannot perform t-tests on these, so i thought the only viable way was
>> to look at z-tests for proportions to check for post-hoc differences
>>
>> Any advise on other methods would be gratefully taken
>>
>>
I still don't see where the notion of power needs to come in. Shouldn't the effect size for "The questions that I am looking at later" enter somehow? If you just want to know whether there is age-dependent exposure, how about

chisq.test(SURVEY$n_0,exposed)

(or wilcox.test if you want something that takes the group ordering into account, or prop.trend.test). If, for better or worse, you want to test single rows, you could use

chisq.test(SURVEY$n_0 == "35-44",exposed)

etc.

>>
>> On Fri, Jun 20, 2008 at 11:14 AM, Peter Dalgaard <P.Dalgaard@biostat.ku.dk>
>> wrote:
>>
>>
>>> Michael Pearmain wrote:
>>>
>>>> I'm having trouble creating a looping variable and i can't see wher ethe
>>>> problem arises from any hep gratfully appreciated
>>>>
>>>> First create a table
>>>>
>>>> x<-table(SURVEY$n_0,exposed)
>>>>
>>>>
>>>>> x
>>>>>
>>>>>
>>>> exposed
>>>> False True
>>>> Under 16 24 1
>>>> 16-19 68 9
>>>> 20-24 190 37
>>>> 25-34 555 204
>>>> 35-44 330 87
>>>> 45-54 198 65
>>>> 55-64 67 35
>>>> 65+ 10 8
>>>>
>>>> Now ectors to store counts and column proportions
>>>>
>>>>
>>>>
>>>>> xT<-x[,"True"]
>>>>> xF<-x[,"False"]
>>>>> yT<-x[,"True"]/colSums(x)
>>>>> yF<-x[,"False"]/colSums(x)
>>>>>
>>>>>
>>>> check length for dynamic looping
>>>>
>>>>
>>>>> length(yT)
>>>>>
>>>>>
>>>> [1] 8
>>>>
>>>> now create loop
>>>>
>>>>
>>>>> for(i in 1:length(yT)){
>>>>>
>>>>>
>>>> +
>>>>
>>> pwr.2p2n.test(2*(asin(sqrt(yT[i]))-asin(sqrt(yF[i]))),n1=xT[i],n2=xF[i])
>>>
>>>> + }
>>>> Error in pwr.2p2n.test(2 * (asin(sqrt(yT[i])) - asin(sqrt(yF[i]))), n1 =
>>>> xT[i], :
>>>> number of observations in the first group must be at least 2
>>>>
>>>> this confuses me as if i enter the data as values the procedure works?
>>>>
>>>> Thanks in advance
>>>>
>>>>
>>> Er, the first row "under 16" has a count of 1 in the "True" column and
>>> it confuses you that you get an error saying that you need at least 2??
>>>
>>> But what looks _really_ confused is what you are trying to do in the
>>> first place: The p's you are passing to pwr.2p2n are the empirical
>>> relative frequencies of the individual age groups. This sort of reverses
>>> cause and effect (presumably the exposure does not cause middle age) and
>>> it is pretty odd to compare a particular row in a table with everything
>>> else jumbled together but worse, it is post-hoc power calculation, which
>>> is just a plain Bad Idea (as several people have pointed out before).
>>>
>>> --
>>> O__ ---- Peter Dalgaard �ster Farimagsgade 5, Entr.B
>>> c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
>>> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
>>> ~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk) FAX: (+45) 35327907
>>>
>>>
>>>
>>>
>> --
>> Michael Pearmain
>> Senior Statistical Analyst
>>
>>
>> 1st Floor, 180 Great Portland St. London W1W 5QZ
>> t +44 (0) 2032191684
>> mpearmain_at_google.com
>> mpearmain_at_doubleclick.com
>>
>>
>> Doubleclick is a part of the Google group of companies
>>
>
> [[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.
>

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
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.
Received on Fri 20 Jun 2008 - 14:04:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Jun 2008 - 15:00:56 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive