[R] variance?,...

Jan.Schelling@hydro.com Jan.Schelling at hydro.com
Wed Nov 24 09:51:52 CET 1999



xmatl at informatics.muni.cz on 99-11-22 07:04 PM GMT
> I know
> EX <- function(xval,xprob) sum( (xval*xprob) );
> where xval is vector of values and xprob vector of probabalities,
> but
> DX <- function(xval,xprob) EX((xval^2),xprob) - (EX(xval,xprob))^2;
> doesn't work as I thought.

Well, what did you expect?

xval <- 0:100
xprob <- dnorm(xval, 45, sqrt(64))
EX(xval, xprob)
[1] 45
DX(xval, xprob)
[1] 64

looks ok to me.

plot(0:100, dnorm(0:100,45,sqrt(64)))

produces (by definition ) just as many probablities as you have data points. In
my case 101. If you want something like a continuous density from a small number
of discrete data points you should consider density().

Example:

xval <- 0:10
xprob <- dnorm(xval, 4.5, 1.5)
plot(xval, xprob) # 11 points
lines(density(rep(xval, 100*xprob), bw=.6, n=512)) # continuous line based on n
= 512 points

Jan

----------
Jan Schelling
Norsk Hydro
Research Centre
N - 3925 Porsgrunn




From: xmatl at informatics.muni.cz on 99-11-22 07:04 PM GMT



To:   r-help at stat.math.ethz.ch
cc:    (bcc: Jan Schelling/HRE/Hydro)
Subject:  [R] variance?,...



hi

I'm learning R and making some examples.
One of them is that for given distribution
I show density function, distribution function
expected value and variance(?).
I know
EX <- function(xval,xprob) sum( (xval*xprob) );
where xval is vector of values and xprob vector of probabalities,
but
DX <- function(xval,xprob) EX((xval^2),xprob) - (EX(xval,xprob))^2;
doesn't work as I thought.
I've looked intto FAQs and archives but my question
is probably too simple.
Can somebody tell me what's wrong on my example ?
And one more question: when I'm plotting density:
plot(x, dnorm(x,as.double(mu),as.double(sigma_square)), style );
on interval x I get relatively small number of probabilities.
I've spent long time searching trough docs to find how
to change it but didn't found it. So please tell me how.

thanks for replies
+-----------------------------------------------------------------------------+
|  ROSTISLAV MATL, student of Masaryk University - Faculty of Informatics     |
|  e-mail: xmatl at fi.muni.cz      WWW: http://www.fi.muni.cz/~xmatl/index.html |
|  ICQ#: 17058749                                                             |
+-----------------------------------------------------------------------------+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._






-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list