Running into strange errors when using glmnet and generating graphs Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsDo you have to normalize data when building decision trees using R?Finding predictions using biglm without finding errorsWhy does ada (adaboost) in R return different training error graphs and variable importance plots when running the same function multiple times?Using R and Python togetherHow to keep track of assumptions/design choices and avoid errors in complex projectsError while using decompose and stl functions in RHow to deal with an attribute including a lot of character or factor values when using caret package in RSpliting training data into multiple variables using RRunning multiple random forest and combining themImporting Excel format data into R/R Studio and using glmnet package?
Coin Game with infinite paradox
Is Bran literally the world's memory?
Married in secret, can marital status in passport be changed at a later date?
What came first? Venom as the movie or as the song?
Like totally amazing interchangeable sister outfit accessory swapping or whatever
Can gravitational waves pass through a black hole?
What is the ongoing value of the Kanban board to the developers as opposed to management
How to keep bees out of canned beverages?
Lights are flickering on and off after accidentally bumping into light switch
Kepler's 3rd law: ratios don't fit data
Are Flameskulls resistant to magical piercing damage?
How to calculate density of unknown planet?
Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?
Knights and Knaves question
Why not use the yoke to control yaw, as well as pitch and roll?
Why aren't these two solutions equivalent? Combinatorics problem
FME Console for testing
Will the Antimagic Field spell cause elementals not summoned by magic to dissipate?
When speaking, how do you change your mind mid-sentence?
Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?
Why does my GNOME settings mention "Moto C Plus"?
Who's this lady in the war room?
Is it OK if I do not take the receipt in Germany?
Protagonist's race is hidden - should I reveal it?
Running into strange errors when using glmnet and generating graphs
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsDo you have to normalize data when building decision trees using R?Finding predictions using biglm without finding errorsWhy does ada (adaboost) in R return different training error graphs and variable importance plots when running the same function multiple times?Using R and Python togetherHow to keep track of assumptions/design choices and avoid errors in complex projectsError while using decompose and stl functions in RHow to deal with an attribute including a lot of character or factor values when using caret package in RSpliting training data into multiple variables using RRunning multiple random forest and combining themImporting Excel format data into R/R Studio and using glmnet package?
$begingroup$
I developed a very simple Ridge Regression with glmnet, the R package. When I use the plot.glmnet()
function I encounter strange errors:
plot.glmnet(ridge_model, xvar = "lambda", label = TRUE)
Error in if(nr ==1) {: argument is of length zero
This error is related to IF statements and loops. It does not even seem related to the graph. Even when I use this simplest coding that should work according to the documentation
plot.glmnet(ridge_model)
I still get the same error.
Below I am representing a more complete picture of the script I have used:
library(glmnet)
library(Matrix)
library(foreach)
attach(data)
x = as.matrix(data[, c(3,2)])
y = as.matrix(data[, c(1)])
# Setting up the cross validation of a Ridge Regression
set.seed(101)
cv.glmnet(x, y, type.measure = "mse", alpha = 0)
# Plotting the graph of the Lambda values vs. the MSEs. This works just fine
ridge1 <- cv.glmnet(x, y, type.measure = "mse", alpha = 0)
plot.cv.glmnet(ridge1, main = "Log(Lambda) vs MSE")
# Attempting to extract a graph of coefficients.
# Either simple or more complex coding generates same error.
plot.glmnet(ridge1)
plot.glmnet(ridge1, xvar="lambda", label = TRUE)
r regularization plotting ridge-regression
$endgroup$
add a comment |
$begingroup$
I developed a very simple Ridge Regression with glmnet, the R package. When I use the plot.glmnet()
function I encounter strange errors:
plot.glmnet(ridge_model, xvar = "lambda", label = TRUE)
Error in if(nr ==1) {: argument is of length zero
This error is related to IF statements and loops. It does not even seem related to the graph. Even when I use this simplest coding that should work according to the documentation
plot.glmnet(ridge_model)
I still get the same error.
Below I am representing a more complete picture of the script I have used:
library(glmnet)
library(Matrix)
library(foreach)
attach(data)
x = as.matrix(data[, c(3,2)])
y = as.matrix(data[, c(1)])
# Setting up the cross validation of a Ridge Regression
set.seed(101)
cv.glmnet(x, y, type.measure = "mse", alpha = 0)
# Plotting the graph of the Lambda values vs. the MSEs. This works just fine
ridge1 <- cv.glmnet(x, y, type.measure = "mse", alpha = 0)
plot.cv.glmnet(ridge1, main = "Log(Lambda) vs MSE")
# Attempting to extract a graph of coefficients.
# Either simple or more complex coding generates same error.
plot.glmnet(ridge1)
plot.glmnet(ridge1, xvar="lambda", label = TRUE)
r regularization plotting ridge-regression
$endgroup$
$begingroup$
tryxvar=lambda
(i.e. without the quotation marks)
$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42
add a comment |
$begingroup$
I developed a very simple Ridge Regression with glmnet, the R package. When I use the plot.glmnet()
function I encounter strange errors:
plot.glmnet(ridge_model, xvar = "lambda", label = TRUE)
Error in if(nr ==1) {: argument is of length zero
This error is related to IF statements and loops. It does not even seem related to the graph. Even when I use this simplest coding that should work according to the documentation
plot.glmnet(ridge_model)
I still get the same error.
Below I am representing a more complete picture of the script I have used:
library(glmnet)
library(Matrix)
library(foreach)
attach(data)
x = as.matrix(data[, c(3,2)])
y = as.matrix(data[, c(1)])
# Setting up the cross validation of a Ridge Regression
set.seed(101)
cv.glmnet(x, y, type.measure = "mse", alpha = 0)
# Plotting the graph of the Lambda values vs. the MSEs. This works just fine
ridge1 <- cv.glmnet(x, y, type.measure = "mse", alpha = 0)
plot.cv.glmnet(ridge1, main = "Log(Lambda) vs MSE")
# Attempting to extract a graph of coefficients.
# Either simple or more complex coding generates same error.
plot.glmnet(ridge1)
plot.glmnet(ridge1, xvar="lambda", label = TRUE)
r regularization plotting ridge-regression
$endgroup$
I developed a very simple Ridge Regression with glmnet, the R package. When I use the plot.glmnet()
function I encounter strange errors:
plot.glmnet(ridge_model, xvar = "lambda", label = TRUE)
Error in if(nr ==1) {: argument is of length zero
This error is related to IF statements and loops. It does not even seem related to the graph. Even when I use this simplest coding that should work according to the documentation
plot.glmnet(ridge_model)
I still get the same error.
Below I am representing a more complete picture of the script I have used:
library(glmnet)
library(Matrix)
library(foreach)
attach(data)
x = as.matrix(data[, c(3,2)])
y = as.matrix(data[, c(1)])
# Setting up the cross validation of a Ridge Regression
set.seed(101)
cv.glmnet(x, y, type.measure = "mse", alpha = 0)
# Plotting the graph of the Lambda values vs. the MSEs. This works just fine
ridge1 <- cv.glmnet(x, y, type.measure = "mse", alpha = 0)
plot.cv.glmnet(ridge1, main = "Log(Lambda) vs MSE")
# Attempting to extract a graph of coefficients.
# Either simple or more complex coding generates same error.
plot.glmnet(ridge1)
plot.glmnet(ridge1, xvar="lambda", label = TRUE)
r regularization plotting ridge-regression
r regularization plotting ridge-regression
edited Apr 12 at 4:07
Sympa
asked Apr 4 at 22:04
SympaSympa
1164
1164
$begingroup$
tryxvar=lambda
(i.e. without the quotation marks)
$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42
add a comment |
$begingroup$
tryxvar=lambda
(i.e. without the quotation marks)
$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42
$begingroup$
try
xvar=lambda
(i.e. without the quotation marks)$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
try
xvar=lambda
(i.e. without the quotation marks)$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fdatascience.stackexchange.com%2fquestions%2f48636%2frunning-into-strange-errors-when-using-glmnet-and-generating-graphs%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 Data Science Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fdatascience.stackexchange.com%2fquestions%2f48636%2frunning-into-strange-errors-when-using-glmnet-and-generating-graphs%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
$begingroup$
try
xvar=lambda
(i.e. without the quotation marks)$endgroup$
– I'mAnAccountantIKnowAlotOfMath
Apr 5 at 3:03
$begingroup$
xvar=lambda generates the error: object 'lambda' not found.
$endgroup$
– Sympa
Apr 5 at 18:03
$begingroup$
We're going to need a lot more information on your script to be able to figure this one out. The error is almost certainly due to something "behind the scenes" in plot.glmnet() creating the graph, and seems like an input validation condition where "nr" means "number of rows" or something similar. Can you include some code used to generate ridge_model?
$endgroup$
– Upper_Case
Apr 5 at 19:10
$begingroup$
Is there anyway to share an Excel file that represents the data and an R/R Studio script file? The mentioned files are actually pretty small. But, just sharing the codes in absence of the actual data that is too big to impart in just code rows, the review of this situation is a bit difficult. I would think or hope that the error I have encountered is rather common. But, I don't know that for sure.
$endgroup$
– Sympa
Apr 6 at 0:18
$begingroup$
@Sympa The problem is that the error is not very specific. I've already offered my best guess about what's going on, but that's as far as the information you've posted can take us. The data itself is not very useful, because the error is at least as likely to be due to your R code as it is to be a problem with the underlying data. I'd even say moreso, because the problem seems to be with the ridge_model object, which you were able to generate from your data. In either case, the R script will be vastly more useful than your data set.
$endgroup$
– Upper_Case
Apr 8 at 17:42