Surface Plot of Multivariate Normal Density
I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]'
and covariance=9*I
. How can I plot its 2D surface in Matlab?
matlab normal-distribution probability-density
add a comment |
I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]'
and covariance=9*I
. How can I plot its 2D surface in Matlab?
matlab normal-distribution probability-density
add a comment |
I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]'
and covariance=9*I
. How can I plot its 2D surface in Matlab?
matlab normal-distribution probability-density
I have a likelihood function with Multivariate Normal Density whose mean is mu=[3 5]'
and covariance=9*I
. How can I plot its 2D surface in Matlab?
matlab normal-distribution probability-density
matlab normal-distribution probability-density
edited Feb 27 at 7:44
SecretAgentMan
718316
718316
asked Nov 27 '18 at 23:14
john greenjohn green
11
11
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The log-likelihood function can be obtained from the PDF or by referencing the wiki.
Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x
xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
for j = 1:length(X2)
x = [X1(i) X2(j)]';
L(i,j) = loglikeh(x);
end
end
If I've made a mistake, please comment so I can fix. Hope this helps.
Plotting
surf(X1,X2,L') % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')
See these answers for more visualizations and options.
add a comment |
You may try to refer in here:
(use mvnpdf function in MATLAB)
F = mvnpdf([X1(:) X2(:)],mu,Sigma)
Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509675%2fsurface-plot-of-multivariate-normal-density%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The log-likelihood function can be obtained from the PDF or by referencing the wiki.
Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x
xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
for j = 1:length(X2)
x = [X1(i) X2(j)]';
L(i,j) = loglikeh(x);
end
end
If I've made a mistake, please comment so I can fix. Hope this helps.
Plotting
surf(X1,X2,L') % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')
See these answers for more visualizations and options.
add a comment |
The log-likelihood function can be obtained from the PDF or by referencing the wiki.
Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x
xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
for j = 1:length(X2)
x = [X1(i) X2(j)]';
L(i,j) = loglikeh(x);
end
end
If I've made a mistake, please comment so I can fix. Hope this helps.
Plotting
surf(X1,X2,L') % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')
See these answers for more visualizations and options.
add a comment |
The log-likelihood function can be obtained from the PDF or by referencing the wiki.
Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x
xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
for j = 1:length(X2)
x = [X1(i) X2(j)]';
L(i,j) = loglikeh(x);
end
end
If I've made a mistake, please comment so I can fix. Hope this helps.
Plotting
surf(X1,X2,L') % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')
See these answers for more visualizations and options.
The log-likelihood function can be obtained from the PDF or by referencing the wiki.
Mu = [3 5]';
Sigma = 9*eye(2);
loglikeh=@(x) -0.5*log(det(Sigma)) + (x-Mu)'*inv(Sigma)*(x-Mu) + length(x)*log(2*pi); % For single x
xMin = -2;
xMax = 7;
step = 0.1;
X1 = xMin:step:xMax;
X2 = xMin:step:xMax;
L = zeros(length(X1),length(X2));
for i = 1:length(X1)
for j = 1:length(X2)
x = [X1(i) X2(j)]';
L(i,j) = loglikeh(x);
end
end
If I've made a mistake, please comment so I can fix. Hope this helps.
Plotting
surf(X1,X2,L') % Note L is transposed if done this way
xlabel('x_1')
ylabel('x_2')
zlabel('log-likelihood')
See these answers for more visualizations and options.
answered Nov 28 '18 at 15:13
SecretAgentManSecretAgentMan
718316
718316
add a comment |
add a comment |
You may try to refer in here:
(use mvnpdf function in MATLAB)
F = mvnpdf([X1(:) X2(:)],mu,Sigma)
Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
add a comment |
You may try to refer in here:
(use mvnpdf function in MATLAB)
F = mvnpdf([X1(:) X2(:)],mu,Sigma)
Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
add a comment |
You may try to refer in here:
(use mvnpdf function in MATLAB)
F = mvnpdf([X1(:) X2(:)],mu,Sigma)
Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html
You may try to refer in here:
(use mvnpdf function in MATLAB)
F = mvnpdf([X1(:) X2(:)],mu,Sigma)
Please check here https://www.mathworks.com/help/stats/multivariate-normal-distribution.html
answered Nov 28 '18 at 1:10
A. SyamA. Syam
113119
113119
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
add a comment |
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
The multivariate Normal probability density function (PDF) and likelihood function are not the same thing. See here
– SecretAgentMan
Nov 28 '18 at 14:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53509675%2fsurface-plot-of-multivariate-normal-density%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown