R: 'x' values being identical and lambda values being too redistricted in boxcoxnc functionCounting the number of elements with the values of x in a vectorIs there a built-in function for finding the mode?Grouping functions (tapply, by, aggregate) and the *apply familyRemove rows with all or some NAs (missing values) in data.frameHow do I replace NA values with zeros in an R dataframe?Explicitly calling return in a function or notFunction to clear the console in R and RStudioHow can I view the source code for a function?Function values with normally distributed errorsR: use one list to modify another list efficiently
Why not use a diode instead of a resistor for current sense circuits?
Marrying a second woman behind your wife's back: is it wrong and can Quran/Hadith prove this?
Is it legal for private citizens to "impound" e-scooters?
Unethical behavior : should I report it?
Character is called by their first initial. How do I write it?
How to deal with a player who makes bad characters and kills them?
What's the difference between 2a and 10a charging options?
Send a single HTML email from Thunderbird, overriding the default "plain text" setting
3D Statue Park: U shapes
Basic Questions on Wiener Filtering
Weed in Massachusetts: underground roots, skunky smell when bruised
A planet illuminated by a black hole?
How can I prevent corporations from growing their own workforce?
Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?
How do we explain the E major chord in this progression?
How do I run a game when my PCs have different approaches to combat?
Does the Intel 8086 CPU have user mode and kernel mode?
At what rate does the volume (velocity) of a note decay?
Integral of the integral using NIntegrate
How to judge a Ph.D. applicant that arrives "out of thin air"
Examples of simultaneous independent breakthroughs
This message is flooding my syslog, how to find where it comes from?
Are there any examples of technologies have been lost over time?
Can two figures have the same area, perimeter, and same number of segments have different shape?
R: 'x' values being identical and lambda values being too redistricted in boxcoxnc function
Counting the number of elements with the values of x in a vectorIs there a built-in function for finding the mode?Grouping functions (tapply, by, aggregate) and the *apply familyRemove rows with all or some NAs (missing values) in data.frameHow do I replace NA values with zeros in an R dataframe?Explicitly calling return in a function or notFunction to clear the console in R and RStudioHow can I view the source code for a function?Function values with normally distributed errorsR: use one list to modify another list efficiently
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to use the boxcoxnc function in the AID package to calculate normalized data using the Shapiro-Wilcox W statistic to determine lambda.
I want the boxcoxnc function to run on each column in my data frame in a for loop.
data<-data.frame(data[,2:27])
for (f in 1:length(data))
model<-boxcoxnc(as.matrix(as.numeric(unlist(data[f]))),
method="sw",lambda = as.numeric(seq(-20,20,0.01)))
The first three columns work fine and when I get to the fourth I get the error:
Error in boxcoxnc(as.matrix(as.numeric(unlist(data[f]))), method = "sw", :
Enlarge the range of the lambda
Which I do, enlarge the range of lambda to(-21, -20, 0.01) and then get the following error on the first column.
Error in shapiro.test(store2[[x]]) : all 'x' values are identical
However, the data is not identical. It is only certain columns in my data frame that does this and I do not know why. The fourth column that calls the first error is this:
1.539
1.587
1.558
1.625
1.651
1.659
1.654
1.643
1.53
1.552
1.537
1.522
1.559
1.636
1.57
1.631
1.544
1.625
1.552
1.519
1.556
1.528
1.616
1.554
1.571
1.534
1.574
1.578
1.574
1.533
1.54
1.531
1.561
1.576
1.624
1.593
1.557
1.556
1.559
1.59
The first column is this: 6.301
6.611
6.448
7.049
7.068
7.208
7.215
7.084
6.129
6.471
6.295
5.984
6.34
7.052
6.448
6.885
6.42
6.963
6.169
6.185
6.289
6.05
6.901
6.333
6.458
6.228
6.458
6.477
6.71
6.296
6.147
6.171
6.278
6.667
6.932
6.646
6.369
6.408
6.466
6.688
Any help is really appreciated.
r normal-distribution
add a comment |
I am trying to use the boxcoxnc function in the AID package to calculate normalized data using the Shapiro-Wilcox W statistic to determine lambda.
I want the boxcoxnc function to run on each column in my data frame in a for loop.
data<-data.frame(data[,2:27])
for (f in 1:length(data))
model<-boxcoxnc(as.matrix(as.numeric(unlist(data[f]))),
method="sw",lambda = as.numeric(seq(-20,20,0.01)))
The first three columns work fine and when I get to the fourth I get the error:
Error in boxcoxnc(as.matrix(as.numeric(unlist(data[f]))), method = "sw", :
Enlarge the range of the lambda
Which I do, enlarge the range of lambda to(-21, -20, 0.01) and then get the following error on the first column.
Error in shapiro.test(store2[[x]]) : all 'x' values are identical
However, the data is not identical. It is only certain columns in my data frame that does this and I do not know why. The fourth column that calls the first error is this:
1.539
1.587
1.558
1.625
1.651
1.659
1.654
1.643
1.53
1.552
1.537
1.522
1.559
1.636
1.57
1.631
1.544
1.625
1.552
1.519
1.556
1.528
1.616
1.554
1.571
1.534
1.574
1.578
1.574
1.533
1.54
1.531
1.561
1.576
1.624
1.593
1.557
1.556
1.559
1.59
The first column is this: 6.301
6.611
6.448
7.049
7.068
7.208
7.215
7.084
6.129
6.471
6.295
5.984
6.34
7.052
6.448
6.885
6.42
6.963
6.169
6.185
6.289
6.05
6.901
6.333
6.458
6.228
6.458
6.477
6.71
6.296
6.147
6.171
6.278
6.667
6.932
6.646
6.369
6.408
6.466
6.688
Any help is really appreciated.
r normal-distribution
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting thedata
or the result ofas.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).
– Valentin Ruano
Mar 26 at 18:28
add a comment |
I am trying to use the boxcoxnc function in the AID package to calculate normalized data using the Shapiro-Wilcox W statistic to determine lambda.
I want the boxcoxnc function to run on each column in my data frame in a for loop.
data<-data.frame(data[,2:27])
for (f in 1:length(data))
model<-boxcoxnc(as.matrix(as.numeric(unlist(data[f]))),
method="sw",lambda = as.numeric(seq(-20,20,0.01)))
The first three columns work fine and when I get to the fourth I get the error:
Error in boxcoxnc(as.matrix(as.numeric(unlist(data[f]))), method = "sw", :
Enlarge the range of the lambda
Which I do, enlarge the range of lambda to(-21, -20, 0.01) and then get the following error on the first column.
Error in shapiro.test(store2[[x]]) : all 'x' values are identical
However, the data is not identical. It is only certain columns in my data frame that does this and I do not know why. The fourth column that calls the first error is this:
1.539
1.587
1.558
1.625
1.651
1.659
1.654
1.643
1.53
1.552
1.537
1.522
1.559
1.636
1.57
1.631
1.544
1.625
1.552
1.519
1.556
1.528
1.616
1.554
1.571
1.534
1.574
1.578
1.574
1.533
1.54
1.531
1.561
1.576
1.624
1.593
1.557
1.556
1.559
1.59
The first column is this: 6.301
6.611
6.448
7.049
7.068
7.208
7.215
7.084
6.129
6.471
6.295
5.984
6.34
7.052
6.448
6.885
6.42
6.963
6.169
6.185
6.289
6.05
6.901
6.333
6.458
6.228
6.458
6.477
6.71
6.296
6.147
6.171
6.278
6.667
6.932
6.646
6.369
6.408
6.466
6.688
Any help is really appreciated.
r normal-distribution
I am trying to use the boxcoxnc function in the AID package to calculate normalized data using the Shapiro-Wilcox W statistic to determine lambda.
I want the boxcoxnc function to run on each column in my data frame in a for loop.
data<-data.frame(data[,2:27])
for (f in 1:length(data))
model<-boxcoxnc(as.matrix(as.numeric(unlist(data[f]))),
method="sw",lambda = as.numeric(seq(-20,20,0.01)))
The first three columns work fine and when I get to the fourth I get the error:
Error in boxcoxnc(as.matrix(as.numeric(unlist(data[f]))), method = "sw", :
Enlarge the range of the lambda
Which I do, enlarge the range of lambda to(-21, -20, 0.01) and then get the following error on the first column.
Error in shapiro.test(store2[[x]]) : all 'x' values are identical
However, the data is not identical. It is only certain columns in my data frame that does this and I do not know why. The fourth column that calls the first error is this:
1.539
1.587
1.558
1.625
1.651
1.659
1.654
1.643
1.53
1.552
1.537
1.522
1.559
1.636
1.57
1.631
1.544
1.625
1.552
1.519
1.556
1.528
1.616
1.554
1.571
1.534
1.574
1.578
1.574
1.533
1.54
1.531
1.561
1.576
1.624
1.593
1.557
1.556
1.559
1.59
The first column is this: 6.301
6.611
6.448
7.049
7.068
7.208
7.215
7.084
6.129
6.471
6.295
5.984
6.34
7.052
6.448
6.885
6.42
6.963
6.169
6.185
6.289
6.05
6.901
6.333
6.458
6.228
6.458
6.477
6.71
6.296
6.147
6.171
6.278
6.667
6.932
6.646
6.369
6.408
6.466
6.688
Any help is really appreciated.
r normal-distribution
r normal-distribution
asked Mar 26 at 17:28
dlsankardlsankar
62 bronze badges
62 bronze badges
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting thedata
or the result ofas.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).
– Valentin Ruano
Mar 26 at 18:28
add a comment |
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting thedata
or the result ofas.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).
– Valentin Ruano
Mar 26 at 18:28
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting the
data
or the result of as.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).– Valentin Ruano
Mar 26 at 18:28
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting the
data
or the result of as.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).– Valentin Ruano
Mar 26 at 18:28
add a comment |
1 Answer
1
active
oldest
votes
One thing you must keep always in mind in R is that by design R tends to just to keep going no matter what, coercing and converting the data even when some of the transformation actually do not make sense. This results in values and errors messages down the line that do not make sense and that is what may be happening here. If you inspect the result of as.matrix(as.numeric(...))
, for every one of those columns I likely that is not what you expect it to be.
Without knowing exactly how boxcoxnc
works I suggest the following alternative code to make it more readable and may-be even fix the bug but that is a big maybe:
for (col in 2:27)
model <- boxcoxnc(data[,col], method="sw", lambda = seq(-20,20,0.01))
# what are you trying to do with model here, it is rewritten every time.
Comments:
subsetting the original
data
is unnecessary since you are iterating through the columns by index.even when
data[col]
would work (since a data.frame is in fact a list of columns) is more appropriate to dodata[,col]
. Also instead oflength(data)
you should writencol(data)
but that expression is gone anyway.as.matrix(as.numeric(unlist(...))) seems totally unnecessary here and is just a chance to something go wrong in terms of R doing an untended conversion. Perhaps as.numeric is necessary iff
boxcoxnc
is a bit particular and really cannot accept anything but a numeric vector.as.numeric(seq(...))
can be justsec(...)
; it would be surprising ifseq
would return anything but a numeric vector.
Now, something you should consider is perhaps some of those columns do not contain numeric data. If it say numbers but as strings then yes you need as.numeric
. Can you confirm that there is no column that contains anything but numerics and integers typed data? Strings or factors would be problematic and might be the root cause of your issues. What is the result of:
sapply(d, class)
Btw apply
methods are preferable to for
loops so perhaps you want to go that route perhaps you co do something like this:
models <- sapply(data[,2:27], function(col)
boxcoxnc(col, method="sw", lambda = seq(-20,20,0.01))
)
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%2f55363029%2fr-x-values-being-identical-and-lambda-values-being-too-redistricted-in-boxcox%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
One thing you must keep always in mind in R is that by design R tends to just to keep going no matter what, coercing and converting the data even when some of the transformation actually do not make sense. This results in values and errors messages down the line that do not make sense and that is what may be happening here. If you inspect the result of as.matrix(as.numeric(...))
, for every one of those columns I likely that is not what you expect it to be.
Without knowing exactly how boxcoxnc
works I suggest the following alternative code to make it more readable and may-be even fix the bug but that is a big maybe:
for (col in 2:27)
model <- boxcoxnc(data[,col], method="sw", lambda = seq(-20,20,0.01))
# what are you trying to do with model here, it is rewritten every time.
Comments:
subsetting the original
data
is unnecessary since you are iterating through the columns by index.even when
data[col]
would work (since a data.frame is in fact a list of columns) is more appropriate to dodata[,col]
. Also instead oflength(data)
you should writencol(data)
but that expression is gone anyway.as.matrix(as.numeric(unlist(...))) seems totally unnecessary here and is just a chance to something go wrong in terms of R doing an untended conversion. Perhaps as.numeric is necessary iff
boxcoxnc
is a bit particular and really cannot accept anything but a numeric vector.as.numeric(seq(...))
can be justsec(...)
; it would be surprising ifseq
would return anything but a numeric vector.
Now, something you should consider is perhaps some of those columns do not contain numeric data. If it say numbers but as strings then yes you need as.numeric
. Can you confirm that there is no column that contains anything but numerics and integers typed data? Strings or factors would be problematic and might be the root cause of your issues. What is the result of:
sapply(d, class)
Btw apply
methods are preferable to for
loops so perhaps you want to go that route perhaps you co do something like this:
models <- sapply(data[,2:27], function(col)
boxcoxnc(col, method="sw", lambda = seq(-20,20,0.01))
)
add a comment |
One thing you must keep always in mind in R is that by design R tends to just to keep going no matter what, coercing and converting the data even when some of the transformation actually do not make sense. This results in values and errors messages down the line that do not make sense and that is what may be happening here. If you inspect the result of as.matrix(as.numeric(...))
, for every one of those columns I likely that is not what you expect it to be.
Without knowing exactly how boxcoxnc
works I suggest the following alternative code to make it more readable and may-be even fix the bug but that is a big maybe:
for (col in 2:27)
model <- boxcoxnc(data[,col], method="sw", lambda = seq(-20,20,0.01))
# what are you trying to do with model here, it is rewritten every time.
Comments:
subsetting the original
data
is unnecessary since you are iterating through the columns by index.even when
data[col]
would work (since a data.frame is in fact a list of columns) is more appropriate to dodata[,col]
. Also instead oflength(data)
you should writencol(data)
but that expression is gone anyway.as.matrix(as.numeric(unlist(...))) seems totally unnecessary here and is just a chance to something go wrong in terms of R doing an untended conversion. Perhaps as.numeric is necessary iff
boxcoxnc
is a bit particular and really cannot accept anything but a numeric vector.as.numeric(seq(...))
can be justsec(...)
; it would be surprising ifseq
would return anything but a numeric vector.
Now, something you should consider is perhaps some of those columns do not contain numeric data. If it say numbers but as strings then yes you need as.numeric
. Can you confirm that there is no column that contains anything but numerics and integers typed data? Strings or factors would be problematic and might be the root cause of your issues. What is the result of:
sapply(d, class)
Btw apply
methods are preferable to for
loops so perhaps you want to go that route perhaps you co do something like this:
models <- sapply(data[,2:27], function(col)
boxcoxnc(col, method="sw", lambda = seq(-20,20,0.01))
)
add a comment |
One thing you must keep always in mind in R is that by design R tends to just to keep going no matter what, coercing and converting the data even when some of the transformation actually do not make sense. This results in values and errors messages down the line that do not make sense and that is what may be happening here. If you inspect the result of as.matrix(as.numeric(...))
, for every one of those columns I likely that is not what you expect it to be.
Without knowing exactly how boxcoxnc
works I suggest the following alternative code to make it more readable and may-be even fix the bug but that is a big maybe:
for (col in 2:27)
model <- boxcoxnc(data[,col], method="sw", lambda = seq(-20,20,0.01))
# what are you trying to do with model here, it is rewritten every time.
Comments:
subsetting the original
data
is unnecessary since you are iterating through the columns by index.even when
data[col]
would work (since a data.frame is in fact a list of columns) is more appropriate to dodata[,col]
. Also instead oflength(data)
you should writencol(data)
but that expression is gone anyway.as.matrix(as.numeric(unlist(...))) seems totally unnecessary here and is just a chance to something go wrong in terms of R doing an untended conversion. Perhaps as.numeric is necessary iff
boxcoxnc
is a bit particular and really cannot accept anything but a numeric vector.as.numeric(seq(...))
can be justsec(...)
; it would be surprising ifseq
would return anything but a numeric vector.
Now, something you should consider is perhaps some of those columns do not contain numeric data. If it say numbers but as strings then yes you need as.numeric
. Can you confirm that there is no column that contains anything but numerics and integers typed data? Strings or factors would be problematic and might be the root cause of your issues. What is the result of:
sapply(d, class)
Btw apply
methods are preferable to for
loops so perhaps you want to go that route perhaps you co do something like this:
models <- sapply(data[,2:27], function(col)
boxcoxnc(col, method="sw", lambda = seq(-20,20,0.01))
)
One thing you must keep always in mind in R is that by design R tends to just to keep going no matter what, coercing and converting the data even when some of the transformation actually do not make sense. This results in values and errors messages down the line that do not make sense and that is what may be happening here. If you inspect the result of as.matrix(as.numeric(...))
, for every one of those columns I likely that is not what you expect it to be.
Without knowing exactly how boxcoxnc
works I suggest the following alternative code to make it more readable and may-be even fix the bug but that is a big maybe:
for (col in 2:27)
model <- boxcoxnc(data[,col], method="sw", lambda = seq(-20,20,0.01))
# what are you trying to do with model here, it is rewritten every time.
Comments:
subsetting the original
data
is unnecessary since you are iterating through the columns by index.even when
data[col]
would work (since a data.frame is in fact a list of columns) is more appropriate to dodata[,col]
. Also instead oflength(data)
you should writencol(data)
but that expression is gone anyway.as.matrix(as.numeric(unlist(...))) seems totally unnecessary here and is just a chance to something go wrong in terms of R doing an untended conversion. Perhaps as.numeric is necessary iff
boxcoxnc
is a bit particular and really cannot accept anything but a numeric vector.as.numeric(seq(...))
can be justsec(...)
; it would be surprising ifseq
would return anything but a numeric vector.
Now, something you should consider is perhaps some of those columns do not contain numeric data. If it say numbers but as strings then yes you need as.numeric
. Can you confirm that there is no column that contains anything but numerics and integers typed data? Strings or factors would be problematic and might be the root cause of your issues. What is the result of:
sapply(d, class)
Btw apply
methods are preferable to for
loops so perhaps you want to go that route perhaps you co do something like this:
models <- sapply(data[,2:27], function(col)
boxcoxnc(col, method="sw", lambda = seq(-20,20,0.01))
)
edited Mar 26 at 20:31
answered Mar 26 at 18:57
Valentin RuanoValentin Ruano
2,18711 silver badges26 bronze badges
2,18711 silver badges26 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55363029%2fr-x-values-being-identical-and-lambda-values-being-too-redistricted-in-boxcox%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
When you try to make sense of an error message coming from a method/function you need to inspect the values that you are actually passing to the said method. When you see that the values are not indentically are you inspecting the
data
or the result ofas.matrix(as.numeric(...))
? Assign that expression to a variable and see how it looks like (values, dimensions etc).– Valentin Ruano
Mar 26 at 18:28