Displaying 20 results from an estimated 2583 matches for "density".
2013 Mar 20
3
highlight overlapping region of two densities
Hi all.
I would like to highlight overlapping regions of two densities and I could
not find a way to do it.
Here is the sample code:
myd <- c(2,4,5, 4,3,2,2,3,3,3,2,3,3,4,2,4,3,3,3,2,2.5,
2, 3,3, 2.3, 3, 3, 2, 3)
myd1 <- myd-2
plot(range(density(myd)$x, density(myd1)$x), range(density(myd)$y,
density(myd1)$y), type = "n")
lines(density(myd), col=1, lwd=4)
lines(density(myd1), col=2, lwd=4, lty=2)
So, I am trying to highlight the region from 1 to 4, on x axis, taking the
minimum value of corresponding y values.
I am aware of pol...
2009 Mar 02
4
density > 1?
Dear R-Gurus,
I wonder why 'density' values as shown in hist or plot(density(x)) are
sometimes over 1. How can that be?
Example
>hist(rnorm(1000,sd=.5),freq=FALSE)
The resulting plot shows density values below 1 on the y-axis. However,
>hist(rnorm(1000,sd=.1),freq=FALSE)
shows density values over 1.
How to interpret d...
2008 Nov 25
3
plotting density for truncated distribution
I am using density() to plot a density curves. However, one of my variables
is truncated at zero, but has most of its density around zero. I would like
to know how to plot this with the density function.
The problem is that if I do this the regular way density(), values near zero
automatically get a very low value b...
2012 Mar 21
3
Unable to specify order of a factor
Hi all:
I'm attempting to create a faceted plot with ggplot2 and I'm having issues
with a factor's order that is used to define the facet_grid().
The factor (named total.density) has three levels - 8, 16, and 32 - and I
would like them presented in that order. Running
order(levels(total.density)) yields the incorrect order of the facet grid -
2 3 1, corresponding with 16, 32, and 8.
I have attempted correcting the order with the following solutions (of
course, not run at...
2003 Apr 08
3
density ranges for uniform law
Hello,
I would have some details and explanations about the results I get.
In fact, I start with a uniform sample between -1 and 1, and then plot its
density.
My problem is that the density ranges are much more longer than I expected :
samp <- runif(10000,-1,1)
plot(density(samp))
Instead of varying between -1 and 1, the density varies between approximaly
-1.5 and 1.5
Could someone explain me what is happening ? Maybe some arguments for
density est...
2002 Aug 30
5
density() returns a density function that does not add up to 1
Dear R users,
I ran into this curious problem:
> d <- rnorm(100)
> d.density <- density(d)
> sum( d.density$x * d.density$y)
[1] 2.517502
Admittedly the method of computing the mass under the density curve at
line 3 is crude.
But 2.5 is pretty far from 1, the value it should be.
I tried a few other dataset and got similar result. Am I missing
something obvious?
Or i...
2007 Aug 05
1
Selectively shading areas under two density curves
Dear Listers,
I am drawing a plot of two density curves, for male and female incomes. I would
like to shade/hatch/color (whatever) the areas under the curves which are
distinctive for each gender. This is the code I have tried so far:
m <- density(topmal.d$y, bw = "sj")
f <- density(topfem.d$y, bw = "sj")
par(mfrow =...
2006 Aug 30
2
density() with from, to or cut and comparrison of density()
Hi
the function density() does normally integrate to one - I've checked it
and it works and I also read the previous threads.
But I realised that it does not integrate to one if I use from, to or cut.
My scenario: I simulated densities of a plants originating from an sseed
source at distance zero. Therefore the densi...
2011 Sep 08
3
Density function: Area under density plot is not equal to 1. Why?
Hi, I have a vector 'data' of 58 probability values (bounded between 0 and 1) and want to draw a probability density function of these values. For this, I used the commands:
data <- runif(58)
a <- density(data, from=0, to=1)
plot(a, type="l",lwd=3)
But then, when I try to approximate the area under the plotted curve with the command:
area <- sum(a$y)*(a$x[1]-a$y[2])
I get an area that is c...
2013 Jan 22
3
density of hist(freq = FALSE) inversely affected by data magnitude
Hi,
I have a couple of observations, a question or two, and perhaps a
suggestion related to the plotting of density on the y-axis within the
hist() function when freq=FALSE. I was using the function and trying
to develop an intuitive understanding of what the density is telling
me. After reading through this fairly helpful post:
http://stats.stackexchange.com/questions/17258/odd-problem-with-a-histogram-in-r-...
2003 Sep 24
3
density() integrates to 1?
Visual inspection of the plot of a density() function vs a normal with
the same mean and variance suggests the area under the density curve is
bigger than under the normal curve. The two curves are very close over
most of the domain. Assuming the normal curve does integrate to 1, this
implies the area under density() is > 1.
Is there...
2008 Feb 05
2
two densities with same stepsize
Hi there,
I have two series of data. plotting the density function of both gives me an
idea about the difference of the data. But I would like to quantify the
difference I see.
a <- rnorm(100)
b <- rnorm(100)
da <- density(a)
db <- density(b)
The problem is that da$x and db$x are different and so I have difficulties to
compare them... Is...
2011 Oct 12
4
plot probability density function (pdf)
I have 2 series of variables, I want to plot the probability density function
of these 2 variabels (i.e. two curves in one graph), I just want to compare
these two variable distribution.
what should I do?
can I use ggplot2 package?
--
View this message in context: http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3897055.html
Sent from t...
2000 Nov 17
2
hist() and density
There were some questions about hist() a couple of days ago which
triggered this post. My question/suggestion is about the y-axis in hist.
There are reasons to prefer making the y-axis density=relative
frequency/bin width. One reason is that the height of the plot does not
depend on the bin width; another is that if your histogram is in density
then you can easily superimpose a smooth theoretical pdf on top--they will
be on the same scale. (BTW the best intro stats book--Freedman et al--...
2009 Apr 28
3
truehist and density plots
Hi,
I wanted to plot the histogram of a vector and then, plot the density function of subsets of the vector on the histogram. So I use truehist in MASS package and lines(density) as follows:
length(b) = 1000
truehist(b)
lines(density(b[1:100]))
however the density plot of the first 100 points exceeds the max of y axis (see attached). how is it possible to make a graphi...
2009 Nov 05
5
Density estimate with bounds
Dear R users,
I would like to show the estimated density of a (0, 1) uniformly distributed
random variable. The density curve, however, goes beyond 0 and 1 because of the
kernel smoothing.
Example:
x = runif(10000)
plot(density(x))
Is there a way to estimate the density curve strictly within (0, 1) and still
use some sort of smoothing?
Any help woul...
2010 Jun 14
1
script development for Unconditional Density and Probability estimation
...tail_0 <- Marsh[,'cattail'] == '0' # no need to run for 8
species, automate if possible
cattail_1 <- Marsh[,'cattail'] == '1' # yes need to run for 8
species
spbase.rate.d1 <- sum(cattail_1)/(sum(cattail_1) + sum(cattail_0) )
annualDepth.density <- density(AnnualDepth) # this line needs either
interactively defined or automatically cycle thru a number of metrics
cattail.d0.density <- density(AnnualDepth[cattail_0])
cattail.d1.density <- density(AnnualDepth[cattail_1])
approxfun (cattail.d0.density$x, cattail.d0.density$y) -&g...
2009 Sep 29
3
Probability of data values form DENSITY function
Hello,
Could someone help me please and to tell how to get the probability from empirical DENSITY (not parametric) for each data value (R function).
For example, for normal distribution there is such a function like:
“dnorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)”
I need the same function only for the empirical DENSITY function (which does not correspond to any typical d...
2010 Jul 20
2
Constrain density to 0 at 0?
I'm plotting some trip length frequencies using the following code:
plot( density(zTestData$Distance, weights=zTestData$Actual),
xlim=c(0,10),
main="Test TLFD",
xlab="Distance",
col=6 )
lines(density(zTestData$Distance, weights=zTestData$FlatWeight), col=2)
lines(density(zTestData$Distance, weights=zTestData$BrdWeight ), col=3)
which works fi...
2008 Dec 26
1
histogramm$density
hello,
i am using the hist function with classified values. The class breaks are >1, so
histogram$density is != 1.
How to plot the histogram with freq=FALSE and the real class density values.
I used:
> h2 = hist(value, breaks = breaks_vector)
> h2$density = round(h2$counts/sum(h2$counts), 2)
> h2$intensities = h2$density
> plot(h2, freq=F)
but this isn't the best way, i think.
Also...