Error In Model.frame.default Invalid Type Closure For Variable
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might invalid 'type' (closure) of argument r have Meta Discuss the workings and policies of this site About
Aggregate Na.action In R
Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting r type closure ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million
Invalid Type (list) For Variable
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Aggregate error 'invalid type (closure) for variable 'paste' up vote 0 down vote favorite For this question @SimonO101 suggested aggregate solution in comments, as below: #dataframe df <- data.frame(id=c(101,102,102,103,104,104,104), calmonth=c('01','01','01','01','01','01','02'), product=c('apple','apple','htc','htc','apple','htc','nokia'), bb=sample(1:20,7)) #aggregate - SimonO101's solution: aggregate(product~id+calmonth, data=df, FUN=paste, collapse=" & ") #Error Error in model.frame.default(formula = ~product + paste, data = list(id = c(101, : invalid type (closure) for variable 'paste' Can't figure out the cause of this error? Version: Windows 7 Enterprise SP1, 64bit OS, "R version 3.0.1 (2013-05-16)", RStudio Update: Opened new RStudio session, no error, still would like to find out the cause. Update: dput: dput(df123) structure(list(id = c(101, 102, 102, 103, 104, 104, 104), calmonth = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("01", "02"), class = "factor"), product = structure(c(1L, 1L, 2L, 2L, 1L, 2L, 3L), .Label = c("apple", "htc", "nokia"), class = "factor"), bb = c(19L, 17L, 5L, 15L, 16L, 4L, 9L)), .Names = c("id", "calmonth", "product", "bb"), row.names = c(NA, -7L), class = "data.frame") Update: conflicts conflicts() [1] "dbCallProc" "dbClearResult" "dbColumnInfo" "dbCommit" [5] "dbConnect" "dbDataType" "dbDisconnect" "dbExistsTable" [9] "dbGetException" "dbGetInfo" "dbGetQuery" "dbGetRowCount" [13] "dbGetRowsAffected" "dbGetStatement" "dbHasCompleted" "dbListConnections" [17] "dbListFields" "dbListResults" "dbListTables" "dbReadTable" [21] "dbRemoveTable" "dbRollback" "dbSendQuery" "dbUnloadDriver" [25] "dbWriteTable" "fetch" "isSQLKeyword" "make.db.names
(Spring 2015) Mon 13 Apr 2015 – Mon 4 May 2015 (17 months ago) Dashboard ▼ Home Data Make a submission Information Description Evaluation Rules Timeline Forum Leaderboard Public Private Competition Forum All Forums » 15.071x - The Analytics Edge (Spring 2015) Why do I keep getting this Error? Start Watching « Prev Topic » Next Topic 0 votes whenever I impementpredict function on glm or rpartmodel I get this error Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : invalid type (closure) for variable 'open' http://stackoverflow.com/questions/20990888/aggregate-error-invalid-type-closure-for-variable-paste (IN GLM) Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = attr(object, : invalid type (closure) for variable 'open' (IN RPART) I dont understand what I am doing wrong. I have even removed the terms from train set which are absent in test set. #1 | Posted 18 months ago Permalink Abhishek Jaimini Posts 6 | https://www.kaggle.com/c/15-071x-the-analytics-edge-competition-spring-2015/forums/t/13381/why-do-i-keep-getting-this-error Votes 1 Joined 6 Apr '15 | Email User 0 votes newdata = ? #2 | Posted 18 months ago Permalink Data Wallah Competition 95th Posts 165 | Votes 105 Joined 13 Apr '14 | Email User 0 votes If you named one of your variables "open" then you have a name collision with the open function. Try a different name. #3 | Posted 18 months ago Permalink oconnoda Competition 71st Posts 235 | Votes 197 Joined 7 Apr '15 | Email User 0 votes I cannot get probabilities in test prediction train.log <- glm(Popular~.,data=train.dtm,family=binomial)
Warning message:
glm.fit: fitted probabilities numerically 0 or 1 occurred test.pred.log <- predict(train.log,newdata=test.dtm,type="response")
Warning message:
In predict.lm(object, newdata, se.fit, scale = 1, type = ifelse(type == :
prediction from a rank-deficient fit may be misleading head(test.pred.log)
character(0) character(0).1 character(0).2 character(0).3 character(0).4 character(0).5
1.901740e-09 1.128881e-02 9.210107e-01 7.480466e-01 3.862621e-01 4.591159e-01 #4 | Posted 18 months ago Permalink darkrai Posts 8 | Votes 3 Joined 7 Apr '15 | Email User Reply You must be logged in to reply to this topic. Log in » Flagging notifies Kaggle that this message is spam, inappropriate, abusive, or violates
Open this post in threaded view ♦ ♦ | http://r.789695.n4.nabble.com/Problem-passing-a-statistical-model-as-an-argument-td889459.html Report Content as Inappropriate ♦ ♦ Problem passing a statistical https://stat.ethz.ch/pipermail/r-help/2011-January/264808.html model as an argument Dear Colleagues: I would like to write a front end for a modeling function, but run into trouble when passing a weights argument. y <- 1:5 x <- c(1,3,2,5,4) w <- function(formula, ...) invalid type lm(formula, ...) lm(y ~ x, weights=c(1,1,1,2,2)) w(y ~ x) w(y ~ x, weights=c(1,1,1,2,2)) Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in w <- function(formula, weights, ...) lm(formula, weights=weights, ...) w(y ~ x, weights=c(1,1,1,2,2)) Error in model.frame.default(formula = formula, error in model.frame.default weights = weights, drop.unused.levels = TRUE) : invalid type (closure) for variable '(weights)' Is there a general approach that solves this? Thanks -Frank > sessionInfo() R version 2.9.0 (2009-04-17) x86_64-pc-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] survival_2.35-4 -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Frank Harrell Department of Biostatistics, Vanderbilt University Gabor Grothendieck Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: Problem passing a statistical model
weighted lm() Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] No one replied to this, so I'll try again, with a simple example. I calculate a set of log odds ratios, and turn them into a data frame as follows: > library(vcdExtra) > (lor.CM <- loddsratio(CoalMiners)) log odds ratios for Wheeze and Breathlessness by Age 25-29 30-34 35-39 40-44 45-49 50-54 55-59 60-64 3.695261 3.398339 3.140658 3.014687 2.782049 2.926395 2.440571 2.637954 > > (lor.CM.df <- as.data.frame(lor.CM)) Wheeze Breathlessness Age LOR ASE 1 W:NoW B:NoB 25-29 3.695261 0.16471778 2 W:NoW B:NoB 30-34 3.398339 0.07733658 3 W:NoW B:NoB 35-39 3.140658 0.03341311 4 W:NoW B:NoB 40-44 3.014687 0.02866111 5 W:NoW B:NoB 45-49 2.782049 0.01875164 6 W:NoW B:NoB 50-54 2.926395 0.01585918 7 W:NoW B:NoB 55-59 2.440571 0.01452057 8 W:NoW B:NoB 60-64 2.637954 0.02159903 Now I want to fit a linear model by WLS, LOR ~ Age, which can do directly as > lm(LOR ~ as.numeric(Age), weights=1/ASE, data=lor.CM.df) Call: lm(formula = LOR ~ as.numeric(Age), data = lor.CM.df, weights = 1/ASE) Coefficients: (Intercept) as.numeric(Age) 3.5850 -0.1376 But, I want to do the fitting in my own function, the simplest version is my.lm <- function(formula, data, subset, weights) { lm(formula, data, subset, weights) } But there is obviously some magic about formula objects and evaluation environments, because I don't understand why this doesn't work. > my.lm(LOR ~ as.numeric(Age), weights=1/ASE, data=lor.CM.df) Error in model.frame.default(formula = formula, data = data, subset = subset, : invalid type (closure) for variable '(weights)' > A second question: Age is a factor, and as.numeric(Age) gives me 1:8. What simple expression on lor.CM.df$Age would give me either the lower limits (here: seq(25, 60, by = 5)) or midpoints of these Age intervals (here: seq(27, 62, by = 5))? best, -Michael On 12/16/2010 9:43 AM, Michael Friendly wrote: > In the vcdExtra package on R-Forge, I have functions and generic methods > for calculating log odds ratios > for R x C x strata