Displaying 20 results from an estimated 1000 matches similar to: "Return function from function and Recall()"
2006 Apr 05
1
predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
Hi,
forget about the below details. 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 ...
2006 Apr 05
1
page() (Was: Re: predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall()))
Here I think S3 dispatch is very natural. Try the following:
page <- function(x, method = c("dput", "print"), ...) UseMethod("page")
page.getAnywhere <- function(x, ..., idx=NULL) {
name <- x$name;
objects <- x$obj;
if (length(objects) == 0)
stop("no object named '", name, "' was found");
if (is.null(idx)) {
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
2011 Jan 27
2
Extrapolating values from a glm fit
Dear R-help,
I have fitted a glm logistic function to dichotomous forced choices
responses varying according to time interval between two stimulus. x values
are time separation in miliseconds, and the y values are proportion
responses for one of the stimulus. Now I am trying to extrapolate x values
for the y value (proportion) at .25, .5, and .75. I have tried several
predict parameters, and they
2018 May 22
2
Bootstrap and average median squared error
I forgot, you should also set.seed() before calling boot() to make the
results reproducible.
Rui Barradas
On 5/22/2018 10:00 AM, Rui Barradas wrote:
> Hello,
>
> 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,
2006 Apr 04
2
Return function from function with minimal environment
Hi,
this relates to the question "How to set a former environment?" asked
yesterday. What is the best way to to return a function with a
minimal environment from a function? Here is a dummy example:
foo <- function(huge) {
scale <- mean(huge)
function(x) { scale * x }
}
fcn <- foo(1:10e5)
The problem with this approach is that the environment of 'fcn' does
not
2007 Aug 22
3
integrate
Hi,
I am trying to integrate a function which is approximately constant
over the range of the integration. The function is as follows:
> my.fcn = function(mu){
+ m = 1000
+ z = 0
+ z.mse = 0
+ for(i in 1:m){
+ z[i] = rnorm(1, mu, 1)
+ z.mse = z.mse + (z[i] - mu)^2
+ }
+ return(z.mse/m)
+ }
> my.fcn(-10)
[1] 1.021711
> my.fcn(10)
[1] 0.9995235
> my.fcn(-5)
[1] 1.012727
> my.fcn(5)
2018 May 22
0
Bootstrap and average median squared error
Hello,
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 <-
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
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
2008 Nov 26
1
Smoothed 3D plots
DeaR list,
I'm trying to represent some information 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
2016 Mar 13
1
formals(x)<- drops attributes including class
Just checking in to see whether it is intended or not that assigning
new formals to a function/closure causes any attributes to be dropped:
EXAMPLE:
> fcn <- structure(function() {}, foo="foo", class=c("foo"))
> str(fcn)
function ()
- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 18 1 30 18 30 1 1
.. ..- attr(*, "srcfile")=Classes
2010 Jun 09
2
OOP and passing by value
Greetings,
I love the R system and am sincerely grateful for the great effort the
product and contributors
are delivering.
My question is as follows:
I am trying to use S4 style classes but cannot write functions that modify
an object
because paramter passing is by value.
For example I want to do this:
setGeneric("setData", function(this,fcn,k){ standardGeneric("setData")
2018 Apr 21
0
Cross-validation : can't get the predicted response on the testing data
Dear R-experts,
Doing cross-validation for 2 robust regressions (HBR and fast Tau). I can't get the 2 errors rates (RMSE and MAPE). The problem is to predict the response on the testing data. I get 2 error messages.
Here below the reproducible (fictional example) R code.
#install.packages("MLmetrics")
# install.packages( "robustbase" )
# install.packages(
2011 Mar 15
1
Problem with nls.lm function of minpack.lm package.
Dear R useRs,
I have a problem with nls.lm function of minpackl.lm package.
I need to fit the Van Genuchten Model to a set of data of Theta and hydraulic conductivity with nls.lm function of minpack.lm package.
For the first fit, the parameter estimates keep changing even after 1000 iterations (Th)
and
I have a following error message for fit of hydraulic conductivity (k);
Reason for
2005 Oct 09
3
[ subscripting sometimes loses names (PR#8192)
--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
R, like recent versions of S-Plus, sometimes - but not always - loses
names when subscripting objects with "[". (Earlier versions of S and
S-Plus had the correct, name-preserving behavior.) This seems bad, it
would be better to remove names only by explicit request, not as an
accidental
2005 Sep 07
1
Tracebacks with tryCatch() and withCallingHandlers()?
When batch processing analysis, I use tryCatch() for failure handling
and to prevent unwanted interrupts. I write detailed progress to log
file and conditions (warnings and errors) are written to the same log
file immediately by using withCallingHandlers(..., condition=function(c)
cat(c, file=logFile)). However, I would also like to write the call
stack to the log file to further simplify
2001 Jul 20
2
plot() axis problem
This posting just illustrates the problem with plot()
x<-1:20
y<-c(1:10,301:310)
plot(x,y)
xrange<-c(1,10)
plot(x,y,xlim=xrange) #uses ylim=range(y)
This is the default behaviour of plot() and I think it is not sensible.
By default the range of the y axis should span the y values corresponding
to the points plotted. In this example the yaxis should span 1-10 rather
than 1-310. This does
2009 Sep 17
1
Beginner Q- dates in the xrange?
Hi all- terribly beginner question here, but I can't figure out how to put
dates as the values for my x range in a plot. Example:
xrange <- results$current
yrange <- results$DIFF
plot(xrange, yrange, type="n", xlab="Date", ylab="Differential")
lines(results$DIFF, type="l", lwd=1.5, col="red")
Where xrange is:
> xrange
[1]
2003 Aug 15
0
Re: [R} stars graphs
I thought about that star graph again, and realized that it would be quite
a handy thing for visualizing cyclic data like time or compass direction.
Here is a cleaned up (and renamed) version to do a polar plot that starts
at the right and goes counterclockwise or a 24 hour clock plot that starts
at the top and goes clockwise. There are probably other varieties that
would be interesting.
Jim