kernel-density

Density Value for each Return

一笑奈何 提交于 2019-12-10 19:50:14
问题 I have a dataframe "foo" looking like this Date Return 1998-01-01 0.02 1998-01-02 0.04 1998-01-03 -0.02 1998-01-04 -0.01 1998-01-05 0.02 ... 1998-02-01 0.1 1998-02-02 -0.2 1998-02-03 -0.1 etc. I would like to add to this dataframe a new column showing me the density value of the corresponding return. I tried: foo$density <- for(i in 1:length(foo$Return)) density(foo$Return, from = foo$Return[i], to = foo$Return[i], n = 1)$y But it didn't work. I really have difficulty applying a "function" to

KDE fails with two points?

假如想象 提交于 2019-12-10 19:09:18
问题 The following trivial example returns a singular matrix. Why? Any ways to overcome it? In: from scipy.stats import gaussian_kde Out: In: points Out: (array([63, 84]), array([46, 42])) In: gaussian_kde(points) Out: (array([63, 84]), array([46, 42])) LinAlgError: singular matrix 回答1: Looking at the backtrace, you can see it fails when inverting the covariance matrix. This is due to exact multicollinearity of your data. From the page, you have multicollinearity in your data if two variables are

Extracting boundaries of dense regions of 1s in a huge list of 1s and 0s

浪尽此生 提交于 2019-12-10 15:43:34
问题 I'm not sure how to word my problem. But here it is... I have a huge list of 1s and 0s [Total length = 53820]. Example of how the list looks like - [0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,1,1...........] The visualization is given below. x-axis: index of the element (from 0 to 53820) y-axis: value at that index (i.e. 1 or 0) Input Plot--> The plot clearly shows 3 dense areas where the occurrence of 1s is more. I have drawn on top of the plot to show the visually dense areas. (ugly black

How can you create a KDE from histogram values only?

五迷三道 提交于 2019-12-10 04:33:53
问题 I have a set of values that I'd like to plot the gaussian kernel density estimation of, however there are two problems that I'm having: I only have the values of bars not the values themselves I am plotting onto a categorical axis Here's the plot I've generated so far: The order of the y axis is actually relevant since it is representative of the phylogeny of each bacterial species. I'd like to add a gaussian kde overlay for each color, but so far I haven't been able to leverage seaborn or

How to plot a density estimate on top of the histogram? [duplicate]

旧街凉风 提交于 2019-12-09 19:00:47
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Fitting a density curve to a histogram in R x is a NAs free numeric vector. I run: > hist(x,density(x), prob=TRUE) Error Message I get: Error in rank(x, ties.method = "min", na.last = "keep") : unimplemented type 'list' in 'greater' It was suggested that I set prob =TRUE when calling hist. If you can explain that as well, it will be great. Thank you. 回答1: You need to call hist and density separately. Something

confusion on 2 dimension kernel density estimation in R

有些话、适合烂在心里 提交于 2019-12-06 12:37:11
问题 A kernel density estimator is used to estimate a particular probability density function (see mvstat.net and sckit-learn docs for references) My confusion is about what exactly does kde2d() do? Does it estimate the joint distribution probability density function of two random variables f(a,b) in the below example? And what does the color mean? Here is the code example I am referring to. b <- log10(rgamma(1000, 6, 3)) a <- log10((rweibull(1000, 8, 2))) density <- kde2d(a, b, n=100) colour_flow

Thread error: can't start new thread

。_饼干妹妹 提交于 2019-12-06 06:34:51
问题 Here's a MWE of a much larger code I'm using. It performs a Monte Carlo integration over a KDE (kernel density estimate) for all values located below a certain threshold (the integration method was suggested over at this question: Integrate 2D kernel density estimate) iteratively for a number of points in a list and returns a list made of these results. import numpy as np from scipy import stats from multiprocessing import Pool import threading # Define KDE integration function. def kde

How can you create a KDE from histogram values only?

雨燕双飞 提交于 2019-12-05 07:03:27
I have a set of values that I'd like to plot the gaussian kernel density estimation of, however there are two problems that I'm having: I only have the values of bars not the values themselves I am plotting onto a categorical axis Here's the plot I've generated so far: The order of the y axis is actually relevant since it is representative of the phylogeny of each bacterial species. I'd like to add a gaussian kde overlay for each color, but so far I haven't been able to leverage seaborn or scipy to do this. Here's the code for the above grouped bar plot using python and matplotlib: enterN =

confusion on 2 dimension kernel density estimation in R

大兔子大兔子 提交于 2019-12-04 20:31:16
A kernel density estimator is used to estimate a particular probability density function (see mvstat.net and sckit-learn docs for references) My confusion is about what exactly does kde2d() do? Does it estimate the joint distribution probability density function of two random variables f(a,b) in the below example? And what does the color mean? Here is the code example I am referring to. b <- log10(rgamma(1000, 6, 3)) a <- log10((rweibull(1000, 8, 2))) density <- kde2d(a, b, n=100) colour_flow <- colorRampPalette(c('white', 'blue', 'yellow', 'red', 'darkred')) filled.contour(density, color

Illustrate mean and standard deviation in ggplot2 density plot

纵然是瞬间 提交于 2019-12-04 15:45:24
I'm trying to construct a plot where I plot normally distributed variables showing their mean on the x-axis and the standard deviation (SD) on the y-axis. Kinda like a density plot, but instead of having the density on the y-axis I want to have the SD (value). I'm working with the data below, set.seed(1) mu1 <- rnorm(10^5, mean = 1, sd = 1) mu3 <- rnorm(10^5, mean = 3, sd = 2) two normally distributed variables. Here their mean and sd, # install.packages("tidyverse", dependencies = TRUE) require(tidyverse) tibble(mu1, mu3) %>% summarise_all(funs(mean, sd)) #> # A tibble: 1 x 4 #> mu1_mean mu3