[R] predict kernelmatrix
HI I got a problem in the predict function of the kernlab. I want to use ksvm and predict with kernelmatrix (S4 method for signature 'kernelMatrix') #executing the following sentences library(kernlab) # identity kernel k - function(x,y) { n-length(x) cont-0 for(i in 1:n){ if(x[i]==y[i]){ cont-cont+1 } } cont } class(k) - kernel data(promotergene) ind - sample(1:dim(promotergene)[1],20) genetrain - promotergene[-ind, -1] genetest - promotergene[ind,-1 ] kx - kernelMatrix(k, as.matrix(genetrain)) #y-as.vector(promotergene[-ind,1 ]) y-as.factor(promotergene[-ind,1 ]) y gene1 - ksvm(kx, y, type=C-svc) gene1 genetype - predict(gene1,genetest) Error en as.matrix(Z) : objeto Z no encontrado #genetest1-as.matrix(genetest) #genetype - predict(gene1,genetest1) genetype thank you, nelsonhernandez [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Predict using SparseM.slm
Hi, I am trying out the SparseM package and had the a question. The following piece of code works fine: ... fit = slm(model, data = trainData, weights = weight) ... But how do I use the fit object to predict the values on say a reserved testDataSet? In the regular lm function I would do something like this: predict.lm(fit,testDataSet) Thanks -Bala __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Predict using SparseM.slm
If you are feeling altruistic you could write a predict method for slm objects, it wouldn't be much work to adapt what is already available and follow the predict.lm prototype. On the other hand if you are looking for something quick and dirty you can always resort to newX %*% coef(slmobj) url:www.econ.uiuc.edu/~rogerRoger Koenker email[EMAIL PROTECTED]Department of Economics vox: 217-333-4558University of Illinois fax: 217-244-6678Champaign, IL 61820 On Aug 1, 2007, at 4:42 PM, T. Balachander wrote: Hi, I am trying out the SparseM package and had the a question. The following piece of code works fine: ... fit = slm(model, data = trainData, weights = weight) ... But how do I use the fit object to predict the values on say a reserved testDataSet? In the regular lm function I would do something like this: predict.lm(fit,testDataSet) Thanks -Bala __ __ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Predict(); Warning rank deficient matrix
I am trying to use lm() for resression followed by stepAIC function. Now when i try to use to predict for some input, predict() gives a warning : prediction from a Rank deficient matrix may be misleading. As I am new to R (or to statistics) How alarming this warning may be? Regards, The fish are biting. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict on biglm class
Hi Everyone, I often use the 'safe prediction' feature available through glm(). Now, I'm at a situation where I must use biglm:::bigglm. ## begin example library(splines) library(biglm) ff - log(Volume)~ns(log(Girth), df=5) fit.glm - glm(ff, data=trees) fit.biglm - bigglm(ff, data=trees) predict(fit.glm, newdata=data.frame(Girth=2:5)) ## -1.3161465 -0.2975659 0.4251285 0.9856938 predict(fit.biglm, newdata=data.frame(Girth=2:5)) ## Error in predict(fit.biglm, newdata = data.frame(Girth = 2:5)) : ##no applicable method for predict ## end example So, it is my understanding that there is no 'predict' method for 'bigglm' class. That suggests me that I need to create my own prediction method, right? What would be an efficient way of making these predictions that use ns() on a very large dataset? My initial thought is that saving the Boundary.knots and knots, I could create the linear predictor by chunks (and therefore get the predictions). Is there a better way of doing this? Thank you very much. Benilton Carvalho Department of Biostatistics Bloomberg School of Public Health Johns Hopkins University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict and arima
Part of the fit is the Kalman filter state after running the model forwards. Try reversing your series, fitting and then forecasting. You might have more success in understanding arima0. On Sat, 25 Nov 2006, Franck Arnaud wrote: Hi all, Forecasting from an arima model is easy with predict. But I can't manage to backcast : invent data from the model before the begining of the sample. The theory is easy : take your parameters, reverse your data, forecast, and then reverse the forecast I've tried to adapt the predict function to do that (i'm not sure that the statistical procedure is fine (with the residuals), but that's not my point right now) : mav.backcast.arima-function(model,n.backcast,...) { if (class(model)[1]!=Arima) stop(argument model must be an object of class 'Arima' (see ?arima)) model2-model model$residuals-rev(model$residuals) if (is.ts(model2$residuals)) model$residuals-ts(model$residuals,start=start(model2$residuals), frequency=frequency(model2$residuals)) pred.before-predict(model,n.ahead=n.backcast,...) freq-frequency(model$residuals) startingdate-per.sub(start(model2$residuals),n.backcast,freq=freq) pred-ts(rev(pred.before$pred),start=startingdate,freq=freq) se-ts(rev(pred.before$se),start=startingdate,freq=freq) return((list(pred = pred, se =se))) } This function does not work : it gives always the same result, it does not depend on the residuals (i've tried to insert a model$residuals-rep(1,100) after the definition, to check that). Then i look at the code, with getS3method(predict,Arima). And i get even more confused (!) : where does data play a role in the function ? residuals are loaded into rsd, but this variable is not used after... I looked at KalmanForecast and at the C code of KalmanFore, but it did not help me understand what was going on. thanks Franck A. btw, it has nothing to do with it, but i've done some stuff on time series (filtering with Hodrick prescott or Baxter King, for instance) that you can find on http://arnaud.ensae.net [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict and arima
Hi all, Forecasting from an arima model is easy with predict. But I can't manage to backcast : invent data from the model before the begining of the sample. The theory is easy : take your parameters, reverse your data, forecast, and then reverse the forecast I've tried to adapt the predict function to do that (i'm not sure that the statistical procedure is fine (with the residuals), but that's not my point right now) : mav.backcast.arima-function(model,n.backcast,...) { if (class(model)[1]!=Arima) stop(argument model must be an object of class 'Arima' (see ?arima)) model2-model model$residuals-rev(model$residuals) if (is.ts(model2$residuals)) model$residuals-ts(model$residuals,start=start(model2$residuals), frequency=frequency(model2$residuals)) pred.before-predict(model,n.ahead=n.backcast,...) freq-frequency(model$residuals) startingdate-per.sub(start(model2$residuals),n.backcast,freq=freq) pred-ts(rev(pred.before$pred),start=startingdate,freq=freq) se-ts(rev(pred.before$se),start=startingdate,freq=freq) return((list(pred = pred, se =se))) } This function does not work : it gives always the same result, it does not depend on the residuals (i've tried to insert a model$residuals-rep(1,100) after the definition, to check that). Then i look at the code, with getS3method(predict,Arima). And i get even more confused (!) : where does data play a role in the function ? residuals are loaded into rsd, but this variable is not used after... I looked at KalmanForecast and at the C code of KalmanFore, but it did not help me understand what was going on. thanks Franck A. btw, it has nothing to do with it, but i've done some stuff on time series (filtering with Hodrick prescott or Baxter King, for instance) that you can find on http://arnaud.ensae.net [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict with logistic regression
Jan Sabee jan.sabee at gmail.com writes: I know that is probability of predict for new dataset. My question is how can I know each probability according to class (sore). I mean that I need the result of predit something like (M=1, F=0): 1 2 3 4 5 6 7 8 9 10 1 0 0 0 1 0 1 1 0 1 As I understand your question: you have the probability, and you can use these to decide whether you think it is high enough for you to think whether it is M=1 or F=0. Anupam. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] predict with logistic regression
I am learning about using logistic regression with glm. Suppose I have dataset: duration - c(45,15,40,83,90,25,35,65,95,35,75,45,50,75,30,25,20,60,70,30,60,61,65,15,20,45,15,25,15,30,40,15,135,20,40) type - c(0,0,0,1,1,1,rep(0,5),1,1,1,0,0,1,1,1,rep(0,4),1,1,0,1,0,1,0,0,rep(1,4)) sore - factor(rep(c(M, F), c(16, 19))) sore.fr - data.frame(duration, type, sore) str(sore.fr) then with glm I have the result. sorethroat.lg - glm(sore ~ type+duration, family=binomial, data=sore.fr) summary(sorethroat.lg, cor=TRUE) If I have a new dataset then predict it, the result: new.sore - data.frame(duration=c(35,25,41,33,30,55,35,62,93,34), type=c(0,1,0,1,0,1,1,1,0,1)) predict(sorethroat.lg, new.sore, type=response) predict(sorethroat.lg, new.sore, type=response) 123456 0.5176877150 0.2750893421 0.5407418590 0.3003664211 0.4984140283 0.3760831903 789 10 0.3068890332 0.4017370393 0.7242061280 0.3036178483 I know that is probability of predict for new dataset. My question is how can I know each probability according to class (sore). I mean that I need the result of predit something like (M=1, F=0): 1 2 3 4 5 6 7 8 9 10 1 0 0 0 1 0 1 1 0 1 Sincerelly, JS __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Predict with loess
I want to do a nonparametric regression. Im using the function loess. The variable are the year from 1968 to 1977 and the dependant variable is a proportion P. The dependant variable have missing value (NA). The script is : year - 1969:2002 length(year) [1] 34 P - c(NA,0.1,0.56,NA,NA,0.5,0.4,0.75,0.9, 0.98,0.2,0.56,0.7,0.89,0.3,0.1,0.45,0.46,0.49,0.78, 0.25,0.79,0.23,0.26,0.46,0.12,0.56,0.8,0.55,0.41, 0.36,0.9,0.22,0.1) length(P) [1] 34 lo1 - loess(P~year,span=0.3,degree=1) summary(lo1) yearCo - 1969:2002 year_lo - data.frame(year = yearCo ) length(year_lo) [1] 34 mlo - predict(loess(P~year,span=0.3,degree=1),new.data=year_lo,se=T) mlo$fit mlo$se.fit plot(year,P,type='o') lines(year,predict(loess(P~year,span=0.15,degree=1),new.data=year_lo, se=T,na.action=na.omit)$fit,col='blue',type='l') The message error indicates that x and y dont have the same length. In fact in m$fit and m$se.fit there are 3 values who dont have a fitted value. There is no predicted value when the dependant variable have a NA. The synthase na.action=na.omit dont seem to ignore the missing value, generating an error. What is the source, the solution to my problem? Thanks for the help CélineI want to do a nonparametric regression. Im using the function loess. The variable are the year from 1968 to 1977 and the dependant variable is a proportion P. The dependant variable have missing value (NA). The script is : year - 1969:2002 length(year) [1] 34 P - c(NA,0.1,0.56,NA,NA,0.5,0.4,0.75,0.9, 0.98,0.2,0.56,0.7,0.89,0.3,0.1,0.45,0.46,0.49,0.78, 0.25,0.79,0.23,0.26,0.46,0.12,0.56,0.8,0.55,0.41, 0.36,0.9,0.22,0.1) length(P) [1] 34 lo1 - loess(P~year,span=0.3,degree=1) summary(lo1) yearCo - 1969:2002 year_lo - data.frame(year = yearCo ) length(year_lo) [1] 34 mlo - predict(loess(P~year,span=0.3,degree=1),new.data=year_lo,se=T) mlo$fit mlo$se.fit plot(year,P,type='o') lines(year,predict(loess(P~year,span=0.15,degree=1),new.data=year_lo, se=T,na.action=na.omit)$fit,col='blue',type='l') The message error indicates that x and y dont have the same length. In fact in m$fit and m$se.fit there are 3 values who dont have a fitted value. There is no predicted value when the dependant variable have a NA. The synthase na.action=na.omit dont seem to ignore the missing value, generating an error. What is the source, the solution to my problem? Thanks for the help Céline __ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Predict with loess
On Tue, 13 Jun 2006, Jouanin Celine wrote: I want to do a nonparametric regression. Im using the function loess. The variable are the year from 1968 to 1977 and the dependant variable is a proportion P. The dependant variable have missing value (NA). The script is : year - 1969:2002 length(year) [1] 34 P - c(NA,0.1,0.56,NA,NA,0.5,0.4,0.75,0.9, 0.98,0.2,0.56,0.7,0.89,0.3,0.1,0.45,0.46,0.49,0.78, 0.25,0.79,0.23,0.26,0.46,0.12,0.56,0.8,0.55,0.41, 0.36,0.9,0.22,0.1) length(P) [1] 34 lo1 - loess(P~year,span=0.3,degree=1) summary(lo1) yearCo - 1969:2002 year_lo - data.frame(year = yearCo ) length(year_lo) [1] 34 I get 1 here, and so should you. mlo - predict(loess(P~year,span=0.3,degree=1),new.data=year_lo,se=T) It should be newdata, not new.data mlo$fit mlo$se.fit Notice that these are of length 31, not 34 You are trying to predict at the values used for fitting (possibly not what you intended), so you don't actually need this. Try lo1 - loess(P~year,span=0.3,degree=1, na.action=na.exclude) fitted(lo1) plot(year,P,type='o') lines(year, fitted(lo1)) Or if you want to try interpolation lines(year, predict(lo1, newdata=year_lo)) This will not extrapolate to 1969, and as far as I recall the version of loess in R does not allow extrapolation. plot(year,P,type='o') lines(year,predict(loess(P~year,span=0.15,degree=1),new.data=year_lo, se=T,na.action=na.omit)$fit,col='blue',type='l') The message error indicates that x and y dont have the same length. In fact in m$fit and m$se.fit there are 3 values who dont have a fitted value. Correct, and that's because you used na.action=na.omit and did not specify newdata. [...] -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict function does not provide SE estimates for multivariate timeseries VAR models?
The dse2 package contains functions forecast and forecastCov. Have you tried them? There may be functions to estimate vector autoregressive models in more than one package in R. If you'd like more help from this listserve, I would encourage you to submit another post after first reading the posting guide! www.R-project.org/posting-guide.html. Please include a simple, self-contained example of something you've tried that was as close as you can find to what you want. I know this doesn't answer your question, but I hope it helps. Spencer Graves Berwin A Turlach wrote: Michael == Michael [EMAIL PROTECTED] writes: Michael What can I do? Implement this feature and send it to the person responsible for the code for inclusion? Michael Thanks a lot! Indeed, you contribution would be very much appreciated. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Mathematics and Statistics+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: [EMAIL PROTECTED] Australiahttp://www.maths.uwa.edu.au/~berwin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict function does not provide SE estimates for multivariate timeseries VAR models?
What can I do? Thanks a lot! [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict function does not provide SE estimates for multivariate timeseries VAR models?
Michael == Michael [EMAIL PROTECTED] writes: Michael What can I do? Implement this feature and send it to the person responsible for the code for inclusion? Michael Thanks a lot! Indeed, you contribution would be very much appreciated. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Mathematics and Statistics+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: [EMAIL PROTECTED] Australiahttp://www.maths.uwa.edu.au/~berwin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Predict nls new data with se.fit snf intervals
Using R to predict.nls() using new data, `se.fit' and `interval' are ignored. . Is there any update for this? Anybody has those routine or may advise me how to do that? Thanks [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Predict function for 'newdata' of different dimension in svm
Sandra, hard to tell where the error message originates from without having the data at hand (perhaps you could provide that to me off-list?), but I am almost sure things will work when you train the model the standard way: cd1.svm-svm(Acode~EXT+TOF, data = boot.dist.dat, cost=100, gamma=20) and then do the predictions. Best, David - I am using the predict function on a support vector machine (svm) object, and I don't understand why I can't predict on a dataset with more observations than the training dataset. I think this problem is a generic predict problem, but I'm not sure. The original svm was fit on 50 observations. cd1.svm-svm(boot.dist.dat$Acode~boot.dist.dat$EXT+boot.dist.dat $TOF,cost=100,gamma=20) ## for these training data, names(boot.dist.dat) [1] TOF EXT Acode dim(boot.dist.dat) [1] 50 3 Now I want to use the svm classifier on a new dataset with 175 observations: new.dat-data.frame(TOF=Cd1[cand.adult,]$TOF,EXT=Cd1[cand.adult,] $EXT,Acode=rep(0,175),row.names=NULL) ## for the new dataset, names(new.dat) [1] TOF EXT Acode dim(new.dat) [1] 175 3 Now try to predict: predict(cd1.svm,newdata=new.dat) Error in names-.default(`*tmp*`, value = c(1, 2, 3, 4, 5, : 'names' attribute [175] must be the same length as the vector [50] What am I missing? Why would the row names have to be the same? Thanks so much, Sandra McBride -- Dr. David Meyer Department of Information Systems and Operations Vienna University of Economics and Business Administration Augasse 2-6, A-1090 Wien, Austria, Europe Tel: +43-1-313 36 4393 Fax: +43-1-313 36 90 4393 HP: http://wi.wu-wien.ac.at/~meyer/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Predict function for 'newdata' of different dimension in svm
I am using the predict function on a support vector machine (svm) object, and I don't understand why I can't predict on a dataset with more observations than the training dataset. I think this problem is a generic predict problem, but I'm not sure. The original svm was fit on 50 observations. cd1.svm-svm(boot.dist.dat$Acode~boot.dist.dat$EXT+boot.dist.dat$TOF,cost=100,gamma=20) ## for these training data, names(boot.dist.dat) [1] TOF EXT Acode dim(boot.dist.dat) [1] 50 3 Now I want to use the svm classifier on a new dataset with 175 observations: new.dat-data.frame(TOF=Cd1[cand.adult,]$TOF,EXT=Cd1[cand.adult,]$EXT,Acode=rep(0,175),row.names=NULL) ## for the new dataset, names(new.dat) [1] TOF EXT Acode dim(new.dat) [1] 175 3 Now try to predict: predict(cd1.svm,newdata=new.dat) Error in names-.default(`*tmp*`, value = c(1, 2, 3, 4, 5, : 'names' attribute [175] must be the same length as the vector [50] What am I missing? Why would the row names have to be the same? Thanks so much, Sandra McBride ~~ Sandra McBride Research Scientist Nicholas School of the Environment and Earth Sciences (NSEES) Box 90328 Duke University Levine Science Research Center Durham, NC 27708-0328 (919) 622 3663 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict nbinomial glm
Dear R-helpers, let us assume, that I have the following dataset: a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) In a first step I run a glm.nb (full code is given at the end of this mail) and want to predict my response variable a. In a second step, I would like to run a glm.nb based on a subset of the data_frame. As soon as I want to predict the response variable a, I get the following error message: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor d has new level(s) q Does anybody have a solution to this problem? Thank you in advance, K. Steinmann (working with R 2.0.0) Code: library(MASS) a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) model_1 = glm.nb(a ~ b + d , data = data_frame) pred_model_1 = predict(model_1, newdata = data_frame, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) subset_of_dataframe = subset(data_frame, (b 80 c 190 )) model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict nbinomial glm
This is seems to be an unstated repeat of much of an earlier and unanswered post https://stat.ethz.ch/pipermail/r-help/2005-August/075914.html entitled [R] error in predict glm (new levels cause problems) It is nothing to do with `nbinomial glm' (sic): all model fitting functions including lm and glm do this. The reason you did not get at least one reply from your first post is that you seemed not to have done your homework. (One thing the posting guide does ask is for you to try the current version of R, and yours is three versions old.) The code is protecting you from an attempt at statistical nonsense. (Indeed, the check was added to catch such misuses.) Your email address seems to be that of a student, so please seek the help of your advisor. You seem surprised that you are not allowed to make predictions about levels for which you have supplied no relevant data. On Tue, 16 Aug 2005, K. Steinmann wrote: Dear R-helpers, let us assume, that I have the following dataset: a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) In a first step I run a glm.nb (full code is given at the end of this mail) and want to predict my response variable a. In a second step, I would like to run a glm.nb based on a subset of the data_frame. As soon as I want to predict the response variable a, I get the following error message: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor d has new level(s) q Does anybody have a solution to this problem? Thank you in advance, K. Steinmann (working with R 2.0.0) Code: library(MASS) a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) model_1 = glm.nb(a ~ b + d , data = data_frame) pred_model_1 = predict(model_1, newdata = data_frame, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) subset_of_dataframe = subset(data_frame, (b 80 c 190 )) model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict nbinomial glm
Katharina, I agree with Prof. Ripley's assessment. But, perhaps one thing you may have overlooked is that subset.data.frame does not remove unused levels. So, subset_of_dataframe = subset(data_frame, (b 80 c 190)) levels(subset_of_dataframe$d) [1] q r s t table(subset_of_dataframe$d) q r s t 0 20 50 10 Even though the level q does not appear it is still a level of d. Perhaps you need to do the following after the subset: subset_of_dataframe[] - lapply(subset_of_dataframe, [, drop = TRUE) which drops all unused levels from factors. I'm not sure if your problem is statistical in nature or simply a misunderstanding of the software. I'm only attempting to answer the latter. As Prof. Ripley suggests, discuss any statistical problem (i.e. predicting on missing levels) with your advisor. HTH, --sundar P.S. Also, update R. It's free. Prof Brian Ripley wrote: This is seems to be an unstated repeat of much of an earlier and unanswered post https://stat.ethz.ch/pipermail/r-help/2005-August/075914.html entitled [R] error in predict glm (new levels cause problems) It is nothing to do with `nbinomial glm' (sic): all model fitting functions including lm and glm do this. The reason you did not get at least one reply from your first post is that you seemed not to have done your homework. (One thing the posting guide does ask is for you to try the current version of R, and yours is three versions old.) The code is protecting you from an attempt at statistical nonsense. (Indeed, the check was added to catch such misuses.) Your email address seems to be that of a student, so please seek the help of your advisor. You seem surprised that you are not allowed to make predictions about levels for which you have supplied no relevant data. On Tue, 16 Aug 2005, K. Steinmann wrote: Dear R-helpers, let us assume, that I have the following dataset: a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) In a first step I run a glm.nb (full code is given at the end of this mail) and want to predict my response variable a. In a second step, I would like to run a glm.nb based on a subset of the data_frame. As soon as I want to predict the response variable a, I get the following error message: Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor d has new level(s) q Does anybody have a solution to this problem? Thank you in advance, K. Steinmann (working with R 2.0.0) Code: library(MASS) a - rnbinom(200, 1, 0.5) b - (1:200) c - (30:229) d - rep(c(q, r, s, t), rep(50,4)) data_frame - data.frame(a,b,c,d) model_1 = glm.nb(a ~ b + d , data = data_frame) pred_model_1 = predict(model_1, newdata = data_frame, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) subset_of_dataframe = subset(data_frame, (b 80 c 190 )) model_2 = glm.nb(a ~ b + d , data = subset_of_dataframe) pred_model_2 = predict(model_2, newdata = subset_of_dataframe, type = response, se.fit = FALSE, dispersion = NULL, terms = NULL) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Predict
When I callculate a linear model, then I can compute via confint the confidencial intervals. the interval level can be chosen. as result, I get the parameter of the model according to the interval level. On the other hand, I can compute the prediction-values for my model as well with predict(object, type=c(response) etc.). Here I have also the possibility to chose a level for the confidential intervals. the output are the calculatet values for the fit, the lower and upper level. the problem now is, that when I calculate the values through the linear model function with the parameter values I get from confint() an I compare them with the values I get from predict() these values differ extremely. Why is that so? Does the command predict() calculate the values through an other routine? That means the command predict() doesn't use the same parameters to calculate the prediction-values than the ones given by confint()? Greetings Matthias -- GMX DSL = Maximale Leistung zum minimalen Preis! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Predict
Dear Matthias Can you provide an example to demonstrate what you did? Two remarks to your email. Maybe that answers already your question. 1) Using predict() you will get the estimated value for each observation or for new data. You can reproduce this value by using the coefficients from your estimated model (see the example below). For the interval you can get a confidence interval for the expected value under fixed conditions of the explanatory variables or you can obtain a prediction interval for a single new observation. The latter is of course wider, since you try to catch a single observation and not the expected value. 2) Using confint() you will get the estimated parameters (which are random variables, too) and their confidence interval. You can use the estimated values to calculate the predicted values. But you can NOT use the upper values from confint to estimate the upper values from predict by just putting them into your regression model. Thats not the way how confidence intervals are constructed. (I am not sure if this was your intention. Maybe if you show a reproducible example you can correct me if you meant something different) ## R Code ## Creation of a dataframe set.seed(1) x1 - runif(40) f1 - rep(c(a, b, c,d), each = 10) y - 2*x1 + rep(c(0.5, 0.1, -0.6, 1.5), each = 10) + rnorm(40, 0, 2) dat - data.frame(y = y, f1 = f1, x1 = x1) ## regression model reg - lm(y~ x1 + f1, data = dat) summary(reg) confint(reg) predict(reg, type=c(response), interval = confidence) ## caluclation of predicted values using the estimated ## coefficients ## estimated coefficients co - summary(reg)$coefficients[,Estimate] ## Using the regression model with that coefficients ## for observation 11 co[(Intercept)] + dat[11,x1]*co[x1] + co[f1b] ## prediction of observation 11 predict(reg, type=c(response))[11] Regards, Christoph -- Christoph Buser [EMAIL PROTECTED] Seminar fuer Statistik, LEO C13 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-44-632-4673 fax: 632-1228 http://stat.ethz.ch/~buser/ -- Matthias Eggenberger writes: When I callculate a linear model, then I can compute via confint the confidencial intervals. the interval level can be chosen. as result, I get the parameter of the model according to the interval level. On the other hand, I can compute the prediction-values for my model as well with predict(object, type=c(response) etc.). Here I have also the possibility to chose a level for the confidential intervals. the output are the calculatet values for the fit, the lower and upper level. the problem now is, that when I calculate the values through the linear model function with the parameter values I get from confint() an I compare them with the values I get from predict() these values differ extremely. Why is that so? Does the command predict() calculate the values through an other routine? That means the command predict() doesn't use the same parameters to calculate the prediction-values than the ones given by confint()? Greetings Matthias -- GMX DSL = Maximale Leistung zum minimalen Preis! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict function for GLMM
I use predict for predictions from glm. I am wondering if there is a predict function for predictions from the results of GLMM model? Thanks ahead! Weihong Li Undergraduate Student in Statistics University of Alberta __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict() question
Hi, there: Following yesterday's question ( i had a new level for a categorical variable occurred in validation dataset and predict() complains about it: i made some python code to solve the problem), but here, I am just curious about some details about the mechanism: I believed rpart follows CART and for a categorical variable, the splitting criteria should be like, is it A or not? --yes, go to left branch --no, go to right So, when you predict, if you have a new level C,for example, the predict() should not complain about the occurrence of C (of course, if there are many C's in validation, it should complain). Maybe for robustness, predict() has to check first if there is new level or not. I am not sure if my understanding is right or not, please be advised! Thanks, -- Weiwei Shi, Ph.D Did you always know? No, I did not. But I believed... ---Matrix III __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict problem
Hi, there: I have a question on predict() function. I built a set of trees using rpart and when I do prediction, I got the following error: Error in model.frame.default(Terms, newdata, na.action = act, xlev = attr(object , : factor V19 has new level(s) 45 Execution halted I think the problem is caused by a new level (which is not used in building trees) for V19. I am wondering if there is an argument in predict() which can help suppress this error by just ignoring this special observation in validation sample. If not, I can do some pre-treatment to remove the obs with new level out for the time being. Thanks, -- Weiwei Shi, Ph.D Did you always know? No, I did not. But I believed... ---Matrix III __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict nlme syntax
Dear all Please help me with correct syntax of predict.nlme. I would like to predict from nlme object for new data. I used predict(fit.nlme6, data=newdata) but I have always got fitted values, no matter how I changed newdata. I have summary(fit.nlme6) Nonlinear mixed-effects model fit by maximum likelihood Model: konverze ~ SSfpl(tepl, A, B, xmid, scal) Data: limity.gr AIC BIClogLik 882.4939 907.6738 -433.2469 Random effects: Formula: list(xmid ~ 1, scal ~ 1) Level: spol.f Structure: General positive-definite, Log-Cholesky parametrization StdDevCorr xmid 29.680114 xmid scal 6.481679 0.249 Residual 2.168191 Fixed effects: list(A ~ 1, B ~ 1, xmid ~ 1, scal ~ 1) Value Std.Error DF t-value p-value A 36.1450 0.837050 154 43.18133 0 B101.0272 0.432074 154 233.81898 0 xmid 735.3860 8.150964 154 90.22074 0 scal 15.4453 2.201864 154 7.01466 0 Correlation: A B xmid B-0.088 xmid 0.057 -0.088 scal -0.089 0.469 0.036 Standardized Within-Group Residuals: MinQ1 MedQ3 Max -3.7707629568 -0.3291628536 0.0005885683 0.4020944158 3.7911729382 Number of Observations: 172 Number of Groups: 15 where **tepl** is independent variable and **spol.f** is grouping factor. The newly constructed data frame newdata has the same structure of spol.f levels as has the limity.gr data frame used for fitting. levels(limity.gr$spol.f) [1] 1.8/3 4/3 6.3/3 10.8/3 1.8/7 1.8/12 1.8/30 6.3/30 10.8/30 1.8/60 4/606.3/60 1.8/110 [14] 1.8/200 1.8/300 levels(newdata$spol.f) [1] 1.8/3 4/3 6.3/3 10.8/3 1.8/7 1.8/12 1.8/30 6.3/30 10.8/30 1.8/60 4/606.3/60 1.8/110 [14] 1.8/200 1.8/300 The only difference is in temperature. Please advice how shall I change newdata to be able to use it in predict function. Thank you. Best regards Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict nlme syntax
Petr Pikal wrote: Dear all Please help me with correct syntax of predict.nlme. I would like to predict from nlme object for new data. I used predict(fit.nlme6, data=newdata) but I have always got fitted values, no matter how I changed newdata. I have The argument's name is newdata, not data. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict(arima)
Dear All, R 1.9.1, Windows When copying and pasting a few lines from the 'predict.Arima' help, I get an error message: data(lh) predict(arima(lh, order = c(3,0,0)), n.ahead = 12) Error in eval(expr, envir, enclos) : Object xreg not found On the other hand, the following is OK: data(lh) predict(arima0(lh, order = c(3,0,0)), n.ahead = 12) $pred Time Series: Start = 49 End = 60 Frequency = 1 [1] 2.460173 2.270829 2.198597 2.260696 2.346933 2.414479 2.438918 2.431440 2.410223 2.391645 2.382653 2.382697 $se Time Series: Start = 49 End = 60 Frequency = 1 [1] 0.4226823 0.5029332 0.5245256 0.5247161 0.5305499 0.5369159 0.5388045 0.5388448 0.5391043 0.5395174 0.5396991 0.5397140 So, what is wrong with arima? Thanking you in advance, Rem __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] predict(arima)
Nothing is wrong with arima: those commands are part of make check, so your copy of R has been corrupted. Search for masked functions, and try starting R with --vanilla. On Sun, 29 Aug 2004, Remigijus Lapinskas wrote: Dear All, R 1.9.1, Windows When copying and pasting a few lines from the 'predict.Arima' help, I get an error message: data(lh) predict(arima(lh, order = c(3,0,0)), n.ahead = 12) Error in eval(expr, envir, enclos) : Object xreg not found On the other hand, the following is OK: data(lh) predict(arima0(lh, order = c(3,0,0)), n.ahead = 12) $pred Time Series: Start = 49 End = 60 Frequency = 1 [1] 2.460173 2.270829 2.198597 2.260696 2.346933 2.414479 2.438918 2.431440 2.410223 2.391645 2.382653 2.382697 $se Time Series: Start = 49 End = 60 Frequency = 1 [1] 0.4226823 0.5029332 0.5245256 0.5247161 0.5305499 0.5369159 0.5388045 0.5388448 0.5391043 0.5395174 0.5396991 0.5397140 So, what is wrong with arima? -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] predict( ..., type=terms)
Hello, After reading the help for predict.lm and predict.glm, it is not clear to me what are the values returned by predict( ..., type=terms). Anybody willing to enlighten me? The example provided by Peter Dalgaard in a recent post unfortunately was enlightening only to the point of making me realize that terms are not what I thought they were. Thanks in advance, Giovanni -- __ [ ] [ Giovanni Petris [EMAIL PROTECTED] ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__] __ [EMAIL PROTECTED] 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
Re: [R] predict( ..., type=terms)
On Wed, 7 Apr 2004, Giovanni Petris wrote: Hello, After reading the help for predict.lm and predict.glm, it is not clear to me what are the values returned by predict( ..., type=terms). Anybody willing to enlighten me? For each term in the formula, extract its coefficients and the corresponding columns of the design matrix, and multiply the two, and then center the result. So, looking at the example in example(termplot) we have a model y~ns(x,6)+z where z is a factor with 4 levels. There are 9 coefficients in the model, but only two terms: ns(x,6) (based on 5 coefficients) and z (based on 3 coefficients). Adding up the terms and the centering value (also returned by predict(,type=terms)) gives the linear predictor. -thomas __ [EMAIL PROTECTED] 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
RE: [R] predict( ..., type=terms)
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Lumley Sent: Wednesday, April 07, 2004 5:44 PM To: Giovanni Petris On Wed, 7 Apr 2004, Giovanni Petris wrote: Hello, After reading the help for predict.lm and predict.glm, it is not clear to me what are the values returned by predict( ..., type=terms). Anybody willing to enlighten me? For each term in the formula, extract its coefficients and the corresponding columns of the design matrix, and multiply the two, and then center the result. So, looking at the example in example(termplot) we have a model y~ns(x,6)+z where z is a factor with 4 levels. There are 9 coefficients in the model, but only two terms: ns(x,6) (based on 5 coefficients) and z (based on 3 coefficients). Adding up the terms and the centering value (also returned by predict(,type=terms)) gives the linear predictor. 1) It would be useful to have this in the help file for predict.(g)lm Also that the constant is accessed as attr( pr.obj, const ) 2) A link to termplot might be useful too. 3) I guess that Giovanni (as well as I) was curious what the rationale behind the centering of effects is. Can anyone tell us? Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc __ [EMAIL PROTECTED] 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
Re: [R] predict function
Uwe Ligges wrote: Thomas Jagoe wrote: I am using R to do a loess normalisation procedure. . . . However in 1.8.1 all goes well until the last step when I get an error: Error: couldn't find function predict.loess Can anyone help ? Use predict() instead of predict.loess() (the method is hidden in a namespace, you should use the generic function). Uwe Ligges Why are the developers ***DOING*** these things to us? It used to be so simple and straightforward! If I wanted to look at an object, including a function object, I typed its name. Now I get hand-cuffed by this ``namespace'' business! I will wager Euros to doughnuts that no-one apart from the developers has a clue what a ``namespace'' is, much less what it is good for. Whatever problem ``namespaces'' were introduced to solve, it pales by comparison with the handicaps they introduce. It's classic tail-wagging-the-dog syndrome. When I get errors from R code, which come from within ``system'' functions, it has been my practice to make a local copy (in the .Globalenv) of the function, stick in calls to browser(), and thereby track down what's going on/wrong. This always worked like a charm. Now if the problem arises within, e.g. predict.loess, I'm stuffed. cheers, Rolf Turner [EMAIL PROTECTED] __ [EMAIL PROTECTED] 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
RE: [R] predict function
If you know what you're looking for, you can always get to non-exported function by using :::, e.g., modreg:::predict.loess will give you the function. Andy From: Rolf Turner Uwe Ligges wrote: Thomas Jagoe wrote: I am using R to do a loess normalisation procedure. . . . However in 1.8.1 all goes well until the last step when I get an error: Error: couldn't find function predict.loess Can anyone help ? Use predict() instead of predict.loess() (the method is hidden in a namespace, you should use the generic function). Uwe Ligges Why are the developers ***DOING*** these things to us? It used to be so simple and straightforward! If I wanted to look at an object, including a function object, I typed its name. Now I get hand-cuffed by this ``namespace'' business! I will wager Euros to doughnuts that no-one apart from the developers has a clue what a ``namespace'' is, much less what it is good for. Whatever problem ``namespaces'' were introduced to solve, it pales by comparison with the handicaps they introduce. It's classic tail-wagging-the-dog syndrome. When I get errors from R code, which come from within ``system'' functions, it has been my practice to make a local copy (in the .Globalenv) of the function, stick in calls to browser(), and thereby track down what's going on/wrong. This always worked like a charm. Now if the problem arises within, e.g. predict.loess, I'm stuffed. cheers, Rolf Turner [EMAIL PROTECTED] __ [EMAIL PROTECTED] 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 -- Notice: This e-mail message, together with any attachments,...{{dropped}} __ [EMAIL PROTECTED] 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
RE: [R] predict function
Dear Roft and Andy, At 10:41 AM 2/14/2004 -0500, Liaw, Andy wrote: If you know what you're looking for, you can always get to non-exported function by using :::, e.g., modreg:::predict.loess will give you the function. and getS3method(predict, loess) or getAnywhere(predict.loess) will retrieve the function without specifying where it resides. I'm sure that opinions are divided (and perhaps the current implementation could be improved), but I like the namespace mechanism: Namespaces give a package author the ability to create objects without (inadvertently) shadowing objects of the same names in other packages, and the ability to shadow objects intentionally that are (potentially) in locations higher on the search path. To my mind, the traditional flat namespace in R was a liability. Regards, John Andy From: Rolf Turner Uwe Ligges wrote: Thomas Jagoe wrote: I am using R to do a loess normalisation procedure. . . . However in 1.8.1 all goes well until the last step when I get an error: Error: couldn't find function predict.loess Can anyone help ? Use predict() instead of predict.loess() (the method is hidden in a namespace, you should use the generic function). Uwe Ligges Why are the developers ***DOING*** these things to us? It used to be so simple and straightforward! If I wanted to look at an object, including a function object, I typed its name. Now I get hand-cuffed by this ``namespace'' business! I will wager Euros to doughnuts that no-one apart from the developers has a clue what a ``namespace'' is, much less what it is good for. Whatever problem ``namespaces'' were introduced to solve, it pales by comparison with the handicaps they introduce. It's classic tail-wagging-the-dog syndrome. When I get errors from R code, which come from within ``system'' functions, it has been my practice to make a local copy (in the .Globalenv) of the function, stick in calls to browser(), and thereby track down what's going on/wrong. This always worked like a charm. Now if the problem arises within, e.g. predict.loess, I'm stuffed. cheers, Rolf Turner [EMAIL PROTECTED] __ [EMAIL PROTECTED] 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 -- Notice: This e-mail message, together with any attachments,...{{dropped}} __ [EMAIL PROTECTED] 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 - John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: [EMAIL PROTECTED] phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox __ [EMAIL PROTECTED] 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
Re: [R] predict function
Other things one might want to ask: - what is the S3 generic corresponding to predict.loess? answer: predict - what are the other methods associated with that S3 generic? answer: methods(predict) - what are all the methods for a given S3 class? answer: apropos([.]loess$) may find some of them but its not guaranteed to find all of them. In fact, in this case it does not find any. Date: Sat, 14 Feb 2004 11:27:11 -0500 From: Duncan Murdoch [EMAIL PROTECTED] To: Liaw, Andy [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], [EMAIL PROTECTED],'Rolf Turner' [EMAIL PROTECTED] Subject: Re: [R] predict function On Sat, 14 Feb 2004 10:41:41 -0500, you wrote: If you know what you're looking for, you can always get to non-exported function by using :::, e.g., modreg:::predict.loess will give you the function. Or getAnywhere('predict.loess') or getS3method('predict','loess') (which are both good to know, because predict.loess won't be in modreg in 1.9, it's in the new stats package). Rolf said: Why are the developers ***DOING*** these things to us? It used to be so simple and straightforward! If I wanted to look at an object, including a function object, I typed its name. Now I get hand-cuffed by this ``namespace'' business! Things weren't so simple in the old days in cases where two packages both defined their own predict.loess functions, or when a user created a function named c or t, or in lots of other situations of name collisions. When two things had the same name, problems were really likely to arise. The point of namespaces is to protect the code in packages from accidental name collisions. Packages with namespaces can safely use c() and t() and know what is going to happen. The decision not to export the name predict.loess follows from the general principle that you shouldn't export things unless you need to. You should be calling predict. If you really need to call predict.loess and predict won't get you there, you need to jump through extra hoops to get it. Duncan Murdoch __ [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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
[R] predict function
I am using R to do a loess normalisation procedure. In 1.5.1 I used the following commands to normalise the variable logratio, over a 2d surface (defined by coordinates x and y): array - read.table(121203B_QCnew.txt, header=T, sep=\t) array$logs555-log(array$s555)/log(2) array$logs647-log(array$s647)/log(2) array$logratio-array$logs555-array$logs647 array$logav-(array$logs555+array$logs647)/2 library(modreg) loess2d-loess(logratio~x+y,data=array) array$logratio2DLoeNorm -array$logratio - predict.loess(loess2d, array) However in 1.8.1 all goes well until the last step when I get an error: Error: couldn't find function predict.loess Can anyone help ? Thomas __ [EMAIL PROTECTED] 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
Re: [R] predict function
You can't use this anymore. The function predict() has a method for loess objects, but there is no longer an available function called predict.loess. So just replace predict.loess with predict. On Fri, 13 Feb 2004, Thomas Jagoe wrote: I am using R to do a loess normalisation procedure. In 1.5.1 I used the following commands to normalise the variable logratio, over a 2d surface (defined by coordinates x and y): array - read.table(121203B_QCnew.txt, header=T, sep=\t) array$logs555-log(array$s555)/log(2) array$logs647-log(array$s647)/log(2) array$logratio-array$logs555-array$logs647 array$logav-(array$logs555+array$logs647)/2 library(modreg) loess2d-loess(logratio~x+y,data=array) array$logratio2DLoeNorm -array$logratio - predict.loess(loess2d, array) However in 1.8.1 all goes well until the last step when I get an error: Error: couldn't find function predict.loess Can anyone help ? Thomas __ [EMAIL PROTECTED] 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 __ [EMAIL PROTECTED] 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
[R] predict for a model with a subset
Hello running R 1.7.1 on Windows 2000 I have a model notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson) and summary(notmar1) gives (as it should) 433 df for the null model but when I run predict(notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson)) I get preditions for 528 people (the full data set, not the subset) How do I get predict to work on just the subset of people for whom the model is estimated? Thanks Peter __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] predict for a model with a subset
Have you tried the following: notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson), data=DF) predict(notmar1, newdata=DF[DF$marcom==0,]) I haven't tested this specific code, but I've gotten sensible results from constructs like this in the past. hope this helps. spencer graves Peter Flom wrote: Hello running R 1.7.1 on Windows 2000 I have a model notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson) and summary(notmar1) gives (as it should) 433 df for the null model but when I run predict(notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson)) I get preditions for 528 people (the full data set, not the subset) How do I get predict to work on just the subset of people for whom the model is estimated? Thanks Peter __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] predict for a model with a subset
example(predict.glm) fit - glm(SF ~ ldose, family=binomial, subset=sex==M) predict(fit) [1] -2.8185550 -1.5596055 -0.3006561 0.9582933 2.2172427 3.4761922 which is just the males. So, that example works correctly, and predict.glm as called by you should just return the fitted values, as above. On Fri, 24 Oct 2003, Peter Flom wrote: running R 1.7.1 on Windows 2000 I have a model notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson) and summary(notmar1) gives (as it should) 433 df for the null model but when I run predict(notmar1 - glm(yprisx~age+harddrug+sex, subset = marcom == 0, family = quasipoisson)) I get preditions for 528 people (the full data set, not the subset) How do I get predict to work on just the subset of people for whom the model is estimated? Perhaps you can show us how you managed to break it? -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] predict for mlm does not work properly
Hello, I've just fitted a model with multi-responses, and I get an object of class lm mlm. My problem is that as soon as I invoke the predict method for a dataframe newdata, the methods runs and give me back prediction at the fitting points but not for newdata. Does someone has an explanation for this behavior, and some ideas to make predict.mlm work efficiently. Thanks in advance Isabelle Zabalza-Mezghani IFP-Reservoir Engineering Department Rueil-Malmaison - France __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] predict for mlm does not work properly
From: ZABALZA-MEZGHANI Isabelle Hello, I've just fitted a model with multi-responses, and I get an object of class lm mlm. My problem is that as soon as I invoke the predict method for a dataframe newdata, the methods runs and give me back prediction at the fitting points but not for newdata. What version of R and on what platform are you doing this? What were the commands that you tried? In R-1.7.1 on WinXPPro, I get: df - data.frame(y1=rnorm(10), y2=rnorm(10), x1=rnorm(10),x2=rnorm(10)) df2 - data.frame(y1=rnorm(10), y2=rnorm(10), x1=rnorm(10),x2=rnorm(10)) try.mlm - lm(cbind(y1,y2) ~ x1+x2, data=df) predict(try.mlm) y1 y2 1 -0.84974045 -0.19779627 2 -1.08128909 0.17851648 3 0.23572795 0.23167228 4 -0.65118764 0.09273186 5 -0.06741819 0.10396708 6 -0.88852774 -0.05386359 7 -0.21007585 0.07839343 8 -0.07061706 0.01714900 9 -0.67554077 0.07551119 10 -1.36196165 0.33502943 predict(try.mlm, df2) y1y2 1 -0.66079093 2.772385e-02 2 -1.25399169 1.344038e-01 3 -0.64321234 3.044455e-02 4 0.29611924 -9.523683e-02 5 -1.01594522 1.557392e-01 6 -0.04513806 -1.529740e-01 7 -0.38954683 -2.780412e-03 8 -1.21828379 -2.460862e-01 9 -0.38511937 6.092239e-02 10 -0.34979146 -9.909837e-05 Seems fine to me. Andy Does someone has an explanation for this behavior, and some ideas to make predict.mlm work efficiently. Thanks in advance Isabelle Zabalza-Mezghani IFP-Reservoir Engineering Department Rueil-Malmaison - France __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo /r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] predict(lm(etc.),some_data) - numeric envir arg not of length one ???
I've got a data frame with two numeric variables, df$flow and df$flow1. tl - lm(flow~flow1,df,na.action=na.exclude) tlo - loess(flow~flow1,df,na.action=na.exclude) Both loess and a simple linear model fit the data well. summary(tl) and summary(tlo) seem reasonable. As do plots such as: plot(predict(tl),df$flow) plot(predict(tlo),df$flow) I want to replace missing values of df$flow from df$flow1: p - is.na(df$flow) df$flow[p] - predict(tl,df$flow1[p]) Error in eval(expr, envir, enclos) : numeric envir arg not of length one ??? df$flow[p]- predict(tlo,df$flow1[p]) This loess prediction works however. Could someone explain the linear model's numeric envir arg not of length one error for me? Thanks in advance ... Bruce L. __ Bruce LaZerte Grandview Lake in Muskoka Baysville, Ontario, Canada __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] predict
It uses the appropriate method for the generic function predict(). In your case it is predict.ar(), and you can examine it by getS3method(predict, ar) On Tue, 15 Jul 2003, ATHANASIA KAMARIOTIS wrote: Can you please tell me how R computes : predict(ar.x)$pred in : #let x be a vector ar.x-ar(x) predict(ar.x)$pred -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] predict
Good afternoon, Can you please tell me how R computes : predict(ar.x)$pred in : #let x be a vector ar.x-ar(x) predict(ar.x)$pred Thank you Bye __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] predict formula with variables
Hello On the subject of using predict formula with variables, I used cbind(var1,var2,var3,var4, predict(glm.obj,type=resp)) to find probability of each combinations. However,I am still hesitant whether I have done it correctly. Is it correct ? thanks in advance Ahmet Temiz Turkey __ __ The views and opinions expressed in this e-mail message are ...{{dropped}} __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help