RE: [R] how to overlap plots

2004-01-15 Thread RBaskin
 Can you help me to overlap a histogram and theoretical density curve of
poison distribution?
There is more than one Poisson distribution you could possibly overlap but a
common choice is the Poisson with parameter = observed mean of the data - in
your case, 0.7.

I think the below is somewhat clumsy but it gives one idea how to do it (and
r-experts will cheerfully show a better way :)

 par(bg = cornsilk)
 
 #number of snails, 
 r - c(0, 1, 2, 3, 4, 5, 8, 15)
 #frequency of r
 f - c(69, 18, 7, 2, 1, 1, 1, 1)
 
 #a clumsy way to bin the observed values
 breakz - (0:16) - 0.5
 
 x - rep(r,f)
 
 xbar - mean(x)
 xbar
[1] 0.7
 
 hist(x, breaks = breakz,
+ freq = FALSE,
+ font.main = 6, 
+ col = lightgray)
 
 #change lambda to change the Poisson dist
 points(x, dpois(x, lambda = xbar),
+ type = l, col = 2)


bob


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 15, 2004 11:20 AM
To: [EMAIL PROTECTED]
Subject: [R] how to overlap plots

Dear R experts:
Can you help me to overlap a histogram and theoretical density curve of
poison 
distribution? for example data like this:
The numbers of sanils found in each of 100 sampling quadrats in an area were

as follows:
number of snails, r 0 1  2 3 4 5 8 15
f=frequency of r   69 18 7 2 1 1 1 1
apparently this is not Poison but near to Poison, How to overlap the 
theoretical desity curve to the histgram of this data?
Thanks in advance!
Josh

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Poisson distribution help requested

2004-01-09 Thread RBaskin
The ppois(q, lambda, ...other options...) in R has similar syntax to the SAS
function POISSON(m,n) (see POISSON in the SASv8 online doc).

1) q = n
2) lambda = m (= mu).

It's not obvious to me how you deal with an alpha in SAS other than by
observation, i.e., for a given mu and alpha does the cumulative prob of an
observation exceed alpha or not.  In R you can get the n corresponding to a
given alpha by using qpois.

from the R console:
 #the mean is assumed to be 1.2
 lambda-1.2
 #the Poisson cdf for q = 0 to 10
 ppois(0:10,lambda)
 [1] 0.3011942 0.6626273 0.8794871 0.9662310 0.9922542 0.9984998 0.9997489
0.630 0.951 0.994 0.999
 #if the observed y is 1 and the mean is 1.2 the cumulative probability is
 ppois(1,1.2)
[1] 0.6626273


Similar SAS output:
73   data _NULL_;
74   *the mean is assumed to be 1.2;
75lambda = 1.2;
76do y = 0 to 10;
77 upper = 1-poisson(lambda,y);
78 lower = poisson(lambda,y);
79 put lower.tail= lower upper.tail= upper y=y;
80end;
81   run;

lower.tail=0.3011942119 upper.tail=0.6988057881 y=0
lower.tail=0.6626272662 upper.tail=0.3373727338 y=1
lower.tail=0.8794870988 upper.tail=0.1205129012 y=2
lower.tail=0.9662310318 upper.tail=0.0337689682 y=3
lower.tail=0.9922542117 upper.tail=0.0077457883 y=4
lower.tail=0.9984997749 upper.tail=0.0015002251 y=5
lower.tail=0.9997488875 upper.tail=0.0002511125 y=6
lower.tail=0.630211 upper.tail=0.369789 y=7
lower.tail=0.951412 upper.tail=4.8588287E-6 y=8
lower.tail=0.994238 upper.tail=5.7615681E-7 y=9
lower.tail=0.999378 upper.tail=6.2236183E-8 y=10
NOTE: DATA statement used:
  real time   0.01 seconds
  cpu time0.01 seconds

Note that the upper tail is prob  y and not prob of = y.

good luck
bob





-Original Message-
From: Mark St.John [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 09, 2004 10:12 AM
To: [EMAIL PROTECTED]
Subject: [R] Poisson distribution help requested

Could somebody help me to understand the syntax of R's ppois function? I'm
looking to calculate the cumulative probability density of an observed value
(y) given the expected mean (mu) and the level of significance (alpha). I'm
coming from using SAS to do this and don't recognize the descriptions of the
arguments for ppois. The definitions of lambda and p as stated in the R
manuals are foreign to me!

Thanks, Mark

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


RE: [R] Excluding from an Array the Elements of Another Array

2003-12-11 Thread RBaskin
 I want to exclude from A the elements contained in B.
A[!(A%in%B)]  may do what you want.

?%in% or ?match

!= will do a pairwise comparison.

Bob


-Original Message-
From: Yao, Minghua [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 11, 2003 3:17 PM
To: R Help (E-mail)
Subject: [R] Excluding from an Array the Elements of Another Array 

Hi,

My question goes like this. I have two arrays A and B. I want to exclude
from A the elements contained in B.
Is there an easy way like A[A != x] to exclude a single one. Thanks for any
help.

Regards,

-MY

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] regression with limited range response

2003-12-04 Thread RBaskin
... the dependent variable is countiuous but bounded, say between 0 and
100.

Do you know why the dependent variable is 'bounded'?

... hints to relavant litterature 
If the dependent var is a percent John Cornell's book on mixture data might
be of interest.

Is it truncated in the sense that negative values are impossible?  This
situation is often dealt with in econometrics literature.  This is somewhat
out of date but a classic:
G. S. Madalla, Limited Dependent and Qualitative Variables in Econometrics,
Cambridge University Press, Cambridge, 1983.

Is it censored?  Maybe search for Tobit analysis depending on what
assumptions you are willing to make (also see something like Madalla for
this).  There is a large literature on censoring.

Maybe you just happened to not see anything outside [0,100]?  Maybe the
boundedness is ignorable:)

Bob




-Original Message-
From: Kim Mouridsen [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 04, 2003 10:39 AM
To: [EMAIL PROTECTED]
Subject: [R] regression with limited range response

Dear R experts

 

How can you perform a regression analysis in R when the dependent
variable is countiuous but bounded, say between 0 and 100?

I would be grateful for pointers to R-functions but also for hints to
relavant litterature since I have never worked with this problem before.

 

Thanks in advance.

Kim Mouridsen. 


[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Weird problem with median on a factor

2003-11-03 Thread RBaskin
Continuing to beat the greasy spot in the road where the dead horse used to
be

1) I know that the people building r are working on bigger and better things
than this silly question and I appreciate the existence of this complicated
package that was dropped in my lap for free.

2) Tony Platt succinctly pointed out one of the underlying 'problems'
(possibly in my understanding):


 #this is a perfectly reasonable r object
 some.weird.object-factor(c(a,b,c))
 #this is an internal r function acting on an object
 typeof(some.weird.object)
[1] integer
 #this is a primitive r function acting on an object
 is.numeric(some.weird.object)
[1] FALSE


Do these functions behave in a design consistent manor??  Can a single r
object simultaneously be of type integer and NOT numeric??  If this is
intentional can someone explain why?

I don't think this has anything to do with taking the median of a factor
(median calls mode that calls typeof).  It just requires a sufficiently
complex object, such as factor, before we start seeing this behavior.  I
wasn't clever enough to come up with examples of non-factor objects that
produced this behavior so I am curious if this problem is internal to factor
or to the functions themselves.

Thanks
Bob


-Original Message-
From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
Sent: Sunday, November 02, 2003 9:40 AM
To: Peter Dalgaard
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Weird problem with median on a factor

On 02 Nov 2003 12:50:37 +0100, you wrote:

(Arguably, sorting an unordered factor ought to Verboten as well,
though!)

No, arbitrarily assigning an ordering and using that to sort is a
useful thing in many situations, e.g. searching.  

Duncan Murdoch

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] dnorm() lead to a probability 1

2003-10-31 Thread RBaskin
Dnorm isn't the probability - it's the y-value on the density function.  Try
plotting it - it makes a nice normal plot.
See ?dnorm for definition.

Bob


-Original Message-
From: Marc Belisle [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 31, 2003 2:40 PM
To: R-Help
Subject: [R] dnorm() lead to a probability 1

Howdee,

One of my student spotted something I can't explain: a probability 1 vs a
normal probability density function.

 dnorm(x=1, mean=1, sd=0.4)
[1] 0.9973557

 dnorm(x=1, mean=1, sd=0.39)
[1] 1.022929

 dnorm(x=1, mean=1, sd=0.3)
[1] 1.329808

 dnorm(x=1, mean=1, sd=0.1)
[1] 3.989423

 dnorm(x=1, mean=1, sd=0.01)
[1] 39.89423

 dnorm(x=1, mean=1, sd=0.001)
[1] 398.9423

Is there a bug with the algorithm?

Thanks,

Marc


Marc Bélisle
Professeur adjoint
Département de biologie
Université de Sherbrooke
2500 boul. de l'Université
Sherbrooke, Québec
J1K 2R1 CANADA

Tél: +1-819-821-8000 poste 1313
Fax: +1-819-821-8049
Courriél: [EMAIL PROTECTED]
Site Web:
www.usherbrooke.ca/biologie/recherche/ecologie/Belisle/belisle.html

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Weird problem with median on a factor

2003-10-31 Thread RBaskin
Beating a dead horse...

I am an R beginner trying to understand this factor business.  While the
entire business of finding the median of factor may be silly from a
practical point of view, this email chain has helped me understand
something.  

I have looked at the median function and it tests to see if what is passed
to it is numeric.  If I were building a function, if I tested for mode
numeric, and if something told me it was numeric then like the median
function I would naively assume that I could do arithmetic on it:
 saywhut-as.factor(c(NA,1,1,1,1,2,10))
 mode(saywhut)
[1] numeric

It appears to me that the when the median function tests for numeric it
doesn't have the desired result with an object of class factor (and maybe
other classes?) as was shown by the example.

I have a suspicion that something of class factor has at least two pieces,
one of which is the levels which can possibly be character or something else
and the other piece is the ordering of the levels which is of storage.mode
integer.  Is it this ordering that determines the mode of the factor??  

But if the mode of factor is truly numeric, why doesn't the median function
use the numeric piece for finding the median (like it did with odd n - not
that anyone would ever really want the median of a factor:)??  I think that
Simon Fear hit on the right idea because of the definition of median that is
used for an even number of observations takes the sum of the ordered middle
two observations.  It is the sum (called by the median function) that chokes
on a factor.

 sum(saywhut,na.rm=T)
Error in Summary.factor(..., na.rm = na.rm) : 
sum not meaningful for factors

It appears that whoever built the sum function built in a test for factor
(Simon Fear's first suggestion for median)


On the other hand:
 sd(saywhut,na.rm=T)
[1] 3.614784
(Simon Fear's second suggestion for median)

Bytheway, mean treats factor in different way:
mean(saywhut)
[1] NA
Warning message: 
argument is not numeric or logical: returning NA in: mean.default(saywhut).


There is an R-FAQ that tells one how to convert a factor to 'numeric' but if
I had tested for something being numeric to begin with I never would have
guessed that I needed to convert it to numeric.  I think what this
conversion is really doing is getting rid of the machinery associated with
the class factor:
 #from the R-FAQ
 test-as.numeric(as.character(saywhut))
 mode(test)
[1] numeric
 median(test,na.rm=T)
[1] 1

and bytheway:
 not.a.factor-c(NA,1,1,2,10)
 mode(not.a.factor)
[1] character
 median(not.a.factor,na.rm=T)
Error in median(not.a.factor, na.rm = T) : 
need numeric data


Simon Fear: It seems to me the best way to deal with this bug would
be to make calling median with a factor argument be an immediate error.
Do you think that all base functions (sum, sd, mean, median,...) should deal
with this in a consistent way (This might be much more work.)?  Another
thing that would make things consistent would be to take the stop-work
behavior out of sum:)  

I don't think there is any real problem in the current behavior of factor as
long as the interaction between functions and classes produces this
stop-work behavior - preferably with a warning - and not unexpected side
effects. I am curious if there are other classes of mode numeric which
median-mean-sum-sd-etc might choke on.

tongue-in-cheek on
Of course, R would produce a median for factors by using the correct
defintion of a median of samples i.e., one that agrees with the definition
of median on a CDF, even though this concept gives most people apoplexy.
off
Thanks
Bob
Usual disclaimers


-Original Message-
From: Simon Fear [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 31, 2003 6:18 AM
To: Christoph Bier
Cc: [EMAIL PROTECTED]
Subject: RE: [R] Weird problem with median on a factor

Final guess as to observed behaviour: in the first case after
removal of NAs there were an odd number of observations
(so that sum was not called within the code for median).
In your second call I suspect that even though you got
an integer answer, it was found as sum(2,2)/2.

It seems to me the best way to deal with this bug would
be to make calling median with a factor argument be an 
immediate error. Or just trust users never to attempt such
a thing ...  
 
Simon Fear 
Senior Statistician 
Syne qua non Ltd 
Tel: +44 (0) 1379 69 
Fax: +44 (0) 1379 65 
email: [EMAIL PROTECTED] 
web: http://www.synequanon.com 
  
Number of attachments included with this message: 0 
  
This message (and any associated files) is confidential and\...{{dropped}}

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Variance of a non-linear combination of the coefficient e stiamtes

2003-10-30 Thread RBaskin
 In Stata, I can just use bs function ...
in STATA the bs command runs a bootstrap

If you want to use the bootstrap function (or you could linearize b*c/a :)
look under ?boot (you may need to load the package first).

Usage:

 boot(data, statistic, R, sim=ordinary, stype=i, 
  strata=rep(1,n), L=NULL, m=0, weights=NULL, 
  ran.gen=function(d, p) d, mle=NULL, ...)


I tried to provide an example - others can clean up the R code for me:

 test.df-cbind(rnorm(25),rnorm(25),rnorm(25))
 test.model-lm(test.df[,1]~test.df[,2]+test.df[,3])
 summary(test.model)

Call:
lm(formula = test.df[, 1] ~ test.df[, 2] + test.df[, 3])

Residuals:
Min  1Q  Median  3Q Max 
-1.3784 -0.6903 -0.2278  0.5879  2.7298 

Coefficients:
 Estimate Std. Error t value Pr(|t|)
(Intercept)  -0.034190.20907  -0.1640.872
test.df[, 2] -0.296360.17705  -1.6740.108
test.df[, 3]  0.160590.21060   0.7630.454

Residual standard error: 1.018 on 22 degrees of freedom
Multiple R-Squared: 0.1439, Adjusted R-squared: 0.06613 
F-statistic:  1.85 on 2 and 22 DF,  p-value: 0.1809 


test.model$coefficients[2]*test.model$coefficients[3]/test.model$coefficient
s[1]
test.df[, 2] 
1.391884 
 umeno.stat-function(xx,...){
+ xx.model-lm(xx[...,1]~xx[...,2]+xx[...,3])
+ xx.model$coefficient[2]*xx.model$coefficient[3]/xx.model$coefficient[1]}
 umeno.stat(test.df,c(1:25))
xx[..., 2] 
  1.391884 
 boot(test.df,umeno.stat,100)

ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = test.df, statistic = umeno.stat, R = 100)


Bootstrap Statistics :
originalbiasstd. error
t1* 1.391884 0.270811916.32276


bob


-Original Message-
From: umeno [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 1:19 PM
To: R-Help r-help
Subject: [R] Variance of a non-linear combination of the coefficient
estiamtes

Hi,

I would like to know if anyone knows how to compute a variance of the 
non-linear combination of the coefficient estimates.

Say, I get a model of

y~c+ax+bz (1)
where x and z are the independent variables, c is the constant estimate, and
a 
and b are the coefficient estimates.

Then, I want to know the variance of

b*c/a (2).

How am I going to get it?

In Stata, I can just use bs function by defining the regression model (1) 
and the statistic of the interest(2).

Help!!!

Thank you
Soyoko

__
Ms. Soyoko Umeno
Graduate Research Assitant for the Illinois-Missouri Biotechnology Alliance
(IMBA) at http://www.imba.missouri.edu/
Ph.D. Student at the Department of Agricultural and Consumer Economics
at the University of Illinois at Urbana-Champaign
Office Phone: 217-333-3417 or 217-333-0364
Fax: 217-244-4817
Mailing Address: 1301 W. Gregory Dr. MC710, Urbana, IL 61801

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] how to set missing values in R

2003-10-27 Thread RBaskin
One way:

x-c(1,3,-1,0,4)
 x[x0]-NA
 x
[1] NA NA -1  0 NA


bob


-Original Message-
From: Yulei He [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 27, 2003 4:05 PM
To: [EMAIL PROTECTED]
Subject: [R] how to set missing values in R

Hi, there.

Can I ask how to set up missing values in R? Suppose I want to assign the
missing value to the elements in vector which is greater than zero like
this:

x-c(1,3,-1,0,4);

after the missing value assignment, x becomes (NA,NA,-1,0,NA).

Thanks!

Yulei


$$$
Yulei He
1586 Murfin Ave. Apt 37
Ann Arbor, MI 48105-3135
[EMAIL PROTECTED]
734-647-0305(H)
734-763-0421(O)
734-763-0427(O)
734-764-8263(fax)
$$

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] hypergeometric population estimates

2003-10-01 Thread RBaskin

I'm not sure I understand your notation:
(1) We recently conducted an aerial survey and saw 70 uncollared caribou and
8 of 11 collared caribou.
(2) k - 70#  number caribou seen (# balls drawn)

It's the number of balls drawn parenthetical remark that bothers me - I
think the total number of balls drawn should be 78 and the number of
non-white balls drawn is 70.

If
x - 8 # number resighted caribou (white balls drawn)
m -11 # number collared caribou (white balls total)
totaldrawn - 78#  number caribou seen (total # balls drawn)

I believe that the maximum likelihood estimator you are looking for is given
by

MLE - floor(m * totaldrawn / x)  #floor(11 * 78 / 8) = 107

I believe the trick is to look at f(n) = P(x|m,totaldrawn,n) as a function
of n and consider the ratio f(n) / f(n-1).  If this ratio is greater than 1
the function is increasing and if the ratio is less than 1 the function is
decreasing.  Then algebraically show that the maximum occurs at floor(m *
totaldrawn / x).

Bytheway, this MLE includes both collared and uncollared balls so it may be
that you are looking for 107 - 11 as your estimate??

hth
Bob
Usual disclaimers...

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 01, 2003 12:56 PM
To: [EMAIL PROTECTED]
Subject: [R] hypergeometric  population estimates

help

We want to estimate the number of caribou in Jasper.  We recently conducted
an aerial survey and saw 70 uncollared caribou and 8 of 11 collared
caribou.  We want to estimate the number of caribou in this population with
95% confidence limits.  Gary White uses the hypergeometric distribution and
determines the population estimates using maximum likelihood and 95%CL as
-2LogLikelihoods.  Below, I determined the population estimate using
dhyper(x,m,n,k) and maximizing the density value as a function of n, but do
not know how I should calculate MLE with this distribution.


x - 8 # number resighted caribou (white balls drawn)
m -11 # number collared caribou (white balls total)
k - 70#  number caribou seen (# balls drawn)
n - 1:500 #  ?? unknown number of uncollared caribou (# black balls)
d - unlist(lapply(n, function(i) dhyper(x,m,i,k))) # density estimate
for each value of n
data - data.frame(estimate = n+m, d)
data - data[is.finite(data$d), ] # filter out NA's

max.d - max(data$d)
pop.estimate - data[data$d == max.d, 1]

Thank-you for your assistance,
Jesse

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] what does the sum of square of Gaussian RVs with differen t variance obey?

2003-09-23 Thread RBaskin

This is a relatively recent article that is somewhat accessible.
Jensen, D. R., and Solomon, Herbert (1994), Approximations to joint
distributions of definite quadratic forms, Journal of the American
Statistical Association, 89 , 480-486
It has references to previous work.

I also have an old paper that is so old I can't tell what journal it came
out of:(
Grad, Arthur and Solomon, Herbert Distribution of Quadratic Forms and Some
Applications probably published in 55 or 56 but I can't tell.  The paper by
Grad and Solomon uses the moment generating function to give the exact
distribution and various approximations to produce a table for a sum of 2 or
3 variates.


Usual disclaimers ...
Bob


-Original Message-
From: Thomas Lumley [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 23, 2003 10:07 AM
To: Jean Sun
Cc: [EMAIL PROTECTED]
Subject: Re: [R] what does the sum of square of Gaussian RVs with different
variance obey?

On Tue, 23 Sep 2003, Jean Sun wrote:

 From basic statistics principle,we know,given several i.i.d Gaussian
 RVs with zero or nonzero mean,the sum of square of them is a central or
 noncentral Chi-distributed RV.However if these Gaussian RVs have
 different variances,what does the sum of square of them obey?


Nothing very useful.  It's a mixture of chisquare(1) variables. One
standard approach is to approximate it by a multiple of a chisquared
distribution that has the correct mean and variance.

-thomas

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Plotting math functions

2003-07-24 Thread RBaskin


 I was wondering whether it is possible to plot math functions, for example
sin ...

also maybe:
?plot

snipped from the help page
Examples:
...
 plot(sin, -pi, 2*pi)
unsnip

bob



-Original Message-
From: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 24, 2003 11:04 AM
To: Jonck van der Kogel
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Plotting math functions

Jonck van der Kogel wrote:
 Hi all,
 I was wondering whether it is possible to plot math functions, for 
 example sin, cos or a Gaussian type function, in R, and if so, how to do 
 it. I have been searching through the archives and the R manual but had 
 no luck in finding any hints on how to go about this.
 Any help is much appreciated!
 Thanks, Jonck
 
 __
 [EMAIL PROTECTED] mailing list
 https://www.stat.math.ethz.ch/mailman/listinfo/r-help

See ?curve

Uwe Ligges

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] create a vector looping over a frame

2003-07-18 Thread RBaskin
 #just to have some data
 testdata-matrix(rnorm(14*7),ncol=14)
 testframe-as.data.frame.matrix(testdata)
 names(testframe)-c(Year,Series,Age,WM,
WF,HM,HF,BM,BF,IM,IF,AM,AF,Yr)
 #one way is colSums
 colSums(testframe)[c(3,5,8,10)]
 Age   WF   BM   IM 
 5.024714070  1.974526477  0.004256433 -2.940214886 
 #another way is a for loop
 testvector-rep(NA,14)
 for (i in 1:14) testvector[i]-sum(testframe[,i])
 testvector[c(3,5,8,10)]
[1]  5.024714070  1.974526477  0.004256433 -2.940214886
 #there are other ways:)



snip
 for(i in 4:13){
sumVar- sum(popA[,i])
sumVar2-c(sumVar) 
}
end snip
You are replacing sumVar in each iteration of the loop, not creating a new
element.

bob



-Original Message-
From: Siddique, Amer [mailto:[EMAIL PROTECTED] 
Sent: Friday, July 18, 2003 4:02 PM
To: '[EMAIL PROTECTED]'
Subject: [R] create a vector looping over a frame 

Hello,

I have a data.frame

 names(popA)
 [1] Year   Series AgeWM WF HM HF BM
 [9] BF IM IF AM AF Yr  

how do i loop over a subset of variables in this frame to create a vector of
length equal to the number of variables in the subset such that the vector's
ith element is the result of an aggregate fncn applied to the ith variable?

eg,
sumvar-c(sum(WM),...,sum(AF))

if i try

for(i in 4:13){
sumVar- sum(popA[,i])
sumVar2-c(sumVar) 
}

it returns 

 sumVar2
[1] 287567

 length(sumVar2)
[1] 1

which is only the value at the last spot. i cant quite figure this simple
loop. 

Thanks,

Amer Siddique

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternative HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Introductory Resources

2003-06-06 Thread RBaskin
I am interested in R as an alternative for a statistical tool 
at our firm.
Ditto...

I have recently moved to this agency from a company where I had access to
Splus.  There is also a coworker here who had used Splus at a previous
employer.  We both would like some access to the S language.  We are
considering either begging loud and long to try to get the agency to
purchase two copies of Splus or trying to convert to R.  This is not an easy
decision under the circumstances and purchasing Splus will mean giving up
something else.  On the other hand I have never used R before and I fear the
learning curve for using R plus possibly ESS.

There are a few things I am trying to determine before I really decide what
to do.  I have been trying to convert some of my old Splus script files at
home to run under R 1.7.0.  Small (less than 50 lines or so) script files
that I have tested run exactly as before.  I tried to run one large
simulation and it took about a week of screaming hell to get the error
messages out (well all but one error message anyway).


1) I want a test suite for R.  I noted in the messages (Date: Mon Feb 24
2003 - 22:18:03 EST) that Prof Ripley wrote Well, R itself has lots of
tests in its test suite (see directory tests in the sources) packages...
but I was too stupid to find them.  
Q1: Can someone provide directions to this test suite that even an idiot can
follow?


2) Most of the problems I ran into had to do with missing values (in effect
I have ragged arrays).  One silly example is that I had made use of which.na
'which' apparently is not defined in R 1.7.0.  There are multiple
workarounds such as simply defining a function which.na but of course it
would be untested and you can loop back to 1).  The problem in my script
files is the same I had in Splus.  I want the defaults on all of the
functions (such as mean, median, etc.) I am using to be reset GLOBALLY so
that the default is to ignore missing values or not. 
Q2: Can the missing defaults be set globally for all functions.  In other
words, I want the default for how to treat NAs in all functions to be set at
startup.


3)  What I really want to do is pass a function name and extra arguments to
another function.  For example, in Splus, you can pass a function such as
median to the bootstrap function.  The bootstrap function says that you can
pass arguments to the median function through the bootstrap function but
unfortunately I could never make this work.  This functionality would
probably solve most of my NA problems if I could make it work.  (I don't
seem to be able to properly use the ellipses:)
Pseudo-Example: The Splus bootstrap can be called as
Bootstrap(variable-name, median, sampler=sample-function, na.rm=T)
But I never figured out how to pass the na.rm=T as an argument to median so
that the function being bootstrapped is median(variable-name, na.rm=T).
Q3: Is there some way in R to pass alternative arguments through a function
to another?

4)Any general thoughts on Splus versus R that you are willing to share?


This is way too much blithering for one day but thanks in advance for any
thoughts.

Bob Baskin
All the usual disclaimers that my statements don't represent the agency etc.
etc.




-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 05, 2003 1:19 PM
To: 'Fohr, Marc [AM]'; '[EMAIL PROTECTED]'
Subject: RE: [R] Introductory Resources

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Fohr, Marc
[AM]
Sent: Thursday, June 05, 2003 11:46 AM
To: '[EMAIL PROTECTED]'
Subject: [R] (no subject)


Hello,

I am interested in R as an alternative for a statistical tool 
at our firm. I
do know RATS an SPSS but not S+. As I read that R is close to 
S+, I would
like to know if you could recommend me any books as an 
introduction to S+ or
R.

Best regards

Marc


Marc,

Reviewing R FAQs 2.7 and 3.x on the main R site would be a good place
to start. The former lists books and other documents (some online)
that serve as excellent introductions, while the latter helps to
differentiate R and S/S+.

Spending some time with those references and the R FAQs will serve as
a good foundation, with keyword searches of the R-help list archive
serving as an additional strong resource.

HTH,

Another Marc

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

[[alternate HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


RE: [R] Introductory Resources

2003-06-06 Thread RBaskin
Thank you for your detailed response.


 R is more responsive to bug reports.
and blithering from frustrated code converters :)


 boot(vname, median, na.rm=T)
should work, ...
agreed

 but myfunc - function(x, str) median(x, na.rm=str)
 boot(vname, myfunc, str=T)
would not.
agreed


What I actually wanted to do was more like:

Myfunc - function(vname, statistic, reps, ...)
{ some code
  boot(vname, statistic, ...)
}
myfunc(vname, median, 1000, na.rm=T)

I never seemed to be able to convince Splus that I wanted the ellipses in
myfunc to pass to the ellipses in boot (actually bootstrap).  


Thank you very much for your response - I have a lot of work to do now.
Bob


-Original Message-
From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
Sent: Friday, June 06, 2003 1:51 PM
To: Baskin, Robert
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Introductory Resources

On Fri, 6 Jun 2003 12:04:47 -0400 , you wrote in message
[EMAIL PROTECTED]:

1) I want a test suite for R.  I noted in the messages (Date: Mon Feb 24
2003 - 22:18:03 EST) that Prof Ripley wrote Well, R itself has lots of
tests in its test suite (see directory tests in the sources) packages...
but I was too stupid to find them.  
Q1: Can someone provide directions to this test suite that even an idiot
can
follow?

You need to download the source code to R from CRAN (e.g.
cran.mirrors.pair.com), it's not in the precompiled binaries.  You'll
find the tests in the tests subdirectory.  They consist of pairs of
foo.R and foo.Rout.save files.  When you run the tests via make
check, foo.Rout will be produced, and you'll be warned about
differences from foo.Rout.save.

Testing also runs almost all of the examples in every help file, and
aborts if any generate errors (or warnings, I forget just now...).
Package writers can include their own test scripts and saved output
files.

Q2: Can the missing defaults be set globally for all functions.  In other
words, I want the default for how to treat NAs in all functions to be set
at
startup.

option(na.action=some function) will control how all well-behaved
functions handle NAs, but not all functions are well-behaved.
Complain about those that should be but aren't (to the package
maintainer in case of a contributed package, here or to r-bugs in case
of a built-in package).

3)  What I really want to do is pass a function name and extra arguments to
another function.  For example, in Splus, you can pass a function such as
median to the bootstrap function.  The bootstrap function says that you can
pass arguments to the median function through the bootstrap function but
unfortunately I could never make this work.  This functionality would
probably solve most of my NA problems if I could make it work.  (I don't
seem to be able to properly use the ellipses:)
Pseudo-Example: The Splus bootstrap can be called as
Bootstrap(variable-name, median, sampler=sample-function, na.rm=T)
But I never figured out how to pass the na.rm=T as an argument to median so
that the function being bootstrapped is median(variable-name, na.rm=T).

Q3: Is there some way in R to pass alternative arguments through a function
to another?

Yes, I think this is similar in R and S-PLUS, so you might run into
the same problems.  Generally it's easy using ellipses, but if the
argument name for your function happens to be the prefix of an
argument name for the Bootstrap function, then you'll get a match
there, instead of where you want it.  

For example, in R bootstrapping can be done using the function boot()
in library(boot).  It has arguments:

 boot(data, statistic, R, sim=ordinary, stype=i, 
  strata=rep(1,n), L=NULL, m=0, weights=NULL, 
  ran.gen=function(d, p) d, mle=NULL, ...)

The ellipses will pass other arguments to the function passed as the
statistic argument, but if you named them str they'd match strata
instead of being passed to   Thus

 boot(vname, median, na.rm=T)

should work, but 

 myfunc - function(x, str) median(x, na.rm=str)

 boot(vname, myfunc, str=T)

would not.


4)Any general thoughts on Splus versus R that you are willing to share?

S-PLUS has a more polished GUI.  R is more responsive to bug reports.

Duncan Murdoch

[[alternate HTML version deleted]]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help