Hi, Rusers: Thanks for answering my last questions. I am frustrated in plotting a trinomial pmf function f(x,y | n, pa, pb) = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y)) obviously it is a bivariate function of x and y. But I have put a lot of time on this. ********************************** x <- seq(0, n, len = n/2+1) # for now I set it to n/2 to control x+y <= n y <- seq(0, n, len = n/2+1) f = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y)) wireframe(f ~ x * y, shade = TRUE) ********************************** well, but it plots nothing out. I wonder if you could help me? Seems R is hard to learn without your help. Many thanks, Sun [[alternative HTML version deleted]]
Have you studied the documentation for "wireframe" including the examples? See also the contour plot examples in Venables and Ripley (2002) Modern Applied Statistics with S, 4th ed. (Springer). It might help if you write your function as follows: f <- function(x,y ,n, pa, pb) (factorial(n)/ (factorial(x) * factorial(y) * factorial(n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y))) I hope this fills in enough gaps that you will be able to complete the remaining steps. Good luck. spencer graves Sun wrote:>Hi, Rusers: > >Thanks for answering my last questions. I am frustrated in plotting a trinomial pmf function > >f(x,y | n, pa, pb) = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y)) > >obviously it is a bivariate function of x and y. But I have put a lot of time on this. > >********************************** >x <- seq(0, n, len = n/2+1) # for now I set it to n/2 to control x+y <= n >y <- seq(0, n, len = n/2+1) >f = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y)) >wireframe(f ~ x * y, shade = TRUE) >********************************** > >well, but it plots nothing out. > >I wonder if you could help me? Seems R is hard to learn without your help. > >Many thanks, > >Sun > [[alternative HTML version deleted]] > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >-- Spencer Graves, PhD, Senior Development Engineer O: (408)938-4420; mobile: (408)655-4567
Hi, All: Thanks. Here is the code n = 30 lamdaa = 4 lamdab = 1.5 pa = lamdaa/n pb = lamdab/n x <- seq(0, n/2, len = n/2+1) y <- seq(0, n/2, len = n/2+1) f = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y)) wireframe(f ~ x * y, shade = TRUE) The above cannot show anything. Just le t you know that now I changed to cloud, it can display something :) cloud(f ~ x * y, shade = TRUE) I have questions: 1. what does x*y mean here? I don't think it is a vector dot multiplication. I guess it will creat all rows of x and y for all possible combinations? Why wireframe cannot show here? 2. How to show the value on the cloud plot? I have no idea of how much the data value is from the plot. 3. Where can I get resources of R? The help file seems not very helpful to me. For example, the lm () function, its weighted least square option does not say clearly the weight = standard deviation. It said it is to minimize sum w*error^2, which mislead us to think it takes variance. I have to ask experienced people. And everytime the answer depends on luck. Thanks, ----- Original Message ----- From: "Andrew Ward" <Andrew.Ward at qsa.qld.edu.au> To: "Sun" <sun at cae.wisc.edu> Sent: Saturday, October 16, 2004 10:15 PM Subject: RE: [R] how to draw a multivariate function> Dear Sun, > > Could you please provide an example that can be run > by readers of the list? What you've given is > missing at least n and pa. > > Regards, > > Andrew C. Ward, andrew.ward at qsa.qld.edu.au > Senior Analyst (Quantitative), Tel: +61 7 3864 0439 > Queensland Studies Authority, Fax: +61 7 3229 3318 > 295 Ann Street, > Brisbane Qld 4000, Australia > > -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Sun > Sent: Sunday, 17 October 2004 12:59 PM > To: R-help mailing list > Subject: [R] how to draw a multivariate function > > > Hi, Rusers: > > Thanks for answering my last questions. I am frustrated in plotting atrinomial pmf function> > f(x,y | n, pa, pb) = factorial(n)/ (factorial(x) * factorial(y) *factorial (n-x-y))* pa^x * pb^y * ((1-pa-pb)^(n-x-y))> > obviously it is a bivariate function of x and y. But I have put a lot oftime on this.> > ********************************** > x <- seq(0, n, len = n/2+1) # for now I set it to n/2 to control x+y <= n > y <- seq(0, n, len = n/2+1) > f = factorial(n)/ (factorial(x) * factorial(y) * factorial (n-x-y))* pa^x* pb^y * ((1-pa-pb)^(n-x-y))> wireframe(f ~ x * y, shade = TRUE) > ********************************** > > well, but it plots nothing out. > > I wonder if you could help me? Seems R is hard to learn without your help. > > Many thanks, > > Sun > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > This email (including any attached files) is for the intended > recipient(s) only. If you received this email by mistake, please, > as a courtesy, tell the sender, then delete this email. > > The views and opinions are the originator's and do not necessarily > reflect those of the Queensland Studies Authority. All reasonable > precautions have been taken to ensure that this email contained no > viruses at the time it was sent. > > >
Sun <sun <at> cae.wisc.edu> writes:> 3. Where can I get resources of R? The help file seems not very helpful to > me. For example, the lm () function, its weighted least square option does > not say clearly the weight = standard deviation. It said it is to minimize > sum w*error^2, which mislead us to think it takes variance. I have to ask > experienced people. And everytime the answer depends on luck.1. There are quite a few pointers under Documentation in the left hand pane of the R web site at www.r-project.org . 2. If you have something specific like weighted regression you can try the Search link at that same site or just use google, e.g. try these search words and you will find some examples of using lm with weights: r-help weight lm 3. Sometimes its easiest to check your understanding by just plugging in some variables for which you know the answer and see what it does. For example, R> set.seed(1) R> y <- rnorm(10) R> w <- runif(10) R> # Run 1 R> coef(lm(w*y ~ w+0)) # +0 means no intercept w -0.1768129 R> # Run 2 R> coef(lm(y~1,weight=w^2)) # ~1 means regression against intercept (Intercept) -0.1768129 R> # Run 3 R> coef(lm(y~1,weight=w)) (Intercept) -0.1037307 The first two runs give the same answer so it seems the help page was correect because the first run finds the b that minimizes sum((w*y - b*w)^2) and we can factor the w out to give = sum(w^2 * (y-b)^2) which corresponds to Run 2, not Run 3.