Re: [R] as.numeric looses precision

2015-07-02 Thread Kehl Dániel
Hi Roger,

I think it does! Try multiplying with 100 or similar. It is just a matter 
of displaying your result.

best
d

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Bos, Roger 
[roger@rothschild.com]
Küldve: 2015. július 2. 15:54
To: r-help@r-project.org
Tárgy: [R] as.numeric looses precision

I have a string that contains a number and when I convert it to a number I 
loose precision and I would like to know if there is a way to avoid that.  Here 
is my example:

p - 1087.003489
as.numeric(p, digits=6)

R gives me 1087.003:

 p - 1087.003489
 as.numeric(p, digits=6)
[1] 1087.003

I would be nice if I could keep all the decimal places after the conversion.

Thanks,

Roger





***
This message and any attachments are for the intended recipient's use only.
This message may contain confidential, proprietary or legally privileged
information. No right to confidential or privileged treatment
of this message is waived or lost by an error in transmission.
If you have received this message in error, please immediately
notify the sender by e-mail, delete the message, any attachments and all
copies from your system and destroy any hard copies.  You must
not, directly or indirectly, use, disclose, distribute,
print or copy any part of this message or any attachments if you are not
the intended recipient.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Problem with apply list to function: numerical expression has 4 elements: only the first used

2015-05-24 Thread Kehl Dániel
Dear Narua,

Others might suggest other things but here are some of my points.
In general it is not a good idea to call a function F as it is an abbreviation 
for FALSE.
Also it might be a good idea to write your functions in a way that they check 
the length of the arguments and behave accordingly  (if nothing else, with 
loops). It is really nice to take a look at the family of apply functions 
(although I also have problems with them sometimes).

I did not check, but you can try something like this

ff - function(m,k)((1/(sum(sqrt(1:m*sqrt(k))
FF - function(m,i)(sum(ff(m,1:i)))
x - 1:4

sapply(x, ff, m=4)
sapply(x, FF, m=4)


Keep up with using R! :)

Best,
kd

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Narua 
[maria@gmx.de]
Küldve: 2015. május 24. 0:21
To: r-help@r-project.org
Tárgy: [R] Problem with apply list to function: numerical expression has 4 
elements: only the first used

Hello ,

I want to try R for statistics.

Therefore, I defined a function f with parameters m and k, which calculates
a to sqrt(x) proportional density function:
f - function(m,k)((1/(sum(sqrt(1:m*sqrt(k))

A function F sums the results in order to get a distribution function:
F - function(m,i)(sum(f(m,1:i)))
It works e.g. for m=4:
 F(4,1)
[1] 0.1627005
 F(4,4)
[1] 1

If I want to see all results for m=4, I write
 F(4,1:4)
[1] 0.1627005
Warning message:
In 1:i : numerical expression has 4 elements: only the first used

what does the error message mean?
and how can I solve it?

I've already tried rapply but I get the same error and googled for a while
but there is nowhere a satisfying answer

Can someone help me here?

many thanks in advance,
Narua




--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-apply-list-to-function-numerical-expression-has-4-elements-only-the-first-used-tp4707588.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Reading access file

2015-05-14 Thread Kehl Dániel
Hi Silvano,

your attachment did not go through (only a couple of formats are supported). 
Please try to give your code next time and what error you get but first read 
this, it might help:

http://www.statmethods.net/input/dbinterface.html

best,
daniel

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: silvano 
[silv...@uel.br]
Küldve: 2015. május 14. 13:31
To: R
Tárgy: [R] Reading access file

Hello everybody.

I have a access file to read in R but I can’t to do this.

I used Hmisc package, but it doesn’t work.

Someone has the commands to read this kind of file?

I attached the access file.

Thanks.

Silvano.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Reading a tiff image

2015-05-14 Thread Kehl Dániel
Hello,

please set your mailing program to plain text instead of HTML if you post to 
this list.
If you google read tiff in R you end up with the package called 'tiff'. 
(http://cran.r-project.org/web/packages/tiff/tiff.pdf)
In case you do not know how to install and load a package, please consult the 
intro to R pdf which comes with your installation.

Good luck with R,
daniel

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Preethi 
Balaji [preet.balaj...@gmail.com]
Küldve: 2015. május 14. 12:50
To: r-help@r-project.org
Tárgy: [R]  Reading a tiff image

Dear R users,

I am new to R and trying to learn raster image processing in R.

I have a tiff image with pixel values and I am trying to read this image in
R so that I can make some calculations and process the image.

Could you please tell me how to read a tiff image in R?

Thanks!
--

Regards,
*Preethi Malur Balaji* | PhD Student
University College Cork | Cork, Ireland.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Not able to submit work assignment4 with submitscript3.R

2015-05-07 Thread Kehl Dániel
Hi there,
this is not a Coursera Forum. Please ask your question there or search the 
Forums, these are quite regular problems there.

PS: do you really have a user name and a password in your e-mail?

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Sonia Marin 
[s.marin...@gmail.com]
Küldve: 2015. május 6. 23:27
To: r-help@r-project.org
Tárgy: [R] Not able to submit work assignment4 with submitscript3.R

Hi, I tried to submit the work assignment4 with submitscript3.R and i got
an error message:
 Error in assign(.CourseraLogin, r, globalenv()) :
  unused arguments (r, globalenv())
I tryied to do it manually, but the files that I got to upload was empty.
Please, let me know, how can i do to send the work assignment4.

Thanks, for your attention.
Best regard
Sonia Marin
rprog-013
TNWpNjGERh

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Need Help!

2015-05-06 Thread Kehl Dániel
Hi,

type
res #ENTER (now it contains your results as a vector)

or

head(res) #so you only see the first couple of values

or

plot(res) #to see a basic plot (you could set axis labels etc, but I suggets 
you to go ahead and read a tutorial on R!

Best, have a great time with R,
kd

Felad�: dawood ahmad [dawoodma...@hotmail.com]
K�ldve: 2015. m�jus 5. 17:05
To: Kehl D�niel; r-help@R-project.org
T�rgy: RE: [R] Need Help!

Dear Daniel,

Thank you very much for such a kind reply. Actually, I couldn't understand well 
the criteria of help list, I am
sorry for that. I tried you method, unfortunately I couldn't get the output. It 
may be due to my lack of expertise in programming. At this point I need your 
help which will mean a lot to me. Moreover, if I use single value it gives the 
output. I am sending you two image files of the outputs. I will be really 
grateful to you if you guide me.

Thanking in advance,

With Best Regards,

Dawood



 From: ke...@ktk.pte.hu
 To: dawoodma...@hotmail.com; r-help@r-project.org
 Subject: RE: [R] Need Help!
 Date: Mon, 4 May 2015 20:17:48 +

 Dear Dawood,

 it is not a really good idea to open a new email with the same problem you 
 already posted earlier.
 I see you accepted some suggestions (HTML, seq) but not others (pi is a 
 defined constant in R, do not change it, type pi ENTER to see this.). I would 
 like to add one more, c is a function, do not use it as a variable name (I 
 used cc instead of c).
 I tried to figure out what you want here. The following code might do what 
 you want. It gives you a feeling about how you would create a basic loop. 
 There are nicer ways to do that in R. Note the [i]-s in the for loop!


 cc - 0.5
 xc - 2
 s - 6
 Hc2 - 30
 H - 1
 ep-seq(0.01, 0.49, by=0.001)
 res - numeric(length=length(ep))

 for (i in 1:length(ep)){
 f-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 
 - cos(k*s))/2)/2*Hc2/H)) - trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - 
 cos(k*s))/2)/2*Hc2/H)))
 res[i] - integrate(f,-pi/s,pi/s)$value
 }

 Best,
 daniel
 
 Felad�: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: dawood 
 ahmad [dawoodma...@hotmail.com]
 K�ldve: 2015. m�jus 4. 10:29
 To: r-help@R-project.org
 T�rgy: [R] Need Help!

 Dear Sir/Madam,

 I hope you will be fine. I am new to R language. Recently, I am trying to fit 
 my data with one model.
 I am sending you the code and image file on which you can see the error I am 
 receiving instead of executing.
 If I give a single value to parameter ep, it executes well, but if I make a 
 loop/seq for getting a range of data it shows
 error.I need you help in solving this problem.

 Thanking in advance,

 With Best Regards,
 Dawood

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Need Help!

2015-05-04 Thread Kehl Dániel
Dear Dawood,

it is not a really good idea to open a new email with the same problem you 
already posted earlier.
I see you accepted some suggestions (HTML, seq) but not others (pi is a defined 
constant in R, do not change it, type pi ENTER to see this.). I would like to 
add one more, c is a function, do not use it as a variable name (I used cc 
instead of c).
I tried to figure out what you want here. The following code might do what you 
want. It gives you a feeling about how you would create a basic loop. There are 
nicer ways to do that in R. Note the [i]-s in the for loop!


cc - 0.5
xc - 2
s - 6
Hc2 - 30
H - 1
ep-seq(0.01, 0.49, by=0.001)
res - numeric(length=length(ep))

for (i in 1:length(ep)){
  f-function(k) 1.211*10^(-6)*Hc2/H*(trigamma( ((ep[i] + H/Hc2 + (2*xc/s)^2*(1 
- cos(k*s))/2)/2*Hc2/H)) -  trigamma(((cc + H/Hc2 + (2*xc/s)^2*(1 - 
cos(k*s))/2)/2*Hc2/H)))
  res[i] - integrate(f,-pi/s,pi/s)$value
}

Best,
daniel

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: dawood ahmad 
[dawoodma...@hotmail.com]
Küldve: 2015. május 4. 10:29
To: r-help@R-project.org
Tárgy: [R] Need Help!

Dear Sir/Madam,

I hope you will be fine. I am new to R language. Recently, I am trying to fit 
my data with one model.
I am sending you the code and image file on which you can see the error I am 
receiving instead of executing.
If I give a single value to parameter ep, it executes well, but if I make a 
loop/seq for getting a range of data it shows
error.I need you help in solving this problem.

Thanking in advance,

With Best Regards,
Dawood

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Plotting Confidence Intervals

2015-05-02 Thread Kehl Dániel
Hi Andre,

I think you'll have to give some more information about what you want to see on 
your plot. The 4 intervals with labels? A bar with an interval maybe? Four bars 
with the intervals? Only two showing differences between conf and pred 
intervals?

Also you do miss a 1 here I guess:

p_conf1- predict(ines,interval=confidence,NJ,level=0.99)
p_conf1 #Intervalo de confiança para o estado NJ e para um nivel de 99%
round(p_conf, digits=3)

last line should read p_conf1 here?

Best,
d

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Andre Roldao 
[andre.rafael.rol...@gmail.com]
Küldve: 2015. május 2. 4:49
To: r-help@r-project.org
Tárgy: [R] Plotting Confidence Intervals

Hi Guys,

It's the first time i use R-Help and i hope you can help me.

How can i plot conffidence intervals? with the data bellow:

#Package Austria
library(car)
#head(States)
States1=data.frame(States)

ines=lm(SATM ~ log2(pop) + SATV , data=States1)
summary(ines)

NJ=as.data.frame(States[NJ,c(4,2,3)]) #Identificação do estado NJ


p_conf- predict(ines,interval=confidence,NJ,level=0.95)
p_conf #Intervalo de confiança para o estado NJ e para um nivel de 95%
round(p_conf, digits=3)

p_conf1- predict(ines,interval=confidence,NJ,level=0.99)
p_conf1 #Intervalo de confiança para o estado NJ e para um nivel de 99%
round(p_conf, digits=3)

p_pred2- predict(ines,interval=prediction,NJ,level=0.95)
p_pred2 #Intervalo de perdição para o estado NJ e para um nivel de 95%
round(p_pred2,digits=3)

p_pred3- predict(ines,interval=prediction,NJ,level=0.99)
p_pred3 #Intervalo de perdição para o estado NJ e para um nivel de 99%
round(p_pred3,digits=3)

Thanks

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] (no subject)

2015-05-02 Thread Kehl Dániel
hi,

did you try this?
http://lmgtfy.com/?q=runs+test+in+r

best,
d

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Hosesin 
Nezami [hosseinnezami1...@yahoo.com]
Küldve: 2015. május 2. 9:48
To: R-help@r-project.org
Tárgy: [R] (no subject)

Is there a package that contains Wald Wolfowitze runs test for two sample 
independentortwo sample Runs test?

 Thank's



[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] cbind question, please

2015-04-24 Thread Kehl Dániel
Hello,

I am not sure what you mean by a matrix. If you want to have a matrix, use the 
function matrix, (matrix(c(dog,cat,tree),3))
but I have the feeling you really want a data frame as you are talking about 
variables.
In that case simply use 

mydataframe - data.frame(dog,cat,tree)

If you are not sure what you want, please read the intro to R pdf which is 
included in your installed R library.

Best regards,
daniel

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Erin Hodgess 
[erinm.hodg...@gmail.com]
Küldve: 2015. április 24. 0:41
To: R help
Tárgy: [R]  cbind question, please

Hello!

I have a cbind type question, please:  Suppose I have the following:

dog - 1:3
cat - 2:4
tree - 5:7

and a character vector
big.char - c(dog,cat,tree)

I want to end up with a matrix that is a cbind of dog, cat, and tree.
This is a toy example.  There will be a bunch of variables.

I experimented with do.call, but all I got was
1
2
3

Any suggestions would be much appreciated.  I still think that do.call
might be the key, but I'm not sure.

R Version 3-1.3, Windows 7.

Thanks,
Erin


--
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Simulate values

2015-04-07 Thread Kehl Dániel
Hi Mike,

please keep conversation on the list. Your code looks wy better now.
I would not name the variable variances2 but that is just a matter of taste.
What you could also do as a one-liner is something like

n - 40
REPS - 5
mu - 10
sigma - 5

chisq - replicate(REPS,(n-1)*var(rnorm(n,mu,sigma))/sigma^2)

Try to draw a histogram of the variances2 or chisq values and superimpose the 
theoratical distribution.
?hist and ?curve might help.

Best,
kd

Felad�: Mike Brechb�hler [osiri...@gmx.ch]
K�ldve: 2015. �prilis 8. 0:28
To: Kehl D�niel
T�rgy: Aw: RE: [R] Simulate values

Hey Daniel,

Thanks for your answer.

I changed my commands and ended up with:
matrix - matrix(rnorm(500 * 40, 10, 5), ncol = 40, nrow = 500)
variances1 - apply(matrix, 1, var)
variances2 -(40 - 1) * variances1 / 25
What do you think about it? Does that work and was more or less what you 
expected to see?

Best wishes,
Mike

Gesendet: Dienstag, 07. April 2015 um 05:39 Uhr
Von: Kehl D�niel ke...@ktk.pte.hu
An: Osiris10101 osiri...@gmx.ch, r-help@r-project.org r-help@r-project.org
Betreff: RE: [R] Simulate values
People do not usually do homework stuff here but I do not see the point in 
repeating the same sample 500 times. You might want to simulate 40x500 
independent samples and put those in a matrix (see ?matrix) with lets say 40 
rows and 500 columns. Once done, you can apply calculate the 500 sample 
standard deviations (or the chi-square values) where the ?apply function might 
help you.

Lets start with that and lets see where you get.

kd

Felad�: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Osiris10101 
[osiri...@gmx.ch]
K�ldve: 2015. �prilis 7. 0:52
To: r-help@r-project.org
T�rgy: [R] Simulate values

Hello,

I'm facing the following task:
Simulate 500 values of the statistic (n-1)s^2/sigma^2 based on taking 500
samples of size n=40
from the N(mu=10; sigma^2 = 25) distribution.

I think with the following command:
rep(rnorm(40,10,25),times=500)
I was able to simulate the samples but how I now can simulate the values of
the chi-square-distribution is a mystery to me...

I hope anyone can help me, shouldn't be a big problem...

Thanks in advance!

Reason for posting:
I started a course at the University of Manchester and had to catch up with
R, which I never used back in Switzerland. Now I'm solving some exercises to
get more practice and this is one of them.



--
View this message in context: 
http://r.789695.n4.nabble.com/Simulate-values-tp4705574.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Simulate values

2015-04-06 Thread Kehl Dániel
People do not usually do homework stuff here but I do not see the point in 
repeating the same sample 500 times. You might want to simulate 40x500 
independent samples and put those in a matrix (see ?matrix) with lets say 40 
rows and 500 columns. Once done, you can apply calculate the 500 sample 
standard deviations (or the chi-square values) where the ?apply function might 
help you.

Lets start with that and lets see where you get.

kd

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Osiris10101 
[osiri...@gmx.ch]
Küldve: 2015. április 7. 0:52
To: r-help@r-project.org
Tárgy: [R] Simulate values

Hello,

I'm facing the following task:
Simulate 500 values of the statistic (n-1)s^2/sigma^2 based on taking 500
samples of size n=40
from the N(mu=10; sigma^2 = 25) distribution.

I think with the following command:
rep(rnorm(40,10,25),times=500)
I was able to simulate the samples but how I now can simulate the values of
the chi-square-distribution is a mystery to me...

I hope anyone can help me, shouldn't be a big problem...

Thanks in advance!

Reason for posting:
I started a course at the University of Manchester and had to catch up with
R, which I never used back in Switzerland. Now I'm solving some exercises to
get more practice and this is one of them.



--
View this message in context: 
http://r.789695.n4.nabble.com/Simulate-values-tp4705574.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Correlation question

2015-02-21 Thread Kehl Dániel
Hi,

try

cor(fitted.right,fitted.wrong)

should give 1 as both are a linear function of speed! Hence 
cor(cars$dist,fitted.right)^2 and cor(x=cars$dist,y=fitted.wrong)^2 must be the 
same.

HTH
d

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Jonathan 
Thayn [jth...@ilstu.edu]
Küldve: 2015. február 21. 22:42
To: r-help@r-project.org
Tárgy: [R] Correlation question

I recently compared two different approaches to calculating the correlation of 
two variables, and I cannot explain the different results:

data(cars)
model - lm(dist~speed,data=cars)
coef(model)
fitted.right - model$fitted
fitted.wrong - -17+5*cars$speed


When using the OLS fitted values, the lines below all return the same R2 value:

1-sum((cars$dist-fitted.right)^2)/sum((cars$dist-mean(cars$dist))^2)
cor(cars$dist,fitted.right)^2
(sum((cars$dist-mean(cars$dist))*(fitted.right-mean(fitted.right)))/(49*sd(cars$dist)*sd(fitted.right)))^2


However, when I use my estimated parameters to find the fitted values, 
fitted.wrong, the first equation returns a much lower R2 value, which I would 
expect since the fit is worse, but the other lines return the same R2 that I 
get when using the OLS fitted values.

1-sum((cars$dist-fitted.wrong)^2)/sum((cars$dist-mean(cars$dist))^2)
cor(x=cars$dist,y=fitted.wrong)^2
(sum((cars$dist-mean(cars$dist))*(fitted.wrong-mean(fitted.wrong)))/(49*sd(cars$dist)*sd(fitted.wrong)))^2


I'm sure I'm missing something simple, but can someone explain the difference 
between these two methods of finding R2? Thanks.

Jon
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] simple question - mean of a row of a data.frame

2015-02-11 Thread Kehl Dániel
Hi,

rock[2,] is a data frame and you should not use sum() on a data frame, first 
google hit for the error message gives

http://stackoverflow.com/questions/19697498/r-beginner-argument-is-not-numeric-or-logical-returning-na

Otherwise I think you should use

?rowSums and ?rowMeans if you have numeric data frames.

HTH,
daniel

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Matthew 
Keller [mckellerc...@gmail.com]
Küldve: 2015. február 11. 23:49
To: r help
Tárgy: [R] simple question - mean of a row of a data.frame

Hi all,

Simple question I should know: I'm unclear on the logic of why the sum of a
row of a data.frame returns a valid sum but the mean of a row of a
data.frame returns NA:

sum(rock[2,])
[1] 10901.05

mean(rock[2,],trim=0)
[1] NA
Warning message:
In mean.default(rock[2, ], trim = 0) :
  argument is not numeric or logical: returning NA

I get that rock[2,] is itself a data.frame of mode list, but why the
inconsistency between functions? How can you figure this out from, e.g.,
?mean
?sum

Thanks in advance,

Matt


--
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] plot circles where z values are circles radius

2015-01-23 Thread Kehl Dániel
Hi,

see the help and especially the argument inches:

Argument inches controls the sizes of the symbols. If TRUE (the default), the 
symbols are scaled so that the largest dimension of any symbol is one inch. If 
a positive number is given the symbols are scaled to make largest dimension 
this size in inches (so TRUE and 1 are equivalent). If inches is FALSE, the 
units are taken to be those of the appropriate axes. (For circles, squares and 
stars the units of the x axis are used. For boxplots, the lengths of the 
whiskers are regarded as dimensions alongside width and height when scaling by 
inches, and are otherwise interpreted in the units of the y axis.)

Try 

scale=5000

xlims =c(min(x),max(x))
ylims =c(min(y),max(y))
z=convertToRadius(z)*scale

symbols(x,y, circles=z,  fg='red', inches=FALSE)

HTH
kd

Feladó: R-help [r-help-boun...@r-project.org] ; meghatalmaz#243;: Dr. Alireza 
Zolfaghari [ali.zolfagh...@gmail.com]
Küldve: 2015. január 23. 22:12
To: R-help; r-help-requ...@r-project.org
Tárgy: [R] plot circles where z values are circles radius

Hi there,
I am trying to plot z values using Circle symbol. Each x and y has a value
which will be plotted using a circle where circle's radius is corrlated
with the value of z.

I wrote the code , but unable to change the size of circle no matter what I
chose for Scale. Any help please?

x=c(84390255386 ,84390255386, 78028317380 ,53594648044,422)
y=c(949849442 ,941645043, 840135292, 74, 821632939)
z=c(0.005641896, 0.005641896 ,0.005641896, 0.007978846,0.007978846)

convertToRadius-function(x){return(sqrt(x/pi))}

scale=0.3

xlims =c(min(x),max(x))
ylims =c(min(y),max(y))
z=convertToRadius(z)*scale

symbols(x,y, circles=z,  fg='red')

thanks
Alireza

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Making several plots using a loop function

2014-06-24 Thread Kehl Dániel
Hi,


try something like

main=paste(plot,i)

in the plot command.

HTH,
kd

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: li li [hannah@gmail.com]
Küldve: 2014. június 24. 15:17
To: r-help
Tárgy: [R] Making several plots using a loop function

Hi all,
   When making a bunch of plots using a loop function, how to add title to
reflect different plots.
Specifically, for the code below, I generated 9 plots.  I would like to add
a title to each plot.
For example, the titles will be respectively, plot1, plot 2, … plot 9.
Thank you very much!
Hanna



par(mfrow=c(3,3), pty=s, pch=16, col=blue)
for ( i in 1:9) {
lm1 -  lm(log(run_res[2:11, i]) ~ log(level))
plot(log(level), log(run_res[2:11, i]), xlab=dllution levels,
ylab=%PS-80)
abline(lm1)}

[[alternative HTML version deleted]]


__
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] how to add a table under a plot?

2014-05-23 Thread Kehl Dániel
Hi, 

the function is in the plotrix package, so you have to install and call that 
package first.
After installing see example(addtable2plot).

HTH,
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Helen Gao [helengao...@gmail.com]
Küldve: 2014. május 23. 16:38
To: r-help@r-project.org
Tárgy: [R] how to add a table under a plot?

Dear all,

If you know how to add a table under a plot, could you please send me your
code?

In R documentation, there is a function addtable2plot{}, do you know where
to download the function?

Thank you in advance,
Helen

[[alternative HTML version deleted]]

__
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.


Re: [R] bin a vector of continuous variables

2014-05-15 Thread Kehl Dániel
Hi,

you might try writing your own function, something like

roundDown - function(x) floor(x/100)*100

 roundDown(c(2282,174,273,432))
[1] 2200  100  200  400

and than apply it to your column.

Please use ?dput next time to present your data, and post in plain text, 
instead of HTML.

best,
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Assa Yeroslaviz [fry...@gmail.com]
Küldve: 2014. május 15. 11:54
To: R help forum
Tárgy: [R] bin a vector of continuous variables

Hi all,

I have a data.frame of three columns:
   partner1 partner2 Substract
1_5000_5001_1 1 5001  2282.3435
1_5000_10001_15000110001   174.1275
1_5000_15001_2115001   273.822
1_5000_20001_25000120001   546.27
1_5000_25001_3125001   701.299
1_5000_30001_35000130001   189.2345
...

I would like to create a new column for this data, but to bin the variable
into separate bin of 0-100, 100-200, 200-300, 300-400, etc.
 so that the new data will look like that
   partner1 partner2 SubstractbinnedData
1_5000_5001_1 1 5001  2282.34352200
1_5000_10001_15000110001   174.1275100
1_5000_15001_2115001   273.822 200
1_5000_20001_25000120001   546.27  500
1_5000_25001_3125001   701.299 700
1_5000_30001_35000130001   189.2345100
...

Can someone give me a hint how to achieve this conversion?

thanks
Assa

[[alternative HTML version deleted]]

__
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.


Re: [R] uniform number

2014-05-05 Thread Kehl Dániel
Maybe you thought the binomial distribution?

see
?rbinom

best,
kd

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Rolf Turner [r.tur...@auckland.ac.nz]
Küldve: 2014. május 5. 9:27
To: Ragia Ibrahim
Cc: r-help@r-project.org
Tárgy: Re: [R] uniform number

On 05/05/14 17:05, Ragia Ibrahim wrote:

 Dear group,
 How to generate  uniform probability choosing p to be 2% and 5%, in separate 
 trials for 100 times.

No idea WTF you are talking about.  Can you formulate a question that is
comprehensible to the human mind?

cheers,

Rolf Turner

__
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.


Re: [R] locating a data value in 3-dimensional data set

2014-04-08 Thread Kehl Dániel
Dear Mamuash Bukana,

is this a data frame with variable names you indicated?

you will need something like which(dataframename$variablename == x) 
but if you have more you might use 

HTH
kd

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: mamuash bukana [mamushbuk...@gmail.com]
Küldve: 2014. április 8. 15:50
To: r-help@r-project.org
Tárgy: [R] locating a data value in 3-dimensional data set

I have a 3-dimentional data set with dimensions longitude,
latitude, and time. Unfortunately, when I look at the range of
values in the data set, I noticed some very extremely large(positive
and negative) values which are unexpected to be there. So I wanted to
point-out the location (lon, lat and time) which these extreme values
correspond to in order to see what is happening there. But I could not
point-out these grid points and time.

I tried:
which(3ddata==x) # 3ddata is name of data set, x is the observed extreme value
But this couldn't help me.

Any suggestion please?

Thanks

B

__
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.


[R] continuous time AR - predict/interpolate

2014-03-30 Thread Kehl Dániel
Dear Members,

I have a dataset that is similar to the first example in the car function, cts 
package

data(V22174)
fit - car(V22174,scale=0.2,order=7, ctrl=car_control(trace=TRUE))
summary(fit)

I would like to ask if there is a way to get the predicted/fitted values for 
all the timepoints 1:784 not just for the timepoints when there are 
observations (which is pre2). I tried to read through car and car_control, 
tried predict(fit, newdata), but without success.

I am not really into cont time ar, a friend of mine asked me to help him out 
with the R code, so sorry if there is a conceptual error in the question, not 
my fault! :)

thanks a lot
kd
__
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] Computing predictive values

2014-03-30 Thread Kehl Dániel
Hi Tom,

I think you are going to get better answers if you include some code which 
helps reproducing what you are doing for other users (posting guide). Exporting 
regression outputs to Excel does not seem to be the way to go. Aren't you just 
looking for ?predict. I am sure R can do the job for you but give an example 
please!

best
kd


Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: steve tom [selli...@uoguelph.ca]
Küldve: 2014. március 30. 3:22
To: r-help@r-project.org
Tárgy: [R] Computing predictive values

Hi All,

I was unable to find help in search history.

I have all my regression outputs in my environment tab, and wish to run
them against my data, so that instead of having to export regression outputs
to excel, and manually connect data-regression.

I have predictive regressions that forecast 5 days ahead and whose rolling
windows are 200 days trailing. I want to compute the daily predictions in R,
using my regression outputs logged in my environment.

Thanks so much for your time, been using R help for a year but this is the
first time I've needed to post.





--
View this message in context: 
http://r.789695.n4.nabble.com/Computing-predictive-values-tp4687832.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.


Re: [R] Determine breaks based on a break type...

2014-03-22 Thread Kehl Dániel
Hi,

you possibly know that there are a lot of methods to determine the number of 
bins. As a default R has the Sturges method. I think it does something like

x - runif(100)
mybreaks - hist(runif(x))$breaks

r - max(x)-min(x)
br - nclass.Sturges(x) #note this is a really simple approach and see 
edit(nclass.Sturges)
brn - 0:br
pretty(min(x)+brn*r/br, n=br)

I tried to make the steps clear, the pretty function does the job in the end.

Hope that helps (although I do not know if it is faster, but you can try it on 
your own), best
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Jonathan Greenberg [j...@illinois.edu]
Küldve: 2014. március 22. 17:15
To: r-help
Tárgy: [R] Determine breaks based on a break type...

R-helpers:

I was wondering, given a vector of data, if there is a way to
calculate the break points based on the breaks= parameter from
histogram, but skipping all the other calculations (all I want is the
breakpoints, not the frequencies).  I can, of course, simply run the
histogram and extract the break component:

mybreaks - hist(runif(100))$breaks

But is there a faster way to do this, if this is all I want?

--j

--
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

__
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.


Re: [R] Assign numbers in R

2014-03-12 Thread Kehl Dániel
Hi,

is this homework? 
Try
d - c(8,7,5,5,3,3,2,1,1,1)

r - rep(1,length(d))

for (i in 2:length(d)) {
  
  if (d[i] != d[i-1]) {
r[i]=r[i-1]+1;
  }
  else {
r[i] = r[i-1];
  }
}

Although I am sure there are better solutions!

HTH
daniel


Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: T Bal [studentt...@gmail.com]
Küldve: 2014. március 12. 10:13
To: r-help@r-project.org
Tárgy: [R] Assign numbers in R

Hi,
I have the following numbers:

d - c(8,7,5,5,3,3,2,1,1,1)

I want to convert these into the following numbers:

r:
1,2,3,3,4,4,5,6,6,6

So if two numbers are different increment it if they are same then assign
the same number:

r - NULL

for (i in 1:length(d)) {

 if (d[i] != d[i+1]) {
  r[i] =i+1;
 }
 else {
  r[i] = i;
 }
 }

But this is not correct. How can I solve this problem? or how can I solve
it in a different way? Thanks a lot!

[[alternative HTML version deleted]]

__
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.


Re: [R] Fwd: Using comma as decimal mark in plots

2014-03-07 Thread Kehl Dániel
Hi,

take a look at this old conversation. I do not know about an other workaround, 
but maybe somebody else will know something. As we also use commas in Hungary, 
I am also affected by this.

https://stat.ethz.ch/pipermail/r-help/2002-January/018030.html

HTH
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Lotharster [lothars...@gmail.com]
Küldve: 2014. március 7. 15:51
To: r-h...@stat.math.ethz.ch
Tárgy: [R] Fwd: Using comma as decimal mark in plots

Hi,

I am preparing plots for a german publication. Therefore, I would like
to use a comma as decimal mark instead of a point. How do I change
this default in R?

I could not find anything in the help pages, maybe you can help me out.

Thanks,

Lothar

__
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.


Re: [R] fitting a time series into a GARCH model using fGarch

2014-02-25 Thread Kehl Dániel
Dear Charles,

see the help file and the examples at
http://cran.r-project.org/web/packages/fGarch/fGarch.pdf
or use ?garchFit

in the examples you will see for example:

garchFit(~ garch(1,1), data = x.vec, trace = FALSE)

Try something like that. Make sure you provide the package of the function next 
time!

HTH
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Charles Thuo [tcmui...@gmail.com]
Küldve: 2014. február 25. 8:36
To: r-help@r-project.org
Tárgy: [R] fitting a time series into a GARCH model using fGarch

I have been trying to fit a time series object using the garchFit()
function. However am getting the results below

 class(v.ts)
[1] ts

fit=garchFit(v.ts)
Error in if (allVarsTest != 1) { : missing value where TRUE/FALSE needed

I do not understand the error. Which missing value  is required. Kindly
assist.


Charles.

[[alternative HTML version deleted]]

__
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.


Re: [R] I am new to R

2014-02-13 Thread Kehl Dániel
Dear Shikami,

R comes with excellent material, look for it in your /doc/manual folder, start 
with R-intro.pdf.
Have fun on your hopfully long journey with R!

daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Shikami Kennedy [shika...@gmail.com]
Küldve: 2014. február 13. 21:16
To: r-help@r-project.org
Tárgy: [R] I am new to R

Hello there,
I am new to R and have no previous experience using any other statistics
software. Can someone send me basic R notes to help me start off for the
very first time?



*With Kind regards,*

* God bless you*



* Shikami K. Akweyu Manager; Fisheries ComponentKenya Coastal Development
Project (KCDP) State Department of Fisheries: Ministry of Agriculture,
Livestock and Fisheries Phone: +254-0722 887 838 / 0736 887 838 Mombasa*

[[alternative HTML version deleted]]

__
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.


Re: [R] match - returns a vector of the positions of (first) matches - looking for All positions.

2014-02-03 Thread Kehl Dániel
Dear Witold,

as a first hint: read posting guide please! People are answering in their free 
time, so please try to be polite!

For your first problem: what are you expecting? You have a dataset where most 
of the values is missing, the others all 0's most of the time, and some Inf 
values as well...

For the second problem: give a reproducible example, please.

daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Witold E Wolski [wewol...@gmail.com]
Küldve: 2014. február 3. 11:18
To: r-help@r-project.org
Tárgy: [R] match - returns a vector of the positions of (first) matches - 
looking for All positions.

Looking for a build in function which returns a vector of the
positions of _ALL_ matches.




--
Witold Eryk Wolski

__
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.


Re: [R] Error Help only 0's may be mixed with negative subscripts

2014-01-31 Thread Kehl Dániel
Dear Agapitus,

we do not know what your variables look like but I assume ((zlim[2] - 
z_invDist)/zlen) * 7 produces a vector with both positive and negative 
numbert and you are using these numbers to extract elements of an other vector. 
If the numbers were all positive or negative, it would work, in this case R 
does not understand what you want.

Try
x - 1:5
x[1]
x[-1]
x[-1:1] #gives the same error

Before posting again you should read an Intro to R at 
http://cran.r-project.org/doc/manuals/R-intro.pdf

best wishes
daniel

ps: Gandhi instead of Gadhi?

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Agapitus Kato [agapitusk...@gmail.com]
Küldve: 2014. január 31. 10:01
To: r-help@r-project.org
Tárgy: [R] Error Help only 0's may be mixed with negative subscripts

Help Please. Iam drawing a plot i R_Studio but consistently get this error:
Error in colorlut2[((zlim[2] - z_invDist)/zlen) * 7] : only 0's may be
mixed with negative subscripts--

*Whenever you are confronted with an opponent. Conquer him with love.
Mahatma Gadhi*

[[alternative HTML version deleted]]

__
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.


Re: [R] Markov chain simulation

2014-01-28 Thread Kehl Dániel
Hi, see inline

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: Armel KAPTUE [armel.kap...@sdstate.edu]
Küldve: 2014. január 28. 8:16
To: R-help@r-project.org
Tárgy: [R] Markov chain simulation

Hi there,

I'm wonder if in R there is a way to simulate a discrete Markov chains with
a specific number of occurence of state knowing the transition matrixway.

Indeed there are many ways to do that in R!

For example, how to simualte a markov chain of length n with p occurences
(pn) of the sate '0' for a transition matrix defined by:

I am not sure what you mean here?! If you give the length of the chain, 
depending on the transition matrix you are going to get some occurences of 
state '0', I do not think you can specify n, p and the transition matrix all at 
once!

TransitionMatrix- matrix(c(0.7, 0.3, 0.4, 0.6),byrow=TRUE, nrow=2)

colnames(TransitionMatrix) - c('0','1')
row.names(TransitionMatrix) - c('0','1')

Please try googling first, there are a lot of good examples on your problem, 
among the first ones:

http://stackoverflow.com/questions/2754469/r-library-for-discrete-markov-chain-simulation

Best
daniel

Thanks,
--
Armel

[[alternative HTML version deleted]]

__
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.


Re: [R] how to replace NA values

2014-01-19 Thread Kehl Dániel
Dear Kinsly,

try http://bit.ly/1mhXOfH

Although values are usually missing for some good reason. Changing them to 0 
might be very dangerous, R is going to think that ID3, 6 and 8 are all newborn 
babies!

best
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmaz#243;: kingsly [ecoking...@yahoo.co.in]
Küldve: 2014. január 19. 20:39
To: r-help@r-project.org
Tárgy: [R] how to replace NA values

Dear R community

I have a large data set contain some empty cells. Because of that,  may be I am 
wrong, NA values are produced.
Now I want replace both empty and NA values with zero.

Elder1 - data.frame(
  ID=c(ID1,ID2,ID3,ID6,ID8),
  age=c(38,35,,NA,NA))
Output I am expecting

ID   age
ID1  38
ID2  35
ID3  0
ID6  0
ID8  0

In advance I thank your help.



--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-replace-NA-values-tp4683831.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]


__
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] Figure title

2012-06-20 Thread Kehl Dániel
Try

?bquote

HTH
kd

2012.06.20. 10:36 keltezéssel, Joaquim J.S. Ramalho írta:
 Hi,



 I created several figures and their titles should appear like this:



 Figure 1: Monte Carlo results for alternative estimators of structural
 parameters (N = 100, T = 5)

 Because N and T change across figures, my code includes the following lines:



 N.set- 100

 T.set- 5

 mtext(?Figure 1: Monte Carlo results for alternative estimators of
 structural parameters,side=3,outer=T,line=4,cex=0.8)

 mtext(as.expression(substitute(list(N==p1,T==p2),list(p1=N.set[1],p2=T.set[1
 ]))),side=3,outer=T,line=2,cex=0.8)



 However, I do not know how to merge the two last command lines in order to
 the title appear in a single line. Is it possible to do that?



 Thanks,



 José Santos








   [[alternative HTML version deleted]]



 __
 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.


[[alternative HTML version deleted]]

__
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] Smoothing a persp graph

2012-06-19 Thread Kehl Dániel
Take a look at the

kde2d
function in the MASS package, maybe it helps.

Best
kd



2012.06.19. 14:26 keltezéssel, Guillaume Chapron írta:
 Hi,

 I'm unable to find a way to smooth data for a persp() graph.

 Example, suppose that I have data x,y,z like this:

 x- 1:10
 y- 1:10

 k- 20
 z- outer(x, y, *) + matrix( k*runif(100, -1, 1), 10, 10)
 persp(x, y, z, theta = 35, phi = 25)

 The graph is not very nice. Is there a way to smooth the z data so that at 
 the end the graph would look more like something like that:

 k- 2
 z- outer(x, y, *) + matrix( k*runif(100, -1, 1), 10, 10)
 persp(x, y, z, theta = 35, phi = 25)

 There seems to be many smoothing functions in R (e.g. loess) but I have not 
 been able to find one for a 3D graph.

 Thanks!

 Guillaume

 __
 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.





[[alternative HTML version deleted]]

__
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] R matrix help

2012-06-14 Thread Kehl Dániel

If you have your data in x, you can try something like

matrix(x,length(x)/4,4)

hth
kd


2012.06.14. 14:51 keltezéssel, karthicklakshman írta:

Dear R experts,

I am interested in getting the dimensions for the matrix dynamically, based
on the the number of elements in a matrix for example. if the number is 12,
I should get dim= 3X4,  if it is 20, dim=5X4.
please help me do this.

Thank you
Regards
karthick

--
View this message in context: 
http://r.789695.n4.nabble.com/R-matrix-help-tp4633372.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.


Re: [R] Rank a numerical variable

2012-05-28 Thread Kehl Dániel

hi,

read an Introduction to R.

?rank is what you are looking for?

kd

2012.05.28. 20:17 keltezéssel, gaiarrido írta:

hello,
Is there any function in R to transform a numerical continuos variable in a
ranked variable?

Thanks

-
Mario Garrido Escudero
PhD student
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca. Agrícola
Universidad de Salamanca
--
View this message in context: 
http://r.789695.n4.nabble.com/Rank-a-numerical-variable-tp4631627.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.


Re: [R] estimation problem

2012-05-04 Thread Kehl Dániel

Dear Petr,

thank you for your input.
I tried to experiment with (probably somewhat biased) truncated means 
like in the following code.

How I got the 225 as a truncation limit is a good question. :)

REPS1 - REPS2 - 1000
N1 - 10
N2 - 3
N - N1+N2
x1 - rep(0,N1)
x2 - rnorm(N2,300,100)
x - c(x1,x2)

n - 1000

for (i in 1:REPS1){
  x_sample - sort(sample(x,n,replace=FALSE),TRUE)
  x_trunc - x_sample[1:225]
  REPS1[i] - mean(x_sample)*N
  REPS2[i] - sum(x_trunc)/n*N
  }

sum(x2)
mean(REPS1)
mean(REPS2)
sd(REPS1)
sd(REPS2)
sd(REPS2)/sd(REPS1)


Best,
daniel

2012.05.03. 17:45 keltezéssel, Petr Savicky írta:

On Thu, May 03, 2012 at 03:08:00PM +0200, Kehl Dániel wrote:

Dear List-members,

I have a problem where I have to estimate a mean, or a sum of a
population but for some reason it contains a huge amount of zeros.
I cannot give real data but I constructed a toy example as follows

N1- 10
N2- 3000
x1- rep(0,N1)
x2- rnorm(N2,300,100)
x- c(x1,x2)

n- 1000

x_sample- sample(x,n,replace=FALSE)

I want to estimate the sum of x based on x_sample (not knowing N1 and N2
but their sum (N) only).
The sample mean has a huge standard deviation I am looking for a better
estimator.

Hi.

I do not know the exact answer, but let me formulate the following observation.
If the question is redefined to estimate the mean of nonzero numbers, then
an estimate is mean(x_sample[x_sample != 0]). Its standard deviation in your
situation may be estimated as

   res- rep(NA, times=1000)
   for (i in seq.int(along=res)) {
   x_sample- sample(x,n,replace=FALSE)
   res[i]- mean(x_sample[x_sample != 0])
   }
   sd(res)

   [1] 18.72677 # this varies with the seed a bit

The observation is that this cannot be improved much, since the estimate
is based on a very small sample. The average size of the sample of nonzero
values is N2/(N1+N2)*n = 29.1. So, the standard deviation should be
something close to 100/sqrt(29.1) = 18.5376.

Petr Savicky.

__
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.


[R] estimation problem

2012-05-03 Thread Kehl Dániel

Dear List-members,

I have a problem where I have to estimate a mean, or a sum of a 
population but for some reason it contains a huge amount of zeros.

I cannot give real data but I constructed a toy example as follows

N1 - 10
N2 - 3000
x1 - rep(0,N1)
x2 - rnorm(N2,300,100)
x - c(x1,x2)

n - 1000

x_sample - sample(x,n,replace=FALSE)

I want to estimate the sum of x based on x_sample (not knowing N1 and N2 
but their sum (N) only).
The sample mean has a huge standard deviation I am looking for a better 
estimator.
I was thinking about trimmed (or left trimmed as my numbers are all 
positive) means or something similar,

but if I calculate trimmed mean I do not know N2 to multiply with.

Do you have any idea or could you give me some insight?

Thanks a lot:
Daniel

__
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] estimation problem

2012-05-03 Thread Kehl Dániel

Dear Jeff,

thank you for the response.
Of course I know this is a theory question still I hope to get some 
comments on it
(if somebody already dealt with alike problems might suggest a package 
and it would not take longer than saying this is a theoretical question)
The values are counts, so 0 means those cases do not have this item, 
they have 0, as such it means a real zero, they are valid members.


thanks,
daniel

2012.05.03. 16:42 keltezéssel, Jeff Newmiller írta:

Although you have provided R code to illustrate your problem, it is 
fundamentally a statistics theory question, and belongs somewhere else like 
stats.stackexchange.net.

When you post there, I recommend that you spend more effort to identify why the 
zeros are present. If they are indicators of unknown values, that will be very 
different than if zeros are valid members of the population.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.us Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.



Kehl Dánielke...@ktk.pte.hu  wrote:


Dear List-members,

I have a problem where I have to estimate a mean, or a sum of a
population but for some reason it contains a huge amount of zeros.
I cannot give real data but I constructed a toy example as follows

N1- 10
N2- 3000
x1- rep(0,N1)
x2- rnorm(N2,300,100)
x- c(x1,x2)

n- 1000

x_sample- sample(x,n,replace=FALSE)

I want to estimate the sum of x based on x_sample (not knowing N1 and
N2
but their sum (N) only).
The sample mean has a huge standard deviation I am looking for a better

estimator.
I was thinking about trimmed (or left trimmed as my numbers are all
positive) means or something similar,
but if I calculate trimmed mean I do not know N2 to multiply with.

Do you have any idea or could you give me some insight?

Thanks a lot:
Daniel

__
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.


[R] compare two matrices

2012-04-10 Thread Kehl Dániel

Dear Members,

I have two estimated transition matrices and I want to compare them.
In fact I want to check the hypothesis if they come from the same process.
I tried to look for some test but all I found was independence test of 
contingency tables.
The following code shows that the usual chi-squared test statistic does 
not follow chisq distribution.


MCRepl - 5000
khi12 - rep(0,MCRepl)

for (i in 1:MCRepl){
  n - 1

  M1 - matrix(table(sample(1:9, size = n, replace = TRUE)),3,3)
  M1 - M1/rowSums(M1)
  M2 - matrix(table(sample(1:9, size = n, replace = TRUE)),3,3)
  M2 - M2/rowSums(M2)

  khi12[i] - sum((M1-M2)^2/M2)

}
plot(density(khi12))

Is there a procedure implemented in R to make this comparison? If not, 
what could be a nice test statistic?


Thank you so much,
Daniel

__
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] simple matrix calculation

2012-03-29 Thread Kehl Dániel

Dear David, Ted, Kjetil, Petr,

thank you, you guys did a great job, I'll use your ideas in the future 
for sure.

After I sent the question I figured a way, see below.

x - 1:81
b - 1:3
Q - matrix(x,9,9)
result - matrix(matrix(colSums(matrix(t(Q),3)),,3,TRUE) %*% b,3,3)

I hope there is no error in this solution and you can use this idea 
sometime!


Thank you again, have a great day
Daniel

2012.03.29. 8:48 keltezéssel, Petr Savicky írta:

On Wed, Mar 28, 2012 at 10:46:11PM +0200, Kehl Dániel wrote:

Dear list-members,

I have a 9-by-9 matrix lets call it A with first row a11, a12, a13,...,
a19 etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3 blocks
- first is
 a11, a12, a13
 a21, a22, a23
 a31, a32, a33
- I want to get rowSums of this A1 matrix
- Multiply A1*B and get a scalar, the first element of my new 3x3 matrix.

Hi.

Try the following, which is based on the solution by Ted Harding.

   # some input
   A- matrix(1:81, nrow=9, ncol=9)
   B- 7:5

   # compute the 3 x 3 matrix
   C- diag(3)[rep(1:3, each=3), ]
   D- cbind(rbind(B, 0, 0), rbind(0, B, 0), rbind(0, 0, B))
   R1- D %*% A %*% C

   # compare with another approach
   E- A * matrix(B, nrow=9, ncol=9) # component wise product
   C- diag(3)[rep(1:3, each=3), ]
   R2- t(C) %*% E %*% C

   max(abs(R1 - R2)) # [1] 0

Hope this helps.

Petr Savicky.

__
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.


[R] simple matrix calculation

2012-03-28 Thread Kehl Dániel

Dear list-members,

I have a 9-by-9 matrix lets call it A with first row a11, a12, a13,..., 
a19 etc.

I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3 blocks
- first is
a11, a12, a13
a21, a22, a23
a31, a32, a33
- I want to get rowSums of this A1 matrix
- Multiply A1*B and get a scalar, the first element of my new 3x3 matrix.

I could do that with loop. Can you suggest something that is more 
elegant and faster?


Thank you
Daniel

__
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] lists everywhere

2011-12-05 Thread Kehl Dániel

Dear list members,

I have a really simple problem.
I connected to a DB and have the following query

adat - dbGetQuery(con, paste(select * from kmdata where SzeAZ=', 
szeazok[i], ' order by datum, sep=))


now I have the data in the adat variable which is a list. In fact the 
elements of the list are lists as well

 is.list(adat)
[1] TRUE
 is.list(adat[10])
[1] TRUE
 is.list(adat[[10]])
[1] FALSE
 is.vector(adat[[10]])
[1] TRUE

I simply want to use a function with sapply on the 13-76th columns of 
the original list.
sapply(data[[13:76]], myfunc) does not work of course. I tried to define 
13:76 in a vector, still no result.

How is it possible?

thanks a lot
d

__
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] SOLVED, Re: lists everywhere

2011-12-05 Thread Kehl Dániel

nevermind, typo (and some gray hair)

sorry

12/5/2011 8:21 PM keltezéssel, Kehl Dániel írta:

Dear list members,

I have a really simple problem.
I connected to a DB and have the following query

adat - dbGetQuery(con, paste(select * from kmdata where SzeAZ=', 
szeazok[i], ' order by datum, sep=))


now I have the data in the adat variable which is a list. In fact the 
elements of the list are lists as well

 is.list(adat)
[1] TRUE
 is.list(adat[10])
[1] TRUE
 is.list(adat[[10]])
[1] FALSE
 is.vector(adat[[10]])
[1] TRUE

I simply want to use a function with sapply on the 13-76th columns of 
the original list.
sapply(data[[13:76]], myfunc) does not work of course. I tried to 
define 13:76 in a vector, still no result.

How is it possible?

thanks a lot
d

__
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.


Re: [R] [SOLVED]looking for beta parameters

2011-11-29 Thread Kehl Dániel
I managed to solve the problem myself without using this code.

thx

2011-11-24 12:26 keltezéssel, Kehl Dániel írta:
 Dear Community,

 I am trying to write code for the following problem.
 Lets assume we have a beta distribution.
 I know one quantile, lets say, 10% of the mass lies above .8, that is 
 between .8 and 1.
 In addition, I  know that the average of this truncated tail is a 
 given number, lets say .86.
 I have found the beta.select function in the LearnBayes package, which 
 is as follows:

 function (quantile1, quantile2)
 {
 betaprior1 = function(K, x, p) {
 m.lo = 0
 m.hi = 1
 flag = 0
 while (flag == 0) {
 m0 = (m.lo + m.hi)/2
 p0 = pbeta(x, K * m0, K * (1 - m0))
 if (p0  p)
 m.hi = m0
 else m.lo = m0
 if (abs(p0 - p)  1e-04)
 flag = 1
 }
 return(m0)
 }
 p1 = quantile1$p
 x1 = quantile1$x
 p2 = quantile2$p
 x2 = quantile2$x
 logK = seq(-3, 8, length = 100)
 K = exp(logK)
 m = sapply(K, betaprior1, x1, p1)
 prob2 = pbeta(x2, K * m, K * (1 - m))
 ind = ((prob2  0)  (prob2  1))
 app = approx(prob2[ind], logK[ind], p2)
 K0 = exp(app$y)
 m0 = betaprior1(K0, x1, p1)
 return(round(K0 * c(m0, (1 - m0)), 2))
 }

 I assume one could change this code to get the results I need, but 
 some parts of the function are not clear for me, any help would be 
 greatly appreciated.

 Thanks a lot:
 Daniel


[[alternative HTML version deleted]]

__
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] Why it is happeing?

2011-11-26 Thread Kehl Dániel
Note that current implementations of*R*use 32-bit integers for integer 
vectors, so the range of representable integers is restricted to 
about/+/-2*10^9/:|double 
http://stat.ethz.ch/R-manual/R-patched/library/base/html/double.html|s 
can hold much larger integers exactly.

hth
d

2011-11-26 13:05 keltezéssel, Christofer Bogaso írta:
 Dear all, I had following calculations with R:
 x = vector(length = 4)
 x[1] = 1
 x[2] = 3
 x[3] = 123456789123456
 x[4] = -9876543219876
 as.integer(x)
 [1]  1  3 NA NA
 Warning message:
 NAs introduced by coercion

 What went wrong?

 Thanks and regards,

 __
 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.




[[alternative HTML version deleted]]

__
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] looking for beta parameters

2011-11-24 Thread Kehl Dániel

Dear Community,

I am trying to write (update) a code for the following problem.
Lets assume we have a beta distribution.
I know one quantile, lets say, 10% of the mass lies above .8, that is 
between .8 and 1.
In addition, I  know that the average of this truncated tail is a 
given number, lets say .86.
I have found the beta.select function in the LearnBayes package, which 
is as follows:


function (quantile1, quantile2)
{
betaprior1 = function(K, x, p) {
m.lo = 0
m.hi = 1
flag = 0
while (flag == 0) {
m0 = (m.lo + m.hi)/2
p0 = pbeta(x, K * m0, K * (1 - m0))
if (p0  p)
m.hi = m0
else m.lo = m0
if (abs(p0 - p)  1e-04)
flag = 1
}
return(m0)
}
p1 = quantile1$p
x1 = quantile1$x
p2 = quantile2$p
x2 = quantile2$x
logK = seq(-3, 8, length = 100)
K = exp(logK)
m = sapply(K, betaprior1, x1, p1)
prob2 = pbeta(x2, K * m, K * (1 - m))
ind = ((prob2  0)  (prob2  1))
app = approx(prob2[ind], logK[ind], p2)
K0 = exp(app$y)
m0 = betaprior1(K0, x1, p1)
return(round(K0 * c(m0, (1 - m0)), 2))
}

I assume one could change this code to get the results I need, but some 
parts of the function are not clear for me, any help would be greatly 
appreciated.


Thanks a lot:
Daniel

__
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] sorry, [WinBUGS] question

2011-09-05 Thread Kehl Dániel

Dear Community,

I know this is not the place to ask WinBUGS questions, but I did not get 
any answers on other lists.
I am rather new to the BUGS language and to bayesian modeling, excuse me 
for probably simple questions.
I have to conduct a bayesian meta-analysis of some data. We have 
collected observational and randomized studies related to a certain 
field of interest.
The idea is to analyse the randomized studies with two different priors. 
One is non-informative, the other is calculated from the observational 
ones. We also want to use a sceptical prior.
The code I used for the non-informative prior analysis and to get the 
other prior is following:


model
{
   for( i in 1 : Num ) {
 rc[i] ~ dbin(pc[i], nc[i])
rt[i] ~ dbin(pt[i], nt[i])
log(pc[i]) - mu[i]
log(pt[i]) - mu[i] + delta[i]
mu[i] ~ dnorm(0,1.0E-5)
delta[i] ~ dnorm(d, tau)
   }
   d ~ dnorm(0,1.0E-6)
   tau ~ dgamma(0.001,0.001)
   sigma - 1 / sqrt(tau)
   relr - exp(d)
}

which appears to work fine after loading data and initials. (there was a 
study with 0 treated and 0 control cases, I had to exclude that one for 
some reasons, is there a solution for this?)
If I understand right, I can interpret the relr as bayesian estimate 
of relative risk, with credible interval etc.

I have some questions in connection with the informative prior analysis:
- after running this same code for the observational data, how do I 
change the specification of d and tau?

- how can I get posterior probabilities like relr1?
- usually how many iterations, thin etc. do we use?
- can I get nice graphics with both priors and posteriors on it?

I do have to learn everything on my own, so any help is greatly 
appreciated.
I know R and the BUGS package are able to communicate, is anybody can 
help to solve the task through the R interface would be great.


Thank you for you answer or any kind of help:
Daniel

__
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] conditions simpler way

2011-06-05 Thread Kehl Dániel

Dear All,

I have a MCMC result in x1. I was wondering if there is a simpler, more 
elegant way of evaluating the estimate of an integral then this (I am 
pretty sure there is):
Also if I want to count the x's say -1x2 but not the ones in the burn 
in period.


[code]
z - -2
burnin - 2000
int1 - 
length(x1$x[(burnin+1):length(x1$x)][x1$x[(burnin+1):length(x1$x)]z])/(length(x1$x)-burnin)

[\code]

Thank you:
Daniel

__
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] Simple MC integration question

2011-05-17 Thread Kehl Dániel

Dear Community,

I try to compute the variance of a MC integral where I know the 
analytical solution.

The function is exp(-x) integrated on the interval (2,4). (Rizzo example)
The true value is exp(-2)-exp(-4)~.1170196

I have the following short code:
code
iter - 1
MCs - numeric(iter)
n - 5000
a - 2; b - 4

for (i in 1:iter){
  x - runif(n, a, b)
  MCs[i] - (b-a)*mean(exp(-x))
  }

hist(MCs, freq=FALSE)
\code

Which shows a nice normal distribution around the theoretical value, 
with a small variance.

On the 125. page of the book the author says that the
Var(theta_hat)=(b-a)^2/m*Var(g(X)).

I try to compare the theoretical normal distribution with the simulated 
one, but the two normal distributions are far from each other.
I thought Var(g(X)) was 1, because g(x) is exponential with lambda 1, 
but probably thats not true.


Any help is appreciated, thanks:
Daniel

__
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] Generalized Linear Model

2011-04-25 Thread Kehl Dániel

Hi!

Try to read about the glm function, type:

?glm

in your R editor. It looks like you have contingency tables, maybe a 
loglin model would be good to start with.


D

2011-04-25 12:28 keltezéssel, Megan írta:

Hello,

I am trying to run a generalized linear model but do not know where to
begin. I have attached my data to R but do not know where to go from there.
I have two independent variables (each has two factors associated with them)
and two dependent variables, each with either a yes/no response which I've
valued either 0 or 1 in the data set. Any input would be greatly
appreciated.

--
View this message in context: 
http://r.789695.n4.nabble.com/Generalized-Linear-Model-tp3473924p3473924.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.


[R] all combinations with replacement

2011-04-21 Thread Kehl Dániel

Dear all,

is there an easy way to get all possible combinations (?) with replacement.
If n=6, k=3, i want something like

0 0 6
0 5 1
0 4 2
0 3 3
0 2 4
.
.
.
5 0 1
5 1 0
6 0 0

I tried to look at combn() but I could not get this done with it.

Thank you in advance:
Daniel

__
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] all combinations with replacement

2011-04-21 Thread Kehl Dániel

Thank you.
I only need those where the rowsum = n.
I could choose those with code, but I dont think it is efficient that way.

daniel

2011-04-21 12:33 keltezéssel, Dimitris Rizopoulos írta:


expand.grid(rep(list(0:6), 3)) 


__
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] What does the - operator mean?

2011-04-21 Thread Kehl Dániel

maybe

help (-)

helps

daniel

2011-04-21 12:14 keltezéssel, Cliff Clive írta:

I should probably point out that in the example, ecov_xy  and decay are
scalars, and x and y are vectors.


--
View this message in context: 
http://r.789695.n4.nabble.com/What-does-the-operator-mean-tp3466657p3466672.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.


Re: [R] Merge matrix

2011-04-12 Thread Kehl Dániel


?cbind should solve your problem


2011-04-12 07:54 keltezéssel, pankaj borah írta:
 I have two matrices A and B

 dim (A)
 [1] 30380   104

 dim(Bt)
 [1] 3038063

 I want to  combine both A and B to matrix C where
 dim(C)
 [1] 30380   167

 How do I do that ?


 Regards,

 Pankaj Barah
 Department of Biology,
 Norwegian University of Science  Technology (NTNU)
 Realfagbygget, N-7491

   [[alternative HTML version deleted]]



 __
 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.


[[alternative HTML version deleted]]

__
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] Dirichlet surface

2011-03-30 Thread Kehl Dániel

Dear David,

I think that is a small bug too, maybe because the function is constant?
is there a nice way to put the c(0,2.1) argument optionally, only if all 
the parameters are 1?

Should I post the problem somewhere else (developers maybe?)

thanks:
Daniel

2011-03-30 04:42 keltezéssel, David Winsemius írta:


On Mar 29, 2011, at 4:45 PM, Kehl Dániel wrote:


Dear list members,

I want to draw surfaces of Dirichlet distributions with different 
parameter settings.

My code is the following:
#begin code
a1 - a2 - a3 - 2
#a2 - .5
#a3 - .5
x1 - x2 - seq(0.01, .99, by=.01)

f - function(x1, x2){
 term1 - gamma(a1+a2+a3)/(gamma(a1)*gamma(a2)*gamma(a3))
 term2 - x1^(a1-1)*x2^(a2-1)*(1-x1-x2)^(a3-1)
 term3 - (x1 + x2  1)
 term1*term2*term3
 }

z - outer(x1, x2, f)
z[z=0] - NA

persp(x1, x2, z,
 main = Dirichlet Distribution,
 col = lightblue,
 theta = 50,
 phi = 20,
 r = 50,
 d = 0.1,
 expand = 0.5,
 ltheta = 90,
 lphi = 180,
 shade = 0.75,
 ticktype = detailed,
 nticks = 5)
#end code

It works fine (I guess), except for a1=a2=a3=1. In that case I get 
the error: Error in persp.default...  invalid 'z' limits.

The z matrix has only elements 2 and NA.


Might be a buglet in persp. If you set the zlim argument to c(0,2.1), 
you get the expected constant plane at z=2 for those arguments.


Any ideas are appreciated.

Thank you:
Daniel
University of Pécs

__
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.


Re: [R] Dirichlet surface

2011-03-30 Thread Kehl Dániel

It helped a lot indeed, thank you very much!
Now I understand why it was a problem for persp!

Daniel

2011-03-30 10:31 keltezéssel, Gavin Simpson írta:

On Wed, 2011-03-30 at 09:55 -0700, Kehl Dániel wrote:

Dear David,

I think that is a small bug too, maybe because the function is constant?
is there a nice way to put the c(0,2.1) argument optionally, only if all
the parameters are 1?
Should I post the problem somewhere else (developers maybe?)

I don't think this is a bug really; the code is having to compute limits
of the z axis and you supplied it one bit of information: a 2. If your
data are so degenerate then it is not unreasonable to expect some user
intervention. Admittedly, persp doesn't seem to work like other R
plotting functions.

You could do something like:

persp(x1, x2, z,
   zlim = if(length(na.omit(unique(as.vector(z  2){ c(0,2.1) }
else { NULL})

in your call to persp so it only uses user-defined limits if the number
of numeric values in z is less than 2.

HTH

G


thanks:
Daniel

2011-03-30 04:42 keltezéssel, David Winsemius írta:

On Mar 29, 2011, at 4:45 PM, Kehl Dániel wrote:


Dear list members,

I want to draw surfaces of Dirichlet distributions with different
parameter settings.
My code is the following:
#begin code
a1- a2- a3- 2
#a2- .5
#a3- .5
x1- x2- seq(0.01, .99, by=.01)

f- function(x1, x2){
  term1- gamma(a1+a2+a3)/(gamma(a1)*gamma(a2)*gamma(a3))
  term2- x1^(a1-1)*x2^(a2-1)*(1-x1-x2)^(a3-1)
  term3- (x1 + x2  1)
  term1*term2*term3
  }

z- outer(x1, x2, f)
z[z=0]- NA

persp(x1, x2, z,
  main = Dirichlet Distribution,
  col = lightblue,
  theta = 50,
  phi = 20,
  r = 50,
  d = 0.1,
  expand = 0.5,
  ltheta = 90,
  lphi = 180,
  shade = 0.75,
  ticktype = detailed,
  nticks = 5)
#end code

It works fine (I guess), except for a1=a2=a3=1. In that case I get
the error: Error in persp.default...  invalid 'z' limits.
The z matrix has only elements 2 and NA.

Might be a buglet in persp. If you set the zlim argument to c(0,2.1),
you get the expected constant plane at z=2 for those arguments.

Any ideas are appreciated.

Thank you:
Daniel
University of Pécs

__
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.


__
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] Dirichlet surface

2011-03-30 Thread Kehl Dániel
Actually, it works for the a=1 case, not for the others. It still gives 
the invalid 'zlim argument' error.
I'll try to work it out maybe instead of NULL giving a c which is 
dependent on the max(z).


Daniel

2011-03-30 10:42 keltezéssel, Kehl Dániel írta:

It helped a lot indeed, thank you very much!
Now I understand why it was a problem for persp!

Daniel

2011-03-30 10:31 keltezéssel, Gavin Simpson írta:

On Wed, 2011-03-30 at 09:55 -0700, Kehl Dániel wrote:

Dear David,

I think that is a small bug too, maybe because the function is 
constant?
is there a nice way to put the c(0,2.1) argument optionally, only if 
all

the parameters are 1?
Should I post the problem somewhere else (developers maybe?)

I don't think this is a bug really; the code is having to compute limits
of the z axis and you supplied it one bit of information: a 2. If your
data are so degenerate then it is not unreasonable to expect some user
intervention. Admittedly, persp doesn't seem to work like other R
plotting functions.

You could do something like:

persp(x1, x2, z,
   zlim = if(length(na.omit(unique(as.vector(z  2){ c(0,2.1) }
else { NULL})

in your call to persp so it only uses user-defined limits if the number
of numeric values in z is less than 2.

HTH

G


thanks:
Daniel

2011-03-30 04:42 keltezéssel, David Winsemius írta:

On Mar 29, 2011, at 4:45 PM, Kehl Dániel wrote:


Dear list members,

I want to draw surfaces of Dirichlet distributions with different
parameter settings.
My code is the following:
#begin code
a1- a2- a3- 2
#a2- .5
#a3- .5
x1- x2- seq(0.01, .99, by=.01)

f- function(x1, x2){
  term1- gamma(a1+a2+a3)/(gamma(a1)*gamma(a2)*gamma(a3))
  term2- x1^(a1-1)*x2^(a2-1)*(1-x1-x2)^(a3-1)
  term3- (x1 + x2  1)
  term1*term2*term3
  }

z- outer(x1, x2, f)
z[z=0]- NA

persp(x1, x2, z,
  main = Dirichlet Distribution,
  col = lightblue,
  theta = 50,
  phi = 20,
  r = 50,
  d = 0.1,
  expand = 0.5,
  ltheta = 90,
  lphi = 180,
  shade = 0.75,
  ticktype = detailed,
  nticks = 5)
#end code

It works fine (I guess), except for a1=a2=a3=1. In that case I get
the error: Error in persp.default...  invalid 'z' limits.
The z matrix has only elements 2 and NA.

Might be a buglet in persp. If you set the zlim argument to c(0,2.1),
you get the expected constant plane at z=2 for those arguments.

Any ideas are appreciated.

Thank you:
Daniel
University of Pécs

__
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.


__
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.


[R] Dirichlet surface

2011-03-29 Thread Kehl Dániel

Dear list members,

I want to draw surfaces of Dirichlet distributions with different 
parameter settings.

My code is the following:
#begin code
a1 - a2 - a3 - 2
#a2 - .5
#a3 - .5
x1 - x2 - seq(0.01, .99, by=.01)

f - function(x1, x2){
  term1 - gamma(a1+a2+a3)/(gamma(a1)*gamma(a2)*gamma(a3))
  term2 - x1^(a1-1)*x2^(a2-1)*(1-x1-x2)^(a3-1)
  term3 - (x1 + x2  1)
  term1*term2*term3
  }

z - outer(x1, x2, f)
z[z=0] - NA

persp(x1, x2, z,
  main = Dirichlet Distribution,
  col = lightblue,
  theta = 50,
  phi = 20,
  r = 50,
  d = 0.1,
  expand = 0.5,
  ltheta = 90,
  lphi = 180,
  shade = 0.75,
  ticktype = detailed,
  nticks = 5)
#end code

It works fine (I guess), except for a1=a2=a3=1. In that case I get the 
error: Error in persp.default...  invalid 'z' limits.

The z matrix has only elements 2 and NA.

Any ideas are appreciated.

Thank you:
Daniel
University of Pécs

__
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.