Use ksdensity with weight

Use ksdensity with weight

By : user334830
Date : November 22 2020, 03:01 PM
To fix this issue How to apply "ksdensity" to a set of data with weights. For example, my data is [5 4 7 9], and the weight of each value is [3 2 1 2], which means there are 3 "5", 2 "4", 1 "7", and 2 "9", and I want to find ksdensity for them. Thank you for your help! , Try this before applying ksdensity:
code :
newData = repelem(OldData,weights)

Share : facebook icon twitter icon
Matlab ksdensity not working properly

Matlab ksdensity not working properly

By : Rubén Marcos
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The probability density estimate that ksdensity returns is based off the assumption of a normal kernal function. If your data has values near zero, you'll naturally get some overlap into the negative as the individual kernels are summed:
code :
x = gamrnd(5,7,1000,1);
[f,xi] = ksdensity(x,'support','positive');
matlab pdf estimation (ksdensity) not working

matlab pdf estimation (ksdensity) not working

By : michael abella
Date : March 29 2020, 07:55 AM
should help you out Is this closer to what you expect?
The ksdensity function expects a vector of samples from the distribution, whereas you were feeding it the values of the probability density function.
code :
>> xi = -3:0.1:3;
>> p1 = normpdf(xi, 1, 0.3);
>> p2 = normpdf(xi,-1, 0.3);
>> subplot(211)
>> plot(xi, 0.5*p1+0.5*p2)
>> a1 = 1 + 0.3 * randn(10000,1);  % construct the same distribution
>> a2 = -1 + 0.3 * randn(10000,1); % construct the same distribution
>> [f, xs] = ksdensity([a1;a2]);
>> subplot(212)
>> plot(xs, f)
ksdensity of frequency histogram

ksdensity of frequency histogram

By : beeb
Date : March 29 2020, 07:55 AM
it should still fix some issue The trick is here that I don't think you are calculating the frequency correctly in your histogram. You are neglecting the bin width. Your frequency should be the number of SNPs per position, which requires dividing by the number of (possibly fractional) positions per bin.
Try this:
code :
Data = rand(1, 1e4);

[n, c] = hist(Data, 20);
dc = abs(c(2) - c(1));

f = n./(dc * sum(n));

[~,f_kde,xi] = kde(Data);
Matlab: A plot with ksdensity to have a pseudo 3D look

Matlab: A plot with ksdensity to have a pseudo 3D look

By : Deepak Arya
Date : March 29 2020, 07:55 AM
This might help you I would like to make a histogram plot using ksdensity in 3D. My plot looks similar to the example here; , This is the explicit solution of your problem:
code :
hold on; grid on
for i = 1:15
    path = ['tmp_',num2str(i),'.out'];
    fid = fopen(path, 'r');
    a = textscan(fid,'%f');

    % Appearantly the first line is a string in some of your files
    % This if statement will take care of it ;)
    if isempty(a{1})
        a = textscan(fid,'%f');
    tmp = a{1};
    % Some of your files (all but one I think) contain element numbering
    % This if statement takes care of it ;)
    if length(tmp) > 180000
        tmp = tmp(2:2:end);
    [f, xi] = ksdensity(tmp);
    plot3(xi, ones(length(f))*i, f)
MATLAB histfit - get PDF from data, ksdensity?

MATLAB histfit - get PDF from data, ksdensity?

By : Akhil Polamarasetty
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I would like to get the equation of the density curve from a plot using histfit.
Related Posts Related Posts :
  • Get rectangle coordinates from a point and a line
  • after user had entered value update number to include commas
  • How to keep new symbolic value for subs remain through Matlab Code
  • I would like to beable to stack rows of one matrix in a special way
  • MATLAB / Octave - how to parse CSV file with numbers and strings that contain commas
  • Accessing video frames in specific order MATLAB
  • Matlab equivalent code of the following equation
  • Brownian motion with multiple molecules/particles [Matlab]
  • Dynamic window forming in efficient way in MATLAB
  • How to concatenate / assign string of different length to existing Matlab table?
  • Best practice for validation of two related inputs in Matlab
  • Putting a smaller 3D matrix into a bigger 3D matrix (3D sub2ind)
  • MATLAB stereo calibration result is different when point pairs are reordered
  • How to generate random points inside sphere using MATLAB
  • MATLAB Piecewise Linear Transformation Function
  • How does imfilter 'replicate' in matlab work for bigger filters?
  • How to add, subtract, etc. two structs element-by-element when they have the same fields
  • Can a MATLAB App Designer app launch a script which saves figures?
  • Subset a region from boundary coordinates using imrect - Matlab
  • Integral of an integral
  • Basic Concept of covariance matrix and using it in Matlab
  • Number series with uniform distribution for a given variance and a mean in matlab
  • set 'help' for matlab anonymous functions
  • How do I change the font of colorbar to latex?
  • How do vectors as inputs work in interpreted matlab function block in Simulink?
  • How can I convert binary bits into index in MATLAB
  • Wrong value for the derivative of the solution of an ODE in MATLAB
  • Sum of rectangles in Matlab
  • How to extract the random shift intensity difference a 3D array elements in MATLAB?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org