# oce runlm function

February 11, 2014
By

(This article was first published on Dan Kelley Blog/R, and kindly contributed to R-bloggers)

# Introduction

As was expected, the `runderiv()` function has been both useful and deficient. Useful because it offers a good replacement for `smooth.spline()` calculations of derivatives for things like N^2. And deficient because it only calculated derivatives, not values!

Both an extension and a renaming were called for. The result is `runlm()`.

# Tests

Below are the examples from its manpage, with the results.

Case 1

 ``1`` ```library(oce) ```
``````## Loading required package: methods
## Loading required package: mapproj
## Loading required package: maps
``````
 ``````1 2 3 4 5 6 7 8`````` ```x <- 1:100 y <- 1 + x/100 + sin(x/5) yn <- y + rnorm(100, sd = 0.1) L <- 4 calc <- runlm(x, y, L = L, deriv = 0) plot(x, y, type = "l", lwd = 7, col = "gray") points(x, yn, pch = 20, col = "blue") lines(x, calc, lwd = 2, col = "red") ``` Case 2

 ``````1 2 3 4 5 6 7 8 9`````` ```data(ctd) plot(ctd, which = "N2") rho <- swRho(ctd) z <- swZ(ctd) zz <- seq(min(z), max(z), 0.1) N2 <- -9.8/mean(rho) * runlm(z, rho, zz, deriv = 1) lines(N2, -zz, col = "red") legend("bottomright", lwd = 2, bg = "white", col = c("black", "red"), legend = c("swN2()", "using runlm()")) ``` # Comments

1. The fit in Case 1 is almost spookily good.

2. The N^2 results suggest including this as a method for `swN2()`, perhaps the default method, but that’s for another day.

# Resources

To leave a comment for the author, please follow the link and comment on their blog: Dan Kelley Blog/R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

# Never miss an update! Subscribe to R-bloggers to receive e-mails with the latest R posts.(You will not see this message again.)

Click here to close (This popup will not appear again)