list() is not updating in the for loop in R
I want to estimate the parameters of the skew normal distribution using mle2
function in r
. I have copied my r
function below.
library(bbmle)
library(sn)
y = c(rsn(n=50, xi=0, omega=1, alpha=1, tau=0, dp=NULL), rsn(n=50, xi=0, omega=1, alpha=6, tau=0, dp=NULL))
n= length(y)
sn.fit = function(xi, omega, alpha){
-sum(dsn(y, xi=0, omega=1, alpha, log = TRUE))
}
parl = list()
for(i in 1:(n-1)){
dat = list(y[1:i])
parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = dat)@coef
}
parll = do.call("rbind", parl)
parll
The output is given below.
> parll
xi omega alpha
[1,] 0 1 1.408533
[2,] 0 1 1.408533
[3,] 0 1 1.408533
[4,] 0 1 1.408533
[5,] 0 1 1.408533
[6,] 0 1 1.408533
[7,] 0 1 1.408533
[8,] 0 1 1.408533
[9,] 0 1 1.408533
[10,] 0 1 1.408533
[11,] 0 1 1.408533
[12,] 0 1 1.408533
Since my intention is to estimate alpha
for y[1:i]
for i=1,...,(n-1)
. Why my result is not updating into the list?
Thank you in advance.
r list for-loop mle
add a comment |
I want to estimate the parameters of the skew normal distribution using mle2
function in r
. I have copied my r
function below.
library(bbmle)
library(sn)
y = c(rsn(n=50, xi=0, omega=1, alpha=1, tau=0, dp=NULL), rsn(n=50, xi=0, omega=1, alpha=6, tau=0, dp=NULL))
n= length(y)
sn.fit = function(xi, omega, alpha){
-sum(dsn(y, xi=0, omega=1, alpha, log = TRUE))
}
parl = list()
for(i in 1:(n-1)){
dat = list(y[1:i])
parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = dat)@coef
}
parll = do.call("rbind", parl)
parll
The output is given below.
> parll
xi omega alpha
[1,] 0 1 1.408533
[2,] 0 1 1.408533
[3,] 0 1 1.408533
[4,] 0 1 1.408533
[5,] 0 1 1.408533
[6,] 0 1 1.408533
[7,] 0 1 1.408533
[8,] 0 1 1.408533
[9,] 0 1 1.408533
[10,] 0 1 1.408533
[11,] 0 1 1.408533
[12,] 0 1 1.408533
Since my intention is to estimate alpha
for y[1:i]
for i=1,...,(n-1)
. Why my result is not updating into the list?
Thank you in advance.
r list for-loop mle
1
You've hard codedy
into thesn.fit
function. Thus you are using the same data for every call, it's not changing. Thedata=
part only works if you pass a formula, not a function tomle2
.
– MrFlick
Nov 19 '18 at 19:50
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick is this correct? right?parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01
add a comment |
I want to estimate the parameters of the skew normal distribution using mle2
function in r
. I have copied my r
function below.
library(bbmle)
library(sn)
y = c(rsn(n=50, xi=0, omega=1, alpha=1, tau=0, dp=NULL), rsn(n=50, xi=0, omega=1, alpha=6, tau=0, dp=NULL))
n= length(y)
sn.fit = function(xi, omega, alpha){
-sum(dsn(y, xi=0, omega=1, alpha, log = TRUE))
}
parl = list()
for(i in 1:(n-1)){
dat = list(y[1:i])
parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = dat)@coef
}
parll = do.call("rbind", parl)
parll
The output is given below.
> parll
xi omega alpha
[1,] 0 1 1.408533
[2,] 0 1 1.408533
[3,] 0 1 1.408533
[4,] 0 1 1.408533
[5,] 0 1 1.408533
[6,] 0 1 1.408533
[7,] 0 1 1.408533
[8,] 0 1 1.408533
[9,] 0 1 1.408533
[10,] 0 1 1.408533
[11,] 0 1 1.408533
[12,] 0 1 1.408533
Since my intention is to estimate alpha
for y[1:i]
for i=1,...,(n-1)
. Why my result is not updating into the list?
Thank you in advance.
r list for-loop mle
I want to estimate the parameters of the skew normal distribution using mle2
function in r
. I have copied my r
function below.
library(bbmle)
library(sn)
y = c(rsn(n=50, xi=0, omega=1, alpha=1, tau=0, dp=NULL), rsn(n=50, xi=0, omega=1, alpha=6, tau=0, dp=NULL))
n= length(y)
sn.fit = function(xi, omega, alpha){
-sum(dsn(y, xi=0, omega=1, alpha, log = TRUE))
}
parl = list()
for(i in 1:(n-1)){
dat = list(y[1:i])
parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = dat)@coef
}
parll = do.call("rbind", parl)
parll
The output is given below.
> parll
xi omega alpha
[1,] 0 1 1.408533
[2,] 0 1 1.408533
[3,] 0 1 1.408533
[4,] 0 1 1.408533
[5,] 0 1 1.408533
[6,] 0 1 1.408533
[7,] 0 1 1.408533
[8,] 0 1 1.408533
[9,] 0 1 1.408533
[10,] 0 1 1.408533
[11,] 0 1 1.408533
[12,] 0 1 1.408533
Since my intention is to estimate alpha
for y[1:i]
for i=1,...,(n-1)
. Why my result is not updating into the list?
Thank you in advance.
r list for-loop mle
r list for-loop mle
asked Nov 19 '18 at 19:32
score324score324
999
999
1
You've hard codedy
into thesn.fit
function. Thus you are using the same data for every call, it's not changing. Thedata=
part only works if you pass a formula, not a function tomle2
.
– MrFlick
Nov 19 '18 at 19:50
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick is this correct? right?parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01
add a comment |
1
You've hard codedy
into thesn.fit
function. Thus you are using the same data for every call, it's not changing. Thedata=
part only works if you pass a formula, not a function tomle2
.
– MrFlick
Nov 19 '18 at 19:50
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick is this correct? right?parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01
1
1
You've hard coded
y
into the sn.fit
function. Thus you are using the same data for every call, it's not changing. The data=
part only works if you pass a formula, not a function to mle2
.– MrFlick
Nov 19 '18 at 19:50
You've hard coded
y
into the sn.fit
function. Thus you are using the same data for every call, it's not changing. The data=
part only works if you pass a formula, not a function to mle2
.– MrFlick
Nov 19 '18 at 19:50
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick is this correct? right?
parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01
@MrFlick is this correct? right?
parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01
add a comment |
0
active
oldest
votes
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%2f53381436%2flist-is-not-updating-in-the-for-loop-in-r%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53381436%2flist-is-not-updating-in-the-for-loop-in-r%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
1
You've hard coded
y
into thesn.fit
function. Thus you are using the same data for every call, it's not changing. Thedata=
part only works if you pass a formula, not a function tomle2
.– MrFlick
Nov 19 '18 at 19:50
@MrFlick, Am I able to improve this? Thanks.
– score324
Nov 19 '18 at 19:59
@MrFlick is this correct? right?
parl = list() for(i in 1:(n-1)){ dat = y[1:i] sn.fit = function(xi, omega, alpha){ -sum(dsn(dat, xi=0, omega=1, alpha, log = TRUE)) } parl[[i]]= mle2(sn.fit, start = list(xi = 0, omega = 1, alpha = 1), data = list(dat))@coef } parll = do.call("rbind", parl) parll
– score324
Nov 19 '18 at 20:01