C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# 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 :

## 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');
figure
plot(xi,f,'linewidth',2)
``````

## matlab pdf estimation (ksdensity) not working

By : michael abella
Date : March 29 2020, 07:55 AM
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

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);

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

f = n./(dc * sum(n));
plot(c,f,'r','LineWidth',3)

[~,f_kde,xi] = kde(Data);
line(xi,f_kde);
``````

## 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 :
``````figure(1)
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})
fgetl(fid);
a = textscan(fid,'%f');
end
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);
end
fclose(fid);
[f, xi] = ksdensity(tmp);
plot3(xi, ones(length(f))*i, f)
end
view(3)
``````

## 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.