Why do I get he error: argument is of length 0 for dffits?How can I get useful error messages in PHP?What's a good way to extend Error in JavaScript?Where does PHP store the error log? (php5, apache, fastcgi, cpanel)Why is `[` better than `subset`?How to find the length of a string in R400 BAD request HTTP error code meaning?“argument is of length zero” error in RandomForest tuneRF()R Function for Rounding Imputed Binary VariablesError in if (object$offset) { : argument is of length zero in relaxnet R packageError in if (pvals[minp] <= pent) { : argument is of length zero
What is the reason for cards stating "Until end of turn, you don't lose this mana as steps and phases end"?
Scam? Checks via Email
How long does it take for electricity to be considered OFF by general appliances?
Why was the LRV's speed gauge displaying metric units?
Why were contact sensors put on three of the Lunar Module's four legs? Did they ever bend and stick out sideways?
How should I quote American English speakers in a British English essay?
Does dual boot harm a laptop battery or reduce its life?
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Piece of chess engine, which accomplishes move generation
Should I accept an invitation to give a talk from someone who might review my proposal?
My employer is refusing to give me the pay that was advertised after an internal job move
Would people understand me speaking German all over Europe?
Is The Venice Syndrome documentary cover photo real?
Narset, Parter of Veils interaction with Aria of Flame
Can Papyrus be folded?
How can Paypal know my card is being used in another account?
Why would anyone ever invest in a cash-only etf?
How does a poisoned arrow combine with the spell Conjure Barrage?
Shouldn't there be "us" instead of "our" in this sentence?
How do I find the FamilyGUID of an exsting database
How to improve king safety
To find islands of 1 and 0 in matrix
How to efficiently shred a lot of cabbage?
What force enables us to walk? Friction or normal reaction?
Why do I get he error: argument is of length 0 for dffits?
How can I get useful error messages in PHP?What's a good way to extend Error in JavaScript?Where does PHP store the error log? (php5, apache, fastcgi, cpanel)Why is `[` better than `subset`?How to find the length of a string in R400 BAD request HTTP error code meaning?“argument is of length zero” error in RandomForest tuneRF()R Function for Rounding Imputed Binary VariablesError in if (object$offset) { : argument is of length zero in relaxnet R packageError in if (pvals[minp] <= pent) { : argument is of length zero
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a problem when I try to run the dffits() function for an object of my own logistic regression.
When I'm running dffits(log)
I get the error message:
error in if (model$rank == 0) { : Argument is of length 0
However, when I'm using the inbuilt gym function (family = binomial), then dffits(glm)
works just fine.
Here is my function for the logistic regression and a short example of my problem:
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank)
mydata$admit <- factor(mydata$admit)
logRegEst <- function(x, y, threshold = 1e-10, maxIter = 100)
calcPi <- function(x, beta)
beta <- as.vector(beta)
return(exp(x %*% beta) / (1 + exp(x %*% beta)))
beta <- rep(0, ncol(x)) # initial guess for beta
diff <- 1000
# initial value bigger than threshold so that we can enter our while loop
iterCount = 0
# counter to ensure we're not stuck in an infinite loop
while(diff > threshold) # tests for convergence
pi <- as.vector(calcPi(x, beta))
# calculate pi by using the current estimate of beta
W <- diag(pi * (1 - pi)) # calculate matrix of weights W
beta_change <- solve(t(x) %*% W %*% x) %*% t(x) %*% (y - pi)
# calculate the change in beta
beta <- beta + beta_change # new beta
diff <- sum(beta_change^2)
# calculate how much we changed beta by in this iteration
# if this is less than threshold, we'll break the while loop
iterCount <- iterCount + 1
# see if we've hit the maximum number of iterations
if(iterCount > maxIter)
stop("This isn't converging.")
# stop if we have hit the maximum number of iterations
df <- length(y) - ncol(x)
# calculating the degrees of freedom by taking the length of y minus
# the number of x columns
vcov <- solve(t(x) %*% W %*% x)
list(coefficients = beta, vcov = vcov, df = df)
# returning results
logReg <- function(formula, data)
mf <- model.frame(formula = formula, data = data)
# model.frame() returns us a data.frame with the variables needed to use the
# formula.
x <- model.matrix(attr(mf, "terms"), data = mf)
# model.matrix() creates a disign matrix. That means that for example the
#"Sex"-variable is given as a dummy variable with ones and zeros.
y <- as.numeric(model.response(mf)) - 1
# model.response gives us the response variable.
est <- logRegEst(x, y)
# Now we have the starting position to apply our function from above.
est$formula <- formula
est$call <- match.call()
est$data <- data
# We add the formular and the call to the list.
est$x <- x
est$y <- y
# We add x and y to the list.
class(est) <- "logReg"
# defining the class
est
log <- logReg(admit ~ gre + gpa, data= mydata)
glm <- glm(admit ~ gre + gpa, data= mydata, family = binomial)
dffits(glm)
dffits(log)
log$data
glm$data
I don't understand why mydata$rank == 0, because when I look at log$data
I see that the rank is just defined as in glm$data
.
I really appreciate your help!
r error-handling regression logistic-regression
add a comment |
I have a problem when I try to run the dffits() function for an object of my own logistic regression.
When I'm running dffits(log)
I get the error message:
error in if (model$rank == 0) { : Argument is of length 0
However, when I'm using the inbuilt gym function (family = binomial), then dffits(glm)
works just fine.
Here is my function for the logistic regression and a short example of my problem:
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank)
mydata$admit <- factor(mydata$admit)
logRegEst <- function(x, y, threshold = 1e-10, maxIter = 100)
calcPi <- function(x, beta)
beta <- as.vector(beta)
return(exp(x %*% beta) / (1 + exp(x %*% beta)))
beta <- rep(0, ncol(x)) # initial guess for beta
diff <- 1000
# initial value bigger than threshold so that we can enter our while loop
iterCount = 0
# counter to ensure we're not stuck in an infinite loop
while(diff > threshold) # tests for convergence
pi <- as.vector(calcPi(x, beta))
# calculate pi by using the current estimate of beta
W <- diag(pi * (1 - pi)) # calculate matrix of weights W
beta_change <- solve(t(x) %*% W %*% x) %*% t(x) %*% (y - pi)
# calculate the change in beta
beta <- beta + beta_change # new beta
diff <- sum(beta_change^2)
# calculate how much we changed beta by in this iteration
# if this is less than threshold, we'll break the while loop
iterCount <- iterCount + 1
# see if we've hit the maximum number of iterations
if(iterCount > maxIter)
stop("This isn't converging.")
# stop if we have hit the maximum number of iterations
df <- length(y) - ncol(x)
# calculating the degrees of freedom by taking the length of y minus
# the number of x columns
vcov <- solve(t(x) %*% W %*% x)
list(coefficients = beta, vcov = vcov, df = df)
# returning results
logReg <- function(formula, data)
mf <- model.frame(formula = formula, data = data)
# model.frame() returns us a data.frame with the variables needed to use the
# formula.
x <- model.matrix(attr(mf, "terms"), data = mf)
# model.matrix() creates a disign matrix. That means that for example the
#"Sex"-variable is given as a dummy variable with ones and zeros.
y <- as.numeric(model.response(mf)) - 1
# model.response gives us the response variable.
est <- logRegEst(x, y)
# Now we have the starting position to apply our function from above.
est$formula <- formula
est$call <- match.call()
est$data <- data
# We add the formular and the call to the list.
est$x <- x
est$y <- y
# We add x and y to the list.
class(est) <- "logReg"
# defining the class
est
log <- logReg(admit ~ gre + gpa, data= mydata)
glm <- glm(admit ~ gre + gpa, data= mydata, family = binomial)
dffits(glm)
dffits(log)
log$data
glm$data
I don't understand why mydata$rank == 0, because when I look at log$data
I see that the rank is just defined as in glm$data
.
I really appreciate your help!
r error-handling regression logistic-regression
1
rank
is not one of the names of the listlog
, solog$rank
will returnNULL
-- the conditionNULL == 0
returns a length 0 logical vector which is why that error is being thrown.
– DiceboyT
Mar 26 at 21:00
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
2
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20
add a comment |
I have a problem when I try to run the dffits() function for an object of my own logistic regression.
When I'm running dffits(log)
I get the error message:
error in if (model$rank == 0) { : Argument is of length 0
However, when I'm using the inbuilt gym function (family = binomial), then dffits(glm)
works just fine.
Here is my function for the logistic regression and a short example of my problem:
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank)
mydata$admit <- factor(mydata$admit)
logRegEst <- function(x, y, threshold = 1e-10, maxIter = 100)
calcPi <- function(x, beta)
beta <- as.vector(beta)
return(exp(x %*% beta) / (1 + exp(x %*% beta)))
beta <- rep(0, ncol(x)) # initial guess for beta
diff <- 1000
# initial value bigger than threshold so that we can enter our while loop
iterCount = 0
# counter to ensure we're not stuck in an infinite loop
while(diff > threshold) # tests for convergence
pi <- as.vector(calcPi(x, beta))
# calculate pi by using the current estimate of beta
W <- diag(pi * (1 - pi)) # calculate matrix of weights W
beta_change <- solve(t(x) %*% W %*% x) %*% t(x) %*% (y - pi)
# calculate the change in beta
beta <- beta + beta_change # new beta
diff <- sum(beta_change^2)
# calculate how much we changed beta by in this iteration
# if this is less than threshold, we'll break the while loop
iterCount <- iterCount + 1
# see if we've hit the maximum number of iterations
if(iterCount > maxIter)
stop("This isn't converging.")
# stop if we have hit the maximum number of iterations
df <- length(y) - ncol(x)
# calculating the degrees of freedom by taking the length of y minus
# the number of x columns
vcov <- solve(t(x) %*% W %*% x)
list(coefficients = beta, vcov = vcov, df = df)
# returning results
logReg <- function(formula, data)
mf <- model.frame(formula = formula, data = data)
# model.frame() returns us a data.frame with the variables needed to use the
# formula.
x <- model.matrix(attr(mf, "terms"), data = mf)
# model.matrix() creates a disign matrix. That means that for example the
#"Sex"-variable is given as a dummy variable with ones and zeros.
y <- as.numeric(model.response(mf)) - 1
# model.response gives us the response variable.
est <- logRegEst(x, y)
# Now we have the starting position to apply our function from above.
est$formula <- formula
est$call <- match.call()
est$data <- data
# We add the formular and the call to the list.
est$x <- x
est$y <- y
# We add x and y to the list.
class(est) <- "logReg"
# defining the class
est
log <- logReg(admit ~ gre + gpa, data= mydata)
glm <- glm(admit ~ gre + gpa, data= mydata, family = binomial)
dffits(glm)
dffits(log)
log$data
glm$data
I don't understand why mydata$rank == 0, because when I look at log$data
I see that the rank is just defined as in glm$data
.
I really appreciate your help!
r error-handling regression logistic-regression
I have a problem when I try to run the dffits() function for an object of my own logistic regression.
When I'm running dffits(log)
I get the error message:
error in if (model$rank == 0) { : Argument is of length 0
However, when I'm using the inbuilt gym function (family = binomial), then dffits(glm)
works just fine.
Here is my function for the logistic regression and a short example of my problem:
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank)
mydata$admit <- factor(mydata$admit)
logRegEst <- function(x, y, threshold = 1e-10, maxIter = 100)
calcPi <- function(x, beta)
beta <- as.vector(beta)
return(exp(x %*% beta) / (1 + exp(x %*% beta)))
beta <- rep(0, ncol(x)) # initial guess for beta
diff <- 1000
# initial value bigger than threshold so that we can enter our while loop
iterCount = 0
# counter to ensure we're not stuck in an infinite loop
while(diff > threshold) # tests for convergence
pi <- as.vector(calcPi(x, beta))
# calculate pi by using the current estimate of beta
W <- diag(pi * (1 - pi)) # calculate matrix of weights W
beta_change <- solve(t(x) %*% W %*% x) %*% t(x) %*% (y - pi)
# calculate the change in beta
beta <- beta + beta_change # new beta
diff <- sum(beta_change^2)
# calculate how much we changed beta by in this iteration
# if this is less than threshold, we'll break the while loop
iterCount <- iterCount + 1
# see if we've hit the maximum number of iterations
if(iterCount > maxIter)
stop("This isn't converging.")
# stop if we have hit the maximum number of iterations
df <- length(y) - ncol(x)
# calculating the degrees of freedom by taking the length of y minus
# the number of x columns
vcov <- solve(t(x) %*% W %*% x)
list(coefficients = beta, vcov = vcov, df = df)
# returning results
logReg <- function(formula, data)
mf <- model.frame(formula = formula, data = data)
# model.frame() returns us a data.frame with the variables needed to use the
# formula.
x <- model.matrix(attr(mf, "terms"), data = mf)
# model.matrix() creates a disign matrix. That means that for example the
#"Sex"-variable is given as a dummy variable with ones and zeros.
y <- as.numeric(model.response(mf)) - 1
# model.response gives us the response variable.
est <- logRegEst(x, y)
# Now we have the starting position to apply our function from above.
est$formula <- formula
est$call <- match.call()
est$data <- data
# We add the formular and the call to the list.
est$x <- x
est$y <- y
# We add x and y to the list.
class(est) <- "logReg"
# defining the class
est
log <- logReg(admit ~ gre + gpa, data= mydata)
glm <- glm(admit ~ gre + gpa, data= mydata, family = binomial)
dffits(glm)
dffits(log)
log$data
glm$data
I don't understand why mydata$rank == 0, because when I look at log$data
I see that the rank is just defined as in glm$data
.
I really appreciate your help!
r error-handling regression logistic-regression
r error-handling regression logistic-regression
edited Mar 26 at 20:51
Nicki
asked Mar 26 at 20:31
NickiNicki
357 bronze badges
357 bronze badges
1
rank
is not one of the names of the listlog
, solog$rank
will returnNULL
-- the conditionNULL == 0
returns a length 0 logical vector which is why that error is being thrown.
– DiceboyT
Mar 26 at 21:00
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
2
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20
add a comment |
1
rank
is not one of the names of the listlog
, solog$rank
will returnNULL
-- the conditionNULL == 0
returns a length 0 logical vector which is why that error is being thrown.
– DiceboyT
Mar 26 at 21:00
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
2
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20
1
1
rank
is not one of the names of the list log
, so log$rank
will return NULL
-- the condition NULL == 0
returns a length 0 logical vector which is why that error is being thrown.– DiceboyT
Mar 26 at 21:00
rank
is not one of the names of the list log
, so log$rank
will return NULL
-- the condition NULL == 0
returns a length 0 logical vector which is why that error is being thrown.– DiceboyT
Mar 26 at 21:00
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
2
2
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20
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%2f55365757%2fwhy-do-i-get-he-error-argument-is-of-length-0-for-dffits%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
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using 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%2f55365757%2fwhy-do-i-get-he-error-argument-is-of-length-0-for-dffits%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
rank
is not one of the names of the listlog
, solog$rank
will returnNULL
-- the conditionNULL == 0
returns a length 0 logical vector which is why that error is being thrown.– DiceboyT
Mar 26 at 21:00
Thanks for your answer @DiceboyT! Now I saw that the object glm contains something called rank. I already found out that rank is the numeric rank of the fitted linear model. But could you tell me what this is exactly? And how can I calculate it?
– Nicki
Mar 26 at 21:21
2
I believe it's just the number of regressors (including the intercept).
– DiceboyT
Mar 26 at 21:55
thanks, I could easily calculate the rank via ncol(x)!
– Nicki
Mar 26 at 23:20