[R] help with tapply or other apply

2010-05-02 Thread peterko

Hi, my data looks this:
  id   forma program   kod obor 
 
rocnik
1 10001 kombinovaná  Matematika M1101   matematika  1
2 10002   prezenční Informatika N1801   teoretická informatika  1
3 10002   prezenční Informatika B1801   obecná informatika  3
4 10003   prezenční Informatika M1801   softwarové systémy  5
5 10004   prezenční Informatika B1801   obecná informatika  2
6 10005 kombinovaná Informatika P1801 diskrétní modely a algoritmy  2
stav ukrok
1   zanechal 2002/2003
2studuje  
3 absolvoval 2008/2009
4 absolvoval 2005/2006
5   zanechal 2007/2008
6   zanechal 2004/2005

data$ukrok is a factor
data$rocnik is numeric

I want to create new column (data$z) and in this column have to be  
as.numeric(first 4 char of column(data$ukrok))-data$rocnik    by the
rows
If ukrok is empty it means 2009.
I know how to do it by cycle FOR , but this is not rigth way. I have too
many observation, and this way is soo slowly.
Know someone how to do it using function TAPPLY ? or another apply function
??? 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-with-tapply-or-other-apply-tp2122683p2122683.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.


Re: [R] help with tapply or other apply

2010-05-02 Thread peterko

Thank you Jim, it works very well. I do not need do it using tapply, but i
think that it is the way.

And Patrick thank you too
-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-with-tapply-or-other-apply-tp2122683p2122728.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.


[R] arg min ???

2009-11-25 Thread Peterko

Is there function what aproximate vector of parameters some function to
minimum ?

tet={tet1,tet2}  i have they starting value

and i want to find the tet what minimalizing some function of tet ?

thanks
-- 
View this message in context: 
http://old.nabble.com/arg-min-tp26513358p26513358.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.


Re: [R] arg min ???

2009-11-25 Thread Peterko

This is nice, but i have to define vector of possible theta, this is not what
i want to do.
I have vector of unknow parameters theta. I have som estimate of theta, but
i want to do better estimate of them, using some criterion function. 
I mean it is clasical argmin f(x_1,x_2,...x_n)  to fit vector
(x_1,x_2...,x_n)`  


David Winsemius wrote:
> 
> 
> On Nov 25, 2009, at 9:15 AM, Peterko wrote:
> 
>>
>> Is there function what aproximate vector of parameters some function  
>> to
>> minimum ?
>>
>> tet={tet1,tet2}  i have they starting value
>>
>> and i want to find the tet what minimalizing some function of tet ?
> 
> ?which.min
> 
> Perhaps:
> 
>   which.min( fn(tet) )
> 
>>
>> thanks
>> -- 
>> View this message in context:
>> http://old.nabble.com/arg-min-tp26513358p26513358.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.
> 
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/arg-min-tp26513358p26515110.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.


Re: [R] arg min ???

2009-11-26 Thread Peterko

Petr that is what i was looking for.
Thanks

p.s. "ak si nahodou z Prahy mas u mna Pivo"

Petr Pikal wrote:
> 
> Hi
> 
> r-help-boun...@r-project.org napsal dne 25.11.2009 16:50:49:
> 
>> 
>> This is nice, but i have to define vector of possible theta, this is not 
> what
>> i want to do.
>> I have vector of unknow parameters theta. I have som estimate of theta, 
> but
>> i want to do better estimate of them, using some criterion function. 
>> I mean it is clasical argmin f(x_1,x_2,...x_n)  to fit vector
>> (x_1,x_2...,x_n)` 
> 
> I am not sure what you mean by argmin, but maybe you could look at ?optim
> 
> Regards
> Petr
> 
>> 
>> 
>> David Winsemius wrote:
>> > 
>> > 
>> > On Nov 25, 2009, at 9:15 AM, Peterko wrote:
>> > 
>> >>
>> >> Is there function what aproximate vector of parameters some function 
>> >> to
>> >> minimum ?
>> >>
>> >> tet={tet1,tet2}  i have they starting value
>> >>
>> >> and i want to find the tet what minimalizing some function of tet ?
>> > 
>> > ?which.min
>> > 
>> > Perhaps:
>> > 
>> >   which.min( fn(tet) )
>> > 
>> >>
>> >> thanks
>> >> -- 
>> >> View this message in context:
>> >> http://old.nabble.com/arg-min-tp26513358p26513358.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.
>> > 
>> > David Winsemius, MD
>> > Heritage Laboratories
>> > West Hartford, CT
>> > 
>> > __
>> > 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.
>> > 
>> > 
>> 
>> -- 
>> View this message in context: 
> http://old.nabble.com/arg-min-tp26513358p26515110.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.
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://old.nabble.com/arg-min-tp26513358p26525273.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.


[R] R. A. Fisher Test for value of periodorgam

2009-04-03 Thread Peterko

Is there in some pacakage this test? i mean that input will be only the value
of periodogram, and the function will say that are significant.

or is there only the way to calcule Fishers statistics W =Vi/V1 + · · · +
Vm, for i =1 m and test it step by step ?
thanks
-- 
View this message in context: 
http://www.nabble.com/R.-A.-Fisher-Test-for-value-of-periodorgam-tp22874210p22874210.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.


[R] GMM with covariance moment condicion

2010-07-02 Thread peterko

hello

I have covariance stacionary proces, and i want to estimate some parameter
of this proces via gmm.

My problem is with write "g" -function.
0 order autocovariance is not problem
1 and higher order autocavariance are problem, because add order from 0 mean
that I "loose" one "observacion"


if I have 100 observation and i am going to use mean, variance and first
autocovariance
and fit one parameter !
g<- function(theta,x) 
  {

  m1<-(P1-x)  
  m2<-(P2-(x-P1)^2)
  m3<-(P3-(???))
  f <- cbind(m1,m2,m3)
  return(f) }


where P1,P2,P3 are formulas for mean, variance and first autocovariance via
my parameter

my question is how to define ???
i think about something like this :
y<-x[2:length(x)]
x<-x[-(length(x))]
   m1<-(P1-x)  
  m2<-(P2-(x-P1)^2)
  m3<-(P3-(x-P1)*(y-P1))
but here i have to lost 1 observacion, what is problem when i call gmm:

rad<-arima.sim(n=200,list(ar=0.5), sd=1)
tet<-gmm(g,rad,t0=c(0))

any idea ? thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/GMM-with-covariance-moment-condicion-tp2276392p2276392.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.


[R] counting across leves of factors

2010-06-09 Thread peterko

I have dataframe with 17factors variables (for example every factor have
3levels)
I have maybe 5000 observation.
And i need to do table where is in every raw 1 of possible combination of
this factors and the numbur how many time is this combination in my dataset.

I wrote one code, but this is very slow and dumb.

it looks like this:

i<-0

for(i1 in levels(hivdat$pohl)){ 
a<-subset(hivdat,hivdat$pohl==i1)
for(i2 in levels(a$vekF)){
b<-subset(a,a$vekF==i2)
for(i3 in levels(b$ekstF)){
c<-subset(b,b$ekst==i3)
for(i4 in levels(c$zam)){
d<-subset(c,c$zam==i4)
for(i5 in levels(d$saman)){
e<-subset(d,d$saman==i5)
for(i6 in levels(e$test)){
f<-subset(e,e$test==i6)
for(i7 in levels(f$aktiv)){
g<-subset(f,f$aktiv==i7)
for(i8 in levels(g$pocpartF)){
h<-subset(g,g$vekF==i8)
for(i9 in levels(h$stav)){
i<-subset(h,h$stav==i9)
for(i10 in levels(i$partner)){
j<-subset(i,i$partner==i10)
for(i11 in levels(i$aktiv6)){
k<-subset(j,j$aktiv6==i11)
for(i12 in levels(k$pocpart6F)){
l<-subset(k,k$pocpart6F==i12)
for(i13 in levels(l$styk6F)){
m<-subset(l,l$styk6F6==i13)
for(i14 in levels(k$kond6F)){
n<-subset(m,m$kond6F==i14)
for(i15 in levels(k$styd)){
o<-subset(n,n$styd==i15)
for(i16 in levels(k$zasl)){
p<-subset(o,o$zasl==i16)
for(i17 in levels(p$izol)){
r<-subset(p,p$izol==i17)
i<-i+1
n<-length(r$pohl)
data2[i,]<-c(n,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,i13,i14,i15,i16,i17)
}

I believe that there exist smart solution, thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/counting-across-leves-of-factors-tp2249355p2249355.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.


[R] Fourier Row and spectral analysis

2009-02-22 Thread Peterko

Hello, i need to find in time serie, k=1,2,3...(how if possible) most domain
frequencies and than smooth original serie by Fourier row  y=mean +
a1*Cos(2*pi/freq*t)+b1*Sin(2*pi/freq*t)+a2..

numbers a1,b1 ... i will have from simple regresion, i need only to find k
msot domain frequensies a than i will have a1,b1,ak,bk - coeficients.

Many many thanks for help.
-- 
View this message in context: 
http://www.nabble.com/Fourier-Row-and-spectral-analysis-tp22151652p22151652.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.


Re: [R] Fourier Row and spectral analysis

2009-02-23 Thread Peterko

Hi, i have result from other program.
Original serie have 225 observing, but program use only 224.
the most domain frequencies are f1=1/224 f2=1/122 f3=1/74,66 f4=1/56
f5=1/24,88
When i know these frequencies a can do, new variable ,nubmers of variavle is
2*nubmer of frequencies:
t<-1:225
c1<-cos(2*pi*f1*t)
s1<-sin(2*pi*f1*t)
.
.
.
s5<-sin(2*pi*f5*t)

and now a can do lm(y~mean+c1+s1+c2+s2+...+s5)


.


Dieter Menne wrote:
> 
> Peterko  gmail.com> writes:
> 
>> Hello, i need to find in time serie, k=1,2,3...(how if possible) most
>> domain
>> frequencies and than smooth original serie by Fourier row  y=mean +
>> a1*Cos(2*pi/freq*t)+b1*Sin(2*pi/freq*t)+a2..
>> 
>> numbers a1,b1 ... i will have from simple regresion, i need only to find
>> k
>> msot domain frequensies a than i will have a1,b1,ak,bk - coeficients.
> 
> 
> It is very difficult to understand what you want, mainly the part about
> the
> "simple regression" in Fourier context. For simple filtering/smoothing,
> check
> 
> http://markmail.org/message/qtyxkwlesy75 
> 
> 
> Dieter
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Fourier-Row-and-spectral-analysis-tp22151652p22157212.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.


Re: [R] Fourier Row and spectral analysis

2009-02-23 Thread Peterko



Dieter Menne wrote:
> 
> Peterko  gmail.com> writes:
> 
>> Original serie have 225 observing, but program use only 224.
>> the most domain frequencies are f1=1/224 f2=1/122 f3=1/74,66 f4=1/56
>> f5=1/24,88
>> When i know these frequencies a can do, new variable ,nubmers of variavle
>> is
>> 2*nubmer of frequencies:
>> t<-1:225
>> c1<-cos(2*pi*f1*t)
>> s1<-sin(2*pi*f1*t)
>> .
>> .
>> .
>> s5<-sin(2*pi*f5*t)
>> 
>> and now a can do lm(y~mean+c1+s1+c2+s2+...+s5)
> 
> Good you got it technically working, but having such highly correlated 
> coefs like 1/224 and 1/122 in lm is asking for trouble. These are 
> "almost DC" components in engineering speak for such short periods.
> 
> Dieter
> 
> It is next problem, eliminate cerrelation, but i to not know whow to get
> this most domain frequencies in R, this result is from other program.
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Fourier-Row-and-spectral-analysis-tp22151652p22160005.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.


[R] bigest part of vector

2009-02-24 Thread Peterko

Hi, may be simle question, but a do not find it anywhere.
Is there same function like max()  ,but giving more results.
max() give 1number-maximum
I need funcion what give p bigest number.
many thanks
-- 
View this message in context: 
http://www.nabble.com/bigest-part-of-vector-tp22188901p22188901.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.


Re: [R] bigest part of vector

2009-02-24 Thread Peterko

Thanks for all

Peterko wrote:
> 
> Hi, may be simle question, but a do not find it anywhere.
> Is there same function like max()  ,but giving more results.
> max() give 1number-maximum
> I need funcion what give p bigest number.
> many thanks
> 

-- 
View this message in context: 
http://www.nabble.com/bigest-part-of-vector-tp22188901p22189283.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.


[R] rounding problem

2009-02-27 Thread Peterko

hi i am creating some variables from same data, but somewhere is different
rouding.
look:
 P = abs(fft(d.zlato)/480)^2 
 hladane= sort(P,decreasing=T)[1:10]/480 
  
 pozicia=c(0,0,0,0,0) 
 for (j in 1:5){ for (i in 2:239){
  if (P[i]/480==hladane[2*j-1]){pozicia[j]=i-1}}}
 period=479/pozicia  

> P[2]/334 
 [1] 0.0001279107 
 > hladane[1]
 [1] 0.0001279107
 > P[2]/334==hladane[1]
 [1] FALSE
> abs(P[2]/334 - hladane[1]) < 0.001
 [1] TRUE

It is possible to avoid it ?
I know in this exam i can use 2x if to eliminate this rouding, but i need to
fix it in general.
-- 
View this message in context: 
http://www.nabble.com/rounding-problem-tp22243179p22243179.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.


Re: [R] rounding problem

2009-02-27 Thread Peterko

all.equal is what i need, many thanks to help me

baptiste auguie-2 wrote:
> 
> Hi,
> 
> you probably want to use ?all.equal instead of "=="
> 
> I couldn't run your example, though
> 
> Hope this helps,
> 
> baptiste
> 
> On 27 Feb 2009, at 10:32, Peterko wrote:
> 
>>
>> hi i am creating some variables from same data, but somewhere is  
>> different
>> rouding.
>> look:
>> P = abs(fft(d.zlato)/480)^2
>> hladane= sort(P,decreasing=T)[1:10]/480
>>
>> pozicia=c(0,0,0,0,0)
>> for (j in 1:5){ for (i in 2:239){
>>  if (P[i]/480==hladane[2*j-1]){pozicia[j]=i-1}}}
>> period=479/pozicia
>>
>>> P[2]/334
>> [1] 0.0001279107
>>> hladane[1]
>> [1] 0.0001279107
>>> P[2]/334==hladane[1]
>> [1] FALSE
>>> abs(P[2]/334 - hladane[1]) < 0.001
>> [1] TRUE
>>
>> It is possible to avoid it ?
>> I know in this exam i can use 2x if to eliminate this rouding, but i  
>> need to
>> fix it in general.
>> --
>> View this message in context:
>> http://www.nabble.com/rounding-problem-tp22243179p22243179.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.
> 
> _
> 
> Baptiste Auguié
> 
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
> 
> Phone: +44 1392 264187
> 
> http://newton.ex.ac.uk/research/emag
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/rounding-problem-tp22243179p22243567.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.