[R] help to program my function

Petr PIKAL petr.pikal at precheza.cz
Wed Aug 8 17:38:31 CEST 2012


Hi

please cc your post also to Rhelp list, others may give you better/quicker 
answer.

> 
> 
> HI peter
> there is the function  that i want to programm (joint in pdf folder).

No pdf allowed.

> my data is > dataexp    v      Ti1  26    5.792  26 1579.523  26 
2323.704 
> 28   68.855  28  426.076  28  110.297  28  108.298  28 1067.609  30 17.
> 0510 30   22.6611 30   21.0212 30  175.8813 30  139.0714 30  144.1215 30 
 
> 20.4616 30   43.4017 30  194.9018 30   47.3019 30    7.7420 32    0.4021 

> 32   82.8522 32    9.8823 32   89.2924 32  215.1025 32    1.7526 32 0.
> 7927 32   15.9328 32    3.9129 32    0.2730 32    0.6931 32  100.5832 32 
 
> 27.8033 32   13.9534 32   53.2435 34    0.9636 34    4.1537 34    0.1938 

> 34    0.7839 34    8.0140 34   31.7541 34    7.3542 34    6.5043 34 8.
> 2744 34   33.9145 34   32.5246 34    3.1647 34    4.8548 34    2.7849 34 
 
> 4.6750 34    1.3151 34   12.0652 34   36.7153 34   72.8954 36    1.9755 
36
> 0.5956 36    2.5857 36    1.6958 36    2.7159 36   25.5060 36    0.3561 
36
> 0.9962 36    3.9963 36    3.6764 36    2.0765 36    0.9666 36    5.3567 
36
> 2.9068 36   13.7769 38    0.4770 38    0.7371 38    1.4072 38    0.7473 
38
> 0.3974 38  !
>    1.1375 38    0.0976 38    2.38

Use dput(your.data) and copy it to mail. It is directly redable by R and 
not scrambled like above.

> NB> X<-Ti

> thanks for helping mehafida

Not at all. I did not help much yet.

Regards
Petr

> 
> Date: Wed, 8 Aug 2012 03:13:28 -0700
> From: ml-node+s789695n4639565h6 at n4.nabble.com
> To: hafida-06 at hotmail.fr
> Subject: Re: help to program my function
> 
> 
> 
>    Hi
> 
> 
> Maybe it is time for you to read some basic stuff like R intro. It seems 

> 
> to me that you expect R to behave like some other language you know but 
> 
> probably your expectation is wrong.
> 
> 
> See inline
> 
> 
> > 
> 
> > HI
> 
> > 
> 
> > >i have a problem please help me to solve it: 
> 
> > http://r.789695.n4.nabble.com/file/n4639434/aj.pdf aj.pdf 
> 
> > 
> 
> > >i want to calculate the vecteur a[j] where j: 1...8
> 
> > 
> 
> > >this is the code in R:
> 
> > 
> 
> > >aj.fun <- function(j, i, X, z, E, beta0, beta1){
> 
> > + n <- length(X)
> 
> > + iX <- order(X)
> 
> > + iz <- order(z)
> 
> > + e1 <- -(beta)*z[ iz[1:(i - 1)] ]
> 
> where do you get beta
> 
> 
> > + numer <- E[j] - sum( X[ iX[1:(i - 1)] ] * exp(e1) )
> 
> > + e2 <- -(beta)*z[ iz[i:n] ]
> 
> > + denom <- sum( exp(e2) )
> 
> > + numer/denom
> 
> > + }
> 
> > 
> 
> > > iX<-order(X)
> 
> > > iX
> 
> >  [1] 75 37 29 60 73 20 69 55 30 70 72 38 26 35 65 61 74 50 71 57 25 54 

> 
> 64 76
> 
> > 56
> 
> > [26] 58 48 67 46 63 28 62 36 49 47 66  1 42 41 19 39 43 22 51 68 33 27 
9 
> 
> 15
> 
> > 11
> 
> > [51] 10 59 32 40 45 44 52 16 18 34  4 53 21 23 31  7  6 13 14 12 17 24 
5 
> 
>  8 
> 
> > 2
> 
> > [76]  3
> 
> > 
> 
> > > iZ<-order(Z)
> 
> > > iZ
> 
> >  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 

> 
> 23 24
> 
> > 25
> 
> > [26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 

> 
> 48 49
> 
> > 50
> 
> > [51] 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 

> 
> 73 74
> 
> > 75
> 
> > [76] 76
> 
> > 
> 
> > >e1 <- -(beta)*Z[ iZ[1:(i - 1)] ]
> 
> > Warning message:
> 
> > In 1:(i - 1) : numerical expression has 76 elements: only the first 
used
> 
> 
> As somebody already mentioned i is probably vector and in this case only 

> 
> first value is taken. i seems to have the firs value 3.
> 
> 
> > > e1
> 
> > [1]  -442 -1664
> 
> > 
> 
> > >> numer <- E[j] - sum( X[ iX[1:(i - 1)] ] * exp(e1))
> 
> > Warning message:
> 
> > In 1:(i - 1) : numerical expression has 76 elements: only the first 
used
> 
> > > numer
> 
> > [1] 9.5 9.5 9.5 9.5 9.5 9.5 9.5 9.5
> 
> 
> Here j is vector of 8 values therefore 8 values
> 
> 
> > 
> 
> > >> e2 <- -(beta)*Z[ iZ[i:n] ]
> 
> > Warning message:
> 
> > In i:n : numerical expression has 76 elements: only the first used
> 
> > > e2
> 
> >  [1]  -442 -1664  -442 -1792  -476 -1792  -476 -1792  -510 -1920  -510 

> 
> -1920
> 
> > [13]  -510 -1920  -510 -1920  -510 -1920  -510 -2048  -544 -2048  -544 

> 
> -2048
> 
> > [25]  -544 -2048  -544 -2048  -544 -2048  -544 -2048  -544 -2048  -578 

> 
> -2176
> 
> > [37]  -578 -2176  -578 -2176  -578 -2176  -578 -2176  -578 -2176  -578 

> 
> -2176
> 
> > [49]  -578 -2176  -578 -2176  -578 -2304  -612 -2304  -612 -2304  -612 

> 
> -2304
> 
> > [61]  -612 -2304  -612 -2304  -612 -2304  -612 -2304  -646 -2432  -646 

> 
> -2432
> 
> > [73]  -646 -2432  -646 -2432
> 
> 
> Strange, here first value of i seems to be 1 as n shall be 76 and final 
e2 
> 
> length is 76. 
> 
> 
> > > denom <- sum( exp(e2) )
> 
> 
> 
> > > numer/denom
> 
> > [1] 4.313746e+192 4.313746e+192 4.313746e+192 4.313746e+192 
> 
> 4.313746e+192
> 
> > [6] 4.313746e+192 4.313746e+192 4.313746e+192
> 
> > 
> 
> > >my problem that the vecteur a[j] could not have the same number!!!
> 
> 
> I do not understand. Your numer is 9.5 repeted 8 times. If you divide it 

> 
> by one number you will get nine times the same number.
> 
> 
> You send us a code but no data so it is difficult to understand what is 
> 
> your goal. It would be better to send input data
> 
> 
> j, i, X, z, E, beta0, beta1
> 
> 
> and assumed result in whole not in chunks scattered in several mails.
> 
> 
> Regards
> 
> Petr
> 
> 
> 
> > 
> 
> > 
> 
> > thank you in advance
> 
> > hafida
> 
> > 
> 
> > 
> 
> > 
> 
> > --
> 
> > View this message in context: http://r.789695.n4.nabble.com/help-to-
> > program-my-function-tp4639434.html
> 
> > Sent from the R help mailing list archive at Nabble.com.
> 
> > 
> 
> > ______________________________________________
> 
> > [hidden email] 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.
> 
> 
> ______________________________________________
> 
> [hidden email] 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.
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>       If you reply to this email, your message will be added to the 
> discussion below:
>       http://r.789695.n4.nabble.com/help-to-program-my-function-
> tp4639434p4639565.html
> 
> 
> 
>       To unsubscribe from help to program my function, click here.
> 
>       NAML
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/help-to-
> program-my-function-tp4639434p4639605.html
> Sent from the R help mailing list archive at Nabble.com.
>    [[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.



More information about the R-help mailing list