# SoS! How to predict new values using linear regression models?

9 messages
Open this post in threaded view
|

## SoS! How to predict new values using linear regression models?

 Hi all, After trial and error by myself for a few hours, I decide to ask for your help. I have a training set which is a matrix of size 200 x 2, where the two columns denote each independent variable. I have 200 observations. ----------------- ss=data.frame(trainingSet); result=lm(trainingClass~ss\$X1+ss\$X2); ----------------- where trainingClass denotes the true classes of the training data. Now I want to apply the model to predict new data: ----------------- > gg=predict(result, data.frame(X1=1, X2=2)) Warning message: 'newdata' had 1 rows but variable(s) found have 200 rows ----------------- That's to say, I provide a new data which is one observation of 2 independent variables(1 row, two columns). I converted it into data frame. However, the R never gives me new predication value for this NEW ONE observation. Instead, it keeps giving me the above warning and keeps printing the fitted value for the 200 training samples... That's very bad. Please help me!         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|

## Re: SoS! How to predict new values using linear regression models?

Open this post in threaded view
|

## Re: SoS! How to predict new values using linear regression models?

Open this post in threaded view
|

## match() & seq()

 sorry if it has already been discussed but i can't understand this:  > seq(0.1,1,by=0.1)  [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0  > match(0.1,seq(0.1,1,by=0.1)) [1] 1  > match(0.2,seq(0.1,1,by=0.1)) [1] 2  > match(0.3,seq(0.1,1,by=0.1)) [1] NA  > match(0.4,seq(0.1,1,by=0.1)) [1] 4  > R.version          _             platform i386-pc-mingw32 arch     i386           os       mingw32       system   i386, mingw32 status                 major    2             minor    2.1           year     2005           month    12             day      20             svn rev  36812         language R ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|

## Re: match() & seq()

 Hope this is clear: > x <- seq(0.1, 1, by=0.1) > 0.3 == x[3] [1] FALSE > abs(0.3 - x[3]) [1] 5.551115e-17 Andy From: Jacques VESLOT > > sorry if it has already been discussed but i can't understand this: > >  > seq(0.1,1,by=0.1) >  [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 >  > match(0.1,seq(0.1,1,by=0.1)) > [1] 1 >  > match(0.2,seq(0.1,1,by=0.1)) > [1] 2 >  > match(0.3,seq(0.1,1,by=0.1)) > [1] NA >  > match(0.4,seq(0.1,1,by=0.1)) > [1] 4 > >  > R.version >          _             > platform i386-pc-mingw32 > arch     i386           > os       mingw32       > system   i386, mingw32 > status                 > major    2             > minor    2.1           > year     2005           > month    12             > day      20             > svn rev  36812         > language R > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html> > ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|

## Re: match() & seq()

 In reply to this post by Jacques VESLOT the problem is in 0.3 == seq(0.1,1,by=0.1)[3] versus all.equal(0.3, seq(0.1,1,by=0.1)[3]) look at ?Comparison for more info. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/     http://www.student.kuleuven.be/~m0390867/dimitris.htm----- Original Message ----- From: "Jacques VESLOT" <[hidden email]> To: <[hidden email]> Sent: Monday, January 30, 2006 3:19 PM Subject: [R] match() & seq() > sorry if it has already been discussed but i can't understand this: > > > seq(0.1,1,by=0.1) > [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 > > match(0.1,seq(0.1,1,by=0.1)) > [1] 1 > > match(0.2,seq(0.1,1,by=0.1)) > [1] 2 > > match(0.3,seq(0.1,1,by=0.1)) > [1] NA > > match(0.4,seq(0.1,1,by=0.1)) > [1] 4 > > > R.version >         _ > platform i386-pc-mingw32 > arch     i386 > os       mingw32 > system   i386, mingw32 > status > major    2 > minor    2.1 > year     2005 > month    12 > day      20 > svn rev  36812 > language R > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Open this post in threaded view
|

## Re: match() & seq()

 In reply to this post by Jacques VESLOT On Mon, 30 Jan 2006, Jacques VESLOT wrote: > sorry if it has already been discussed but i can't understand this: > >  > seq(0.1,1,by=0.1) >  [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 >  > match(0.1,seq(0.1,1,by=0.1)) > [1] 1 >  > match(0.2,seq(0.1,1,by=0.1)) > [1] 2 >  > match(0.3,seq(0.1,1,by=0.1)) > [1] NA >  > match(0.4,seq(0.1,1,by=0.1)) > [1] 4 FAQ 7.31 http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> print(seq(0.1,1,by=0.1), digits=20)  [1] 0.10000000000000000555 0.20000000000000001110 0.30000000000000004441  [4] 0.40000000000000002220 0.50000000000000000000 0.59999999999999997780  [7] 0.70000000000000006661 0.80000000000000004441 0.90000000000000002220 [10] 1.00000000000000000000 > match(c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9), seq(0.1,1,by=0.1)) [1]  1  2 NA  4  5  6 NA  8  9 > all.equal(c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0), seq(0.1,1,by=0.1), + tolerance = .Machine\$double.eps ^ 2) [1] "Mean relative  difference: 1.665335e-16" > all.equal(c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0), seq(0.1,1,by=0.1)) [1] TRUE > >  > R.version >          _             > platform i386-pc-mingw32 > arch     i386           > os       mingw32       > system   i386, mingw32 > status                 > major    2             > minor    2.1           > year     2005           > month    12             > day      20             > svn rev  36812         > language R > > ______________________________________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html> -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [hidden email] ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Roger Bivand Department of Economics NHH Norwegian School of Economics Helleveien 30 N-5045 Bergen, Norway