search for: ypred

Displaying 20 results from an estimated 27 matches for "ypred".

Did you mean: pred
2018 May 22
2
Bootstrap and average median squared error
...uggest you use base package boot. > You would need the data in a data.frame, see how you could do it. > > > library(boot) > > bootMedianSE <- function(data, indices){ > ??? d <- data[indices, ] > ??? fit <- rq(crp ~ bmi + glucose, tau = 0.5, data = d) > ??? ypred <- predict(fit) > ??? y <- d$crp > ??? median(y - ypred)^2 > } > > dat <- data.frame(crp, bmi, glucose) > nboot <- 100 > > medse <- boot(dat, bootMedianSE, R = nboot) > > medse$t0 > mean(medse$t)??? # This is the value you want > > > H...
2018 May 22
1
Bootstrap and average median squared error
Hello, Right! I copied from the OP's question without thinking about it. Corrected would be bootMedianSE <- function(data, indices){ d <- data[indices, ] fit <- rq(crp ~ bmi + glucose, tau = 0.5, data = d) ypred <- predict(fit) y <- d$crp median((y - ypred)^2) } Sorry, rui Barradas On 5/22/2018 11:32 AM, Daniel Nordlund wrote: > On 5/22/2018 2:32 AM, Rui Barradas wrote: >> bootMedianSE <- function(data, indices){ >> ????? d <- data[indices, ] >> ????? fit <-...
2018 May 21
2
Bootstrap and average median squared error
...13,45,46,56,57,67,87,12,13) glucose <-c(23,54,11,12,13,21,32,12,45,54,65,87,21,23,12,12,23,23,43,54) # Create a list to store the results lst<-list() # Numbers of bootstrap samples nboot=100 bootstrap.MedAESQ =rep(NA,nboot) for(i in 1?:nboot) { fit <- rq( crp ~ bmi+glucose, tau = 0.5) ypred=predict(fit) y=new$crp bootstrap.MedAESQ [i]=median(y-ypred)^2 lst[i]<-bootstrap.MedAESQ } mean(unlist(lst)) ################################### ?
2011 Sep 23
1
Adding weights to optim
I realize this may be more of a math question. I have the following optim: optim(c(0.0,1.0),logis.op,x=d1_all$SOA,y=as.numeric(md1[,i])) which uses the following function: logis.op <- function(p,x,y) { ypred <- 1.0 / (1.0 + exp((p[1] - x) / p[2])); res <- sum((y-ypred)^2) return(res) } I would like to add weights to the optim. Do I have to alter the logis.op function by adding an additional weights parameter? And if so, how would I change the ypred formula? Would I just substitute x with...
2018 May 22
0
Bootstrap and average median squared error
On 5/22/2018 2:32 AM, Rui Barradas wrote: > bootMedianSE <- function(data, indices){ > ???? d <- data[indices, ] > ???? fit <- rq(crp ~ bmi + glucose, tau = 0.5, data = d) > ???? ypred <- predict(fit) > ???? y <- d$crp > ???? median(y - ypred)^2 > } since the OP is looking for the "median squared error", shouldn't the final line of the function be median((y - ypred)^2) Dan -- Daniel Nordlund Port Townsend, WA USA
2018 May 22
0
Bootstrap and average median squared error
...o, If you want to bootstrap a statistic, I suggest you use base package boot. You would need the data in a data.frame, see how you could do it. library(boot) bootMedianSE <- function(data, indices){ d <- data[indices, ] fit <- rq(crp ~ bmi + glucose, tau = 0.5, data = d) ypred <- predict(fit) y <- d$crp median(y - ypred)^2 } dat <- data.frame(crp, bmi, glucose) nboot <- 100 medse <- boot(dat, bootMedianSE, R = nboot) medse$t0 mean(medse$t) # This is the value you want Hope this helps, Rui Barradas On 5/22/2018 12:19 AM, varin sacha vi...
2008 Nov 26
1
Smoothed 3D plots
...ion via 3D plots. My data and session info are at the end of this message. So far, I have tried scatterplot3d (scatterplot3d), persp3d (rgl), persp (graphics) and scatter3d (Rmcdr) but any of them gave me what I'd like to have as final result (please see [1] for a similar 3D plot changing PF by ypred, pdn by h4 and pup by h11). In general terms, I would like to plot a smoothed surface with h4 and h11 in the x and y axis, respectively, and y in the z axis. I think that a smoothing procedure should work but I don't know how to get that work in R. I would really appreciate any help you can p...
2006 Apr 05
1
predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
...It is not related to the fact that the function is returned from a function. Sorry about that. I've been troubleshooting soo much I've been shoting over the target. Here is a much smaller reproducible example: x <- 1:10 y <- 1:10 + rnorm(length(x)) sp <- smooth.spline(x=x, y=y) ypred <- predict(sp$fit, x) # [1] 2.325181 2.756166 ... ypred2 <- predict(sp$fit, c(0,x)) # Error in Recall(object, xrange) : couldn't find # function "predict.smooth.spline.fit" /Henrik On 4/5/06, Henrik Bengtsson <hb at maths.lth.se> wrote: > Hi, > > yesterday I...
2011 Jan 27
2
Extrapolating values from a glm fit
...t <- c(1, 3, 2, 5, 4, 4, 3, 5, 5, 4, 5, 11, 22, 11, 15, 16, 11, 7, 14, 10, 16, 19, 11, 5, 4, 5, 6, 9, 4, 2, 5, 5, 2, 2) mylogit <- glm(y~x,weights=weight, family = binomial) # now I try plotting the predicted value, and it looks like a good fit, hopefully I can access what the glm is doing ypred <- predict(mylogit,newdata=as.data.frame(x),type="response") plot(x, ypred,type="l") points(x,y) # so I try to predict the x value when y (proportion) is at .5, but something is wrong.. predict(mylogit,newdata=as.data.frame(0.5)) [[alternative HTML version deleted]]
2012 Feb 25
1
Unexpected behavior in factor level ordering
...t")) y <- rnorm(6) m1 <- lm (y ~ xf ) plot(y ~ xf) abline (m1) ## Just a little problem the line does not "go through" the box ## plot in the right spot because contrasts(xf) is 0,1 but ## the plot uses xf in 1,2. xlevels <- levels(xf) newdf <- data.frame(xf=xlevels) ypred <- predict(m1, newdata=newdf) ##Watch now: the plot comes out "reversed", AC before BC plot(ypred ~ newdf$xf) ## Ah. Now I see: levels(newdf$xf) ## Why doesnt newdf$xf respect the ordering of the levels? -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504...
2018 Apr 21
0
Cross-validation : can't get the predicted response on the testing data
...ple size sam=sample(1?:n,floor(p*n),replace=FALSE) # Sample training data Training =BIO [sam,] # Sample testing data Testing = BIO [-sam,] ? # Build the 2 models fit<- FastTau(model.matrix(~Training$A+Training$B),Training$C) HBR<-hbrfit(C ~ A+B) # Predict the response on the testing data ypred=predict(fit,newdata=Testing) ypred=predict(HBR,newdata=Testing) # Get the true response from testing data y=BIO[-sam,]$D ?# Get error rate RMSE=sqrt(mean((y-ypred)^2)) RMSE MAPE = mean(abs(y-ypred/y)) MAPE
2023 Oct 22
1
running crossvalidation many times MSE for Lasso regression
...ore the results lst<-list() ? # This statement does the repetitions (looping) for(i in 1?:1000) { ? n=45 ? p=0.667 ? sam=sample(1?:n,floor(p*n),replace=FALSE) ? Training =T [sam,] Testing = T [-sam,] ? test1=matrix(c(Testing$x1,Testing$x2),ncol=2) ? predictLasso=predict(cv_model, newx=test1) ? ? ypred=predict(predictLasso,newdata=test1) y=T[-sam,]$y ? MSE = mean((y-ypred)^2) MSE lst[i]<-MSE } mean(unlist(lst)) ##################################################################? ? ? ?
2023 Oct 22
2
running crossvalidation many times MSE for Lasso regression
...s (looping) > for(i in 1 :1000) { > > n=45 > > p=0.667 > > sam=sample(1 :n,floor(p*n),replace=FALSE) > > Training =T [sam,] > Testing = T [-sam,] > > test1=matrix(c(Testing$x1,Testing$x2),ncol=2) > > predictLasso=predict(cv_model, newx=test1) > > > ypred=predict(predictLasso,newdata=test1) > y=T[-sam,]$y > > MSE = mean((y-ypred)^2) > MSE > lst[i]<-MSE > } > mean(unlist(lst)) > ################################################################## > > > > > ______________________________________________ > R-h...
2006 Aug 10
1
logistic discrimination: which chance performance??
Hello, I am using logistic discriminant analysis to check whether a known classification Yobs can be predicted by few continuous variables X. What I do is to predict class probabilities with multinom() in nnet(), obtaining a predicted classification Ypred and then compute the percentage P(obs) of objects classified the same in Yobs and Ypred. My problem now is to figure out whether P(obs) is significantly higher than chance. I opted for a crude permutation approach: compute P(perm) over 10000 random permutations of Yobs (i.e., refit the multino...
2006 Apr 05
0
Return function from function and Recall()
...lem. getPredictor <- function(x, y) { sp <- smooth.spline(x=x, y=y, keep.data=FALSE) function(x, ...) predict(sp$fit, x, ...)$y } # Simulate data x <- 1:10 y <- 1:10 + rnorm(length(x)) # Estimate predictor function fcn <- getPredictor(x,y) # No extrapolation => no Recall() ypred <- fcn(x) print(ypred) # Gives: # [1] 2.325181 2.756166 ... # With extrapolation => Recall() xextrap <- c(0,x) ypred <- fcn(xextrap) # Gives: # Error in Recall(object, xrange) : couldn't find # function "predict.smooth.spline.fit" To see what's the function look...
2023 Oct 24
1
running crossvalidation many times MSE for Lasso regression
...t;> >> ? ? ? >> >> test1=matrix(c(Testing$x1,Testing$x2),ncol=2) >> ? ? ? >> >> >> ? ? ? >> >> predictLasso=predict(cv_model, newx=test1) >> ? ? ? >> >> >> ? ? ? >> >> >> ? ? ? >> >> ypred=predict(predictLasso,newdata=test1) >> ? ? ? >> >> y=T[-sam,]$y >> ? ? ? >> >> >> ? ? ? >> >> MSE = mean((y-ypred)^2) >> ? ? ? >> >> MSE >> ? ? ? >> >> lst[i]<-MSE >> ? ? ? >> >> } &...
2023 Oct 23
2
running crossvalidation many times MSE for Lasso regression
...ng = T [-sam,] > >> >> > >> >> test1=matrix(c(Testing$x1,Testing$x2),ncol=2) > >> >> > >> >> predictLasso=predict(cv_model, newx=test1) > >> >> > >> >> > >> >> ypred=predict(predictLasso,newdata=test1) > >> >> y=T[-sam,]$y > >> >> > >> >> MSE = mean((y-ypred)^2) > >> >> MSE > >> >> lst[i]<-MSE > >> >> } > >> >> mean(unli...
2023 Oct 23
1
running crossvalidation many times MSE for Lasso regression
...ng = T [-sam,] >? ? ? >> >> >? ? ? >> >> test1=matrix(c(Testing$x1,Testing$x2),ncol=2) >? ? ? >> >> >? ? ? >> >> predictLasso=predict(cv_model, newx=test1) >? ? ? >> >> >? ? ? >> >> >? ? ? >> >> ypred=predict(predictLasso,newdata=test1) >? ? ? >> >> y=T[-sam,]$y >? ? ? >> >> >? ? ? >> >> MSE = mean((y-ypred)^2) >? ? ? >> >> MSE >? ? ? >> >> lst[i]<-MSE >? ? ? >> >> } >? ? ? >> >> mean(unli...
2007 Oct 23
1
Compute R2 and Q2 in PLS with pls.pcr package
...ave-one-out cross validation) of the model. I am not sure if there are specific slots in the output of the mvr function that give these parameters (RMS and R2 parameters are given for each variable of Y). I have tried to compute it myself from the ouput of mvr but I am not sure if the values of Ypred within the validat slot are the predictions of each observation of Y when leave-one-out cross validation is applied. My code is as follows: > mypls <- mvr(Xtrain, Ytrain, method="SIMPLS", validation="CV", ncomp=1, niter=nrow(Ytrain)) > Xhat <- mypls$training$Xs...
2004 Nov 15
0
how to obtain predicted labels for test data using "kernelpls"
...predicted Y values for test data, using the Kernel PLS method. Let's take the example in the R help: > data(NIR) > attach(NIR) > NIR.kernelpls <- mvr(Xtrain, Ytrain, 1:6, validation = "CV", method="kernelPLS") How can we get the predicted Y values ("Ypred") for Xtest in this case? As far as I checked, there is no parameter to specify the test data in "mvr" or "pls". I, therefore, thought about the "kernelpls" function as follows: > Kernelpls(Xtrain, Ytrain, ncomp = 21, Xtest) Is this the correct way of g...