Hi, i 'dont understand how to take a general formula, view this: x<-1:5 y<-c(0,1,1.7,2,2.1.4) dummy<-data.frame(x=x,y=y) formula<-"y~A*log(x)/log(2)" formu<-as.formula(formula) fm<-lm(formu,data=dummy) Error in eval(expr, envir, enclos) : Object "A" not found but A is the parameter of fitting, why is this?Thanks Ruben
The '*' operator denotes factor crossing: 'a*b' interpreted as 'a+b+a:b' read ? formula. Best Vito Hi, i 'dont understand how to take a general formula, view this: x<-1:5 y<-c(0,1,1.7,2,2.1.4) dummy<-data.frame(x=x,y=y) formula<-"y~A*log(x)/log(2)" formu<-as.formula(formula) fm<-lm(formu,data=dummy) Error in eval(expr, envir, enclos) : Object "A" not found but A is the parameter of fitting, why is this?Thanks Ruben The '*' operator denotes factor crossing: 'a*b' interpreted as 'a+b+a:b' ====Diventare costruttori di soluzioni Visitate il portale http://www.modugno.it/ e in particolare la sezione su Palese http://www.modugno.it/archivio/cat_palese.shtml
If you want to fit "y = a + bx", then you use "lm(y ~ x)" instead of "lm(y ~ A + bx)". See the details section of help("formula").> x <- 1:5 > y <- c(0, 1.0, 1.7, 2.0, 2.1) > lm(x ~ y)Call: lm(formula = x ~ y) Coefficients: (Intercept) y 0.6828 1.7038 PS : I think there is a typo in y as there is no such number as 2.1.4 On Thu, 2004-07-15 at 16:28, solares at unsl.edu.ar wrote:> Hi, i 'dont understand how to take a general formula, view this: > > x<-1:5 > y<-c(0,1,1.7,2,2.1.4) > dummy<-data.frame(x=x,y=y) > formula<-"y~A*log(x)/log(2)" > formu<-as.formula(formula) > fm<-lm(formu,data=dummy) > Error in eval(expr, envir, enclos) : Object "A" not found > > but A is the parameter of fitting, why is this?Thanks Ruben > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
If you want to fit "y = a + bx", then you use "lm(y ~ x)" instead of "lm(y ~ A + bx)". See the details section of help("formula").> x <- 1:5 > y <- c(0, 1.0, 1.7, 2.0, 2.1) > lm(x ~ y)Call: lm(formula = x ~ y) Coefficients: (Intercept) y 0.6828 1.7038 If A was already defined, and you are trying to multiply the y-values, then use the I() operator. This protects the term/calculation and inhibits the usual term interpretation in linear models.> lm(x ~ I(2*y) )Call: lm(formula = x ~ I(2 * y)) Coefficients: (Intercept) I(2 * y) 0.6828 0.8519 PS : I think there is a typo in the y input as there is no such number as 2.1.4 On Thu, 2004-07-15 at 16:28, solares at unsl.edu.ar wrote:> Hi, i 'dont understand how to take a general formula, view this: > > x<-1:5 > y<-c(0,1,1.7,2,2.1.4) > dummy<-data.frame(x=x,y=y) > formula<-"y~A*log(x)/log(2)" > formu<-as.formula(formula) > fm<-lm(formu,data=dummy) > Error in eval(expr, envir, enclos) : Object "A" not found > > but A is the parameter of fitting, why is this?Thanks Ruben > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
On Thu, 2004-07-15 at 16:28, solares at unsl.edu.ar wrote:> Hi, i 'dont understand how to take a general formula, view this: > > x<-1:5 > y<-c(0,1,1.7,2,2.1.4) > dummy<-data.frame(x=x,y=y) > formula<-"y~A*log(x)/log(2)" > formu<-as.formula(formula) > fm<-lm(formu,data=dummy)You probably meant something similar to this:> lm(as.formula("y ~ log(x)"),dummy)Call: lm(formula = as.formula("y ~log(x)"), data = dummy) Coefficients: (Intercept) log(x) 0.0473 1.3793 And your "A" in this case would be 1.3793 Luis Torgo -- Luis Torgo FEP/LIACC, University of Porto Phone : (+351) 22 607 88 30 Machine Learning Group Fax : (+351) 22 600 36 54 R. Campo Alegre, 823 email : ltorgo at liacc.up.pt 4150 PORTO - PORTUGAL WWW : http://www.liacc.up.pt/~ltorgo
If you want to fit "y = a + bx", then you use "lm(y ~ x)" instead of "lm(y ~ A + bx)". 'A' is not a parameter but coefficient and you do not need to specify coefficients, which is what the linear model is trying to do anyway ! See the details section of help("formula").> x <- 1:5 > y <- c(0, 1.0, 1.7, 2.0, 2.1) > lm(x ~ y)Call: lm(formula = x ~ y) Coefficients: (Intercept) y 0.6828 1.7038 If A was already defined, and you are trying to multiply the y-values, then use the I() operator. This protects the term/calculation and inhibits the usual term interpretation in linear models.> lm(x ~ I(2*y) )Call: lm(formula = x ~ I(2 * y)) Coefficients: (Intercept) I(2 * y) 0.6828 0.8519 PS : I think there is a typo in the y input as there is no such number as 2.1.4 On Thu, 2004-07-15 at 16:28, solares at unsl.edu.ar wrote:> Hi, i 'dont understand how to take a general formula, view this: > > x<-1:5 > y<-c(0,1,1.7,2,2.1.4) > dummy<-data.frame(x=x,y=y) > formula<-"y~A*log(x)/log(2)" > formu<-as.formula(formula) > fm<-lm(formu,data=dummy) > Error in eval(expr, envir, enclos) : Object "A" not found > > but A is the parameter of fitting, why is this?Thanks Ruben > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >