search for: myformula

Displaying 20 results from an estimated 26 matches for "myformula".

2007 Jun 15
2
model.frame: how does one use it?
...rt, the issue has to do with how rpart evaluates a formula and supporting arguments, in particular 'weights'. A simple contrived example is ----------------------------------------------------------------------------- library(rpart) ## using data from help(rpart), set up simple example myformula <- formula(Kyphosis ~ Age + Number + Start) mydata <- kyphosis myweight <- abs(rnorm(nrow(mydata))) goodFunction <- function(mydata, myformula, myweight) { hyp <- rpart(myformula, data=mydata, weights=myweight, method="class") prev <- hyp } goodFunction(mydata, myfo...
2009 Oct 11
3
passing field name parameter to function
...meter name, it doesn't give me what I want, Y = df$mytarget Here is the function, # trying to pass field name to a function logistictest <- function(df,mytarget) { #library for AUC calculation library(caTools) #build logistic model mytarget <- deparse(substitute(mytarget)) myformula <- paste(mytarget," ~ .") myformula <- deparse(substitute(myformula)) logistic_reg <- glm(myformula , data=df, family=binomial(link="logit")) print("model build OK") #score up scores <- predict(logistic_reg, type="response", df) print(&quot...
2010 Jan 05
1
Is the Intercept Term always in First Position?
Dear All, I have a question about formulas and model.matrix(). If one specifies a model via a formula, the corresponding design matrix can be obtained with the model.matrix() function. For example: x1 <- c(1,4,2,3,5) x2 <- c(1,1,2,2,2) myformula <- ~ x1 + factor(x2) model.matrix(myformula) My question is: If an intercept term is in the model (like in the example above), is it always the first column in resulting design matrix? For example, if I add the intercept explicitly as the last term in the formula, it still ends up in the first...
2010 Jan 01
1
Questions bout SVM
Hi everyone, Can someone please help me in these questions?: 1)if I use crossvalidation with svm, do I have to use this equation to calculate RMSE?: mymodel <- svm(myformula,data=mydata,cross=10) sqrt(mean(mymodel$MSE)) But if I don’t use crossvalidation, I have to use the following to calculate RMSE: mymodel <- svm(myformula,data=mydata) mytest <- predict(mymodel, mytestdata) error <- mytest - mytestdata[,1] sqrt(...
2009 Oct 10
1
field names as function parameters
...d in parameter name, it doesn't give me what I want, Y = df$mytarget Here is the function, # trying to pass field name to a function logistictest <- function(df,mytarget) { #library for AUC calculation library(caTools) #build logistic model mytarget <- deparse(substitute(mytarget)) myformula <- paste(mytarget," ~ .") myformula <- deparse(substitute(myformula)) logistic_reg <- glm(myformula , data=df, family=binomial(link="logit")) print("model build OK") #score up scores <- predict(logistic_reg, type="response", df) print("mode...
2007 May 12
0
There might be something wrong with cv.lm(DAAG)
...hat we can't use it to deal with a linear model with more than one predictor variable. But the usage documentation hasn't informed us about this. You can find it by excuting the following code: xx=matrix(rnorm(20*3),ncol=3) bb=c(1,2,0) yy=xx%*%bb+rnorm(20,0,10) data=data.frame(y=yy,x=xx) myformula=formula("y ~ x.1 + x.2 + x.3") cv.lm(data,myformula,m=10,plotit=F, printit=TRUE) myformula=formula("y ~ x.1 + x.2") cv.lm(data,myformula,m=10,plotit=F, printit=TRUE) myformula=formula("y ~ x.1 ") cv.lm(data,myformula,m=10,plotit=F, printit=TRUE) What happened? they gi...
2011 Apr 18
2
as.formula doesn't want to take a phrase
Hello! I am trying to create a formula object using as.formula. But it's not working: examplephraze<-"for.my.example" myformula<-as.formula(paste(examplephraze,"~group, sum, data=mydata",sep="")) What's the problem? Thanks a lot! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com
2019 Jun 04
3
Incluir un rango de varias variables explicativas a un modelo
Hola, gracias por la respuesta, No me funcionó debido a que los nombres de las variables no están seriadas, es decir, los nombres de las variables son del tipo: x23 x25 x30, x301 x320, x80. Entonces me da este error: Error in eval(predvars, data, env) : object 'pot24' not found. Debido a que pot24 no existe, ya que de pot23 se brinca a pot30. En Stata es algo muy simple de hacer, solo
2007 May 21
0
Is this a bug in cv.lm(DAAG) ?
...h a linear model with more than one predictor variable. But the usage documentation hasn't informed us about this. The code illustrates my discovery: > library(DAAG) > xx=matrix(rnorm(20*3),ncol=3) > bb=c(1,2,0) > yy=xx%*%bb+rnorm(20,0,10) > > data=data.frame(y=yy,x=xx) > myformula=formula("y ~ x.1 + x.2 + x.3") > cv.lm(data,myformula,plotit=F, printit=TRUE) Analysis of Variance Table Response: yv Df Sum Sq Mean Sq F value Pr(>F) xv 1 37 37 0.29 0.6 Residuals 18 2288 127 fold 1 Observations in test set: 4 6 7 9 10 19...
2001 Aug 12
1
Creating a Model Matrix - keeping NAs
I am wanting to create a model matrix and keep the NAs. stratmat <- model.matrix(myformula,mydata) Is there any way to do this? model.matrix doesn't have na.action as a parameter. Elsewhere I have made use of na.keep <- function(x){x}. Many thanks, Rachel Cunliffe -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http...
2010 Mar 14
1
Error in object$tables[[v]] : subscript out of bounds
Hi, Could you please tell me how I correct the following error message? “Error in object$tables[[v]] : subscript out of bounds” This is the code: library(e1071) data(iris) attach(iris) class_label <- names(iris)[1] myformula <- formula(paste(class_label,"~ .")) mymodel<-naiveBayes(myformula, iris,cross=3) predict(mymodel,iris) ##Error in object$tables[[v]] : subscript out of bounds Cheers, Amy _________________________________________________________________ Link all your email acc...
1999 Apr 10
1
R/S compatibility in passing a formula
...you are passing an evaluated formula to another function that will store it and use it in printing (such as a model-fitting function), you usually want to unclass the formula. Otherwise, the formula that gets stored looks very ugly when printed. A trick to do the unclassing is to pass form = c( myFormula ) In R this has the effect of making form a list rather than a call. It seems that passing form = as.vector( myFormula ) will work in both dialects. Anyone else have experience with this? -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read...
2009 Dec 29
3
error logging
Yet another question... I'm wondering if there is a built in facility to log errors. I've got this statement that gives me verbose DBI errors as they come up (to standard output), but I'd like to trap and log them to a file as I running about 3000000 sql statements through this particular piece of code and I'd like to keep the loop going and deal with all the errors once the
2013 Oct 18
0
Logistic regression over LOOCV
Hello all. I have this code: myLOOCV <- function(myformula, data) { Y <- all.vars(myformula)[1] Scores<- numeric(length(data[,1])) for (i in 1:length(data[,1])) { train <- data[-i,] test <- data[i,] myModel <- lrm(myformula, train) Scores[i] <- predict(myModel, test,type="mean")...
2005 Jun 09
1
getting more than the coefficients
Hi there, I am trying to export a regression output to Latex. I am using the xtable function in the xtable library. Doing myfit <- lm(myformula, mydata) print.xtable(xtable(myfit), file="myfile") only returns the estimated coefficients and the correspondent standard erros, t-statiscs and p-values. But I wish to get a bit more, say, the number of observations used in the regresion, the R^2 and F statistics. Any suggestions? Th...
2007 Jun 05
1
Question using stepAIC
Hi - I use stepAIC to automatically select the model. The stepAIC was applied on polr as follow:objPolr <- polr(formula=myformula, data=dat, method=METHOD);objPolr.step <- stepAIC(objPolr, trace=T);Then R complaints that it doesn't know about 'dat' when it executes the second line. Below is the exact error that I got when executing the stepAIC line above:Error in eval(expr, envir, enclos) : object "dat&quo...
2009 Dec 27
1
svm regression/classification
...egression and code for using svm in classification? This is my code for regression, should I change it to do classification?: train <- read.table("trainingset.txt",sep=";") test <- read.table("testset.txt",sep=";") svmmodelfitness <- function(myformula,mydata,mytestdata) { mymodel <- svm(myformula,data=mydata) mytest <- predict(mymodel, mytestdata) error <- mytest - mytestdata[,1] -sqrt(mean(error**2)) } Many thanks, Nancy _______________________________________________________...
2011 Nov 22
1
help to setting a multiple (linear) regression model with a 5% significance level (threshold) for the inclusion of the model variables.
...ear Researchers, someone know the right syntax to chose a 5% significance level (threshold) for the inclusion of the model variables in a multiple (linear) regression in backward way? I set the formula in this way, but I don't know to choose the 5% significance? lmodelV <- step(lm(formula=MyFormula[[1]],data=LR.train),direction="backward") thanks in advance gianni [[alternative HTML version deleted]]
2017 Nov 26
0
withTimeout does not timeout nlme anymore
...quot;a3"),f.block=c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)) fpl.B.range <- function(lx,logbase,A,B,C,D) { A/(1+logbase^(-B*(lx-C)))+D } myFormula<-list(formula(A~id),formula(B~id),formula(C~id),formula(D~id)) INIT <- c(A.a1=1,A.a2<https://maps.google.com/?q=1,A.a2&entry=gmail&source=g>=0,A.a3=0,B=1,B.a2=0,B.a3=0,C=0,C.a2=0,C.a3=0,D=1,D.a2<https://maps.google.com/?q=1,D.a2&entry=gmail&source=g>=0,D.a3=0) try...
2010 May 21
3
vaiable in lm
Hi, if I know the colnames x and y in the following example, I can easily to do lm. tmp <- data.frame(x=c(1,1.2),y=c(1,2)) lm(y ~ x, data=tmp) when the colnames are variable, what should I do? for example colnames(tmp)[1] <- paste("aa",1,sep="_") lm(y ~ paste("aa",1,sep="_"), data = tmp) it gives me error. [[alternative HTML version