Re: [R] interpolation using R for PCR quantification
There is some terminology confusion here... interpolation as implemented by approx or spline usually means estimating values between known points. You seem to have approximate (not known) points, and are looking to apply a linear regression model to estimate missing data. Beware that mixing estimates (a.k.a. yhat) with measured data can be misleading because yhat is missing the error term(s) that are present in the original data. If you really want to do this after reconsidering, then perhaps the following does what you want? logconlm <- lm( log10( con ) ~ cyc, data = df ) df$yhat <- predict( logconlm, newdata=df ) df$logconfixed <- ifelse( is.na( df$con ), df$yhat, log10( df$con ) ) plot( df$cyc, df$logconfixed, pch=df$sam ) -- Sent from my phone. Please excuse my brevity. On December 24, 2015 8:12:13 AM PST, Luigi Marongiu wrote: >Dear all, >I am a newbie in interpolation using R and I would like to learn >better the procedure. >I am applying interpolation to quantify nucleic acid targets using an >assay known as PCR. To do this, I have two sets of variables: standard >of known concentrations and query for which I need to identify the >concentration. >For each variable I have the output of the assay (cyc) and an >approximation of the concentration expressed in relation to the >concentration of the standard, so 5 means 10^5 etc. >Given that the actual concentration of the standards is given in the >'con' variable, the relation is that x=log10(con) and y = cyc, as >represented in the first plot of the following example. In black are >depicted the standard and in red the query samples. > >Now, to obtain interpolation the only function that i know is >approx(). The first problem is that I need to switch the x-y variables >because the values specifying where interpolation is to take place go >in the 'xout' parameter and I have y outputs. If I maintain the >original x/y orientation the output from approx() is empty. How can I >keep the original layout? I must admit, anyhow, that the construct >x=log10(con) and y = cyc is an artifact of the PCR analysis, since the >independent variable is indeed the cyc value. > >The second problem I am facing -- and the most important -- is that >the output seems weird. The values I get are simply the concentration >input as such and not calculated by interpolation. In the example, the >output I obtain is: > [1] NA 1480.600 1480.600 148.060 202.319 148.060 14.806 >14.806 14.806 >[10] NA >the first and last value are OK because the cyc values are outside the >dynamic range under evaluation, but the only value that seems genuine >is 202.319, the others are just the values I placed in the 'con' >variable. For instance the second and third values have cyc = 26.992 >and 26.961 and yet they are both assigned to 1480.600. >What I am getting wrong? >Thank you (and merry Christmas!) >L > > >dil <- c(5,5,5,5,4,4,4,3,3,3, >3,3,2,2,2,2,2,2,1,1,1,1, > 1,1,1) >sam <- c(0,0,0,1,0,0,0,0,0,0, >1,1,0,0,0,1,1,1,0,0,0,1, > 1,1,1) >cyc <- c(20.787,20.494,20.475,20.189,23.991, >24.084,23.863,26.298,28.007,27.413,26.992, >26.961,31.363,30.979,32.013,31.004,30.576, >31.195,35.219,34.096,38.088,34.934,35.101, >35.206,38.366) >con <- c(148060,148060,148060,NA,14806,14806, >14806,1480.6,1480.6,1480.6,NA,NA,148.06, >148.06,148.06,NA,NA,NA,14.806,14.806, >14.806,NA,NA,NA,NA) >df <- data.frame(dil, sam, cyc, con) > >std <- subset(df, sam == 0) >qry <- subset(df, sam == 1) > >plot(std$cyc ~ std$dil) >points(qry$dil, qry$cyc, col ="red") > >Q <- approx(x=std$cyc, y=log10(std$con), xout=qry$cyc, >method="linear", rule = 1) >(10^(Q$y)) > >plot(std$cyc, y=log10(std$con)) >abline(lm(log10(df$con) ~ df$cyc)) >abline(v=qry$cyc, col="blue") > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] interpolation using R for PCR quantification
Dear all, I am a newbie in interpolation using R and I would like to learn better the procedure. I am applying interpolation to quantify nucleic acid targets using an assay known as PCR. To do this, I have two sets of variables: standard of known concentrations and query for which I need to identify the concentration. For each variable I have the output of the assay (cyc) and an approximation of the concentration expressed in relation to the concentration of the standard, so 5 means 10^5 etc. Given that the actual concentration of the standards is given in the 'con' variable, the relation is that x=log10(con) and y = cyc, as represented in the first plot of the following example. In black are depicted the standard and in red the query samples. Now, to obtain interpolation the only function that i know is approx(). The first problem is that I need to switch the x-y variables because the values specifying where interpolation is to take place go in the 'xout' parameter and I have y outputs. If I maintain the original x/y orientation the output from approx() is empty. How can I keep the original layout? I must admit, anyhow, that the construct x=log10(con) and y = cyc is an artifact of the PCR analysis, since the independent variable is indeed the cyc value. The second problem I am facing -- and the most important -- is that the output seems weird. The values I get are simply the concentration input as such and not calculated by interpolation. In the example, the output I obtain is: [1] NA 1480.600 1480.600 148.060 202.319 148.060 14.806 14.806 14.806 [10] NA the first and last value are OK because the cyc values are outside the dynamic range under evaluation, but the only value that seems genuine is 202.319, the others are just the values I placed in the 'con' variable. For instance the second and third values have cyc = 26.992 and 26.961 and yet they are both assigned to 1480.600. What I am getting wrong? Thank you (and merry Christmas!) L >>> dil <- c(5,5,5,5,4,4,4,3,3,3, 3,3,2,2,2,2,2,2,1,1,1,1, 1,1,1) sam <- c(0,0,0,1,0,0,0,0,0,0, 1,1,0,0,0,1,1,1,0,0,0,1, 1,1,1) cyc <- c(20.787,20.494,20.475,20.189,23.991, 24.084,23.863,26.298,28.007,27.413,26.992, 26.961,31.363,30.979,32.013,31.004,30.576, 31.195,35.219,34.096,38.088,34.934,35.101, 35.206,38.366) con <- c(148060,148060,148060,NA,14806,14806, 14806,1480.6,1480.6,1480.6,NA,NA,148.06, 148.06,148.06,NA,NA,NA,14.806,14.806, 14.806,NA,NA,NA,NA) df <- data.frame(dil, sam, cyc, con) std <- subset(df, sam == 0) qry <- subset(df, sam == 1) plot(std$cyc ~ std$dil) points(qry$dil, qry$cyc, col ="red") Q <- approx(x=std$cyc, y=log10(std$con), xout=qry$cyc, method="linear", rule = 1) (10^(Q$y)) plot(std$cyc, y=log10(std$con)) abline(lm(log10(df$con) ~ df$cyc)) abline(v=qry$cyc, col="blue") __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Interpolation grid with points outside data area- gstat
Dear All, An interpolation grid of spacing 100m by 100m was created for irregular space spatial data. The plot of the grid and sample data shows some grid points outside the data area. I guess the predicted values of those points outside the data area will not be reliable. How do I modify my R script so that the grid can be created within the range of sample data. Note: The x-y bounding box for the sample spatial data is min max easting 299678.9 301298.6 northing 5737285.6 5738128.1 while the x-y bounding box for the created interpolation grid is min max easting 299628 301328 northing 5737235 5738135 My R script is as follows: # get the range of spatial coordinates in the data easting.range <- as.integer(range(canmod.sp@coords[,1])) northing.range <-as.integer(range(canmod.sp@coords[,2])) ## now expand to a grid with 100 meter spacing: grd <- expand.grid(x=seq(from=easting.range[1], to=easting.range[2], by=100), y=seq(from=northing.range[1], to=northing.range[2], by=100)) names(grd)<-c("easting","northing") coordinates(grd)<-~easting+northing proj4string(grd)<-CRS("+proj=utm +zone=12 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +towgs84=0,0,0") ## plot grid and sample data: plot(grd, cex=0.2) points(canmod.sp, pch=1,col="red", cex=0.4) title("Interpolation Grid and Sample Points") Ordinary kriging to create kriging prediction object prok <- krige(id="yield",yield ~ 1, canmod.sp, newdata = grd, model=exp.mod,block=c(10,10),nmax=100) Your advice, comment and suggestion are highly welcome on what to do so that grid points will be within the data area so that the predicted for such points can be reliable. Thanks Moshood [[alternative HTML version deleted]] __ R-help@r-project.org 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] interpolation in at least 3, perhaps 4 dimensions?
Hello R-helpers, I have a data set of points in three dimensions (x, y, z), each with an associated amplitude. These are data collected using a radar, and of tree roots. There are holes in the data, and I'm interested in interpolating the missing values to create a root map. This could simply be based on distance, but ideally would also incorporate the amplitude data. Is anyone aware of an existing implementation of a solution to this type of problem in R? Thanks *Ben Caldwell* [[alternative HTML version deleted]] __ R-help@r-project.org 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] interpolation to new points between geo coordinates
Jan, There are a lot of packages that can help you, the best one depends on your needs (with or without prediction uncertainty, format of results, different options) and the size of your problem. CRAN has a spatial Task View http://cran.r-project.org/web/views/Spatial.html with a short description of most packages dealing with spatial data. I think the functions you mentioned should be able to solve your problems, but I dont have experience with either of them. It is impossible to know what you are doing wrong as you did not post any error messages. For increasing the resolution of your data, you can also try disaggregate or resample in the raster package. gstat, with automap or intamap as simpler interfaces can also be used for geostatistical interpolation to the higher resolution grid, also giving you a prediction uncertainty. You should in general be careful with interpolation of lat-lon data, consider using spTransform to get projected coordinates if you use any of the geostatistical methods. You will for spatial questions generally get quicker response from the r-sig-geo mailinglist. Best wishes, Jon On 02-Jul-12 10:47, Jan Näs wrote: Hi I have a data set with geo coordinates and values for each coordinate. I want to interpolate the values to new positions on a finer grid, also geo coordinates. I have looked at the fields package (interp.surface) and the akima package (interp) but cant quite figure what I am doing wrong, or if these functions suits my needs. I have the two data set: grid_1: lat lon value 1 56.5 11.1 53 2 56.6 11.1 53.1 3 56.7 11.12 52.1 4 56.5 11.2 52.9 ...etc. and a new grid grid_2 lat lon 1 55.52 11.11 2 55.53 11.115 3 55.54 11.12 ...etc. And I want interpolated values for grid_2. Any ideas? /Jan __ R-help@r-project.org 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. -- Jon Olav Skøien Joint Research Centre - European Commission Institute for Environment and Sustainability (IES) Land Resource Management Unit Via Fermi 2749, TP 440, I-21027 Ispra (VA), ITALY jon.sko...@jrc.ec.europa.eu Tel: +39 0332 789206 Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission. __ R-help@r-project.org 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] interpolation to new points between geo coordinates
Hi I have a data set with geo coordinates and values for each coordinate. I want to interpolate the values to new positions on a finer grid, also geo coordinates. I have looked at the fields package (interp.surface) and the akima package (interp) but cant quite figure what I am doing wrong, or if these functions suits my needs. I have the two data set: grid_1: lat lon value 1 56.5 11.1 53 2 56.6 11.1 53.1 3 56.7 11.12 52.1 4 56.5 11.2 52.9 ...etc. and a new grid grid_2 lat lon 1 55.52 11.11 2 55.53 11.115 3 55.54 11.12 ...etc. And I want interpolated values for grid_2. Any ideas? /Jan __ R-help@r-project.org 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] interpolation to montly data
On Sat, Jun 16, 2012 at 8:19 AM, stef salvez wrote: > I have a panel data set (in MS excel) like the one below > > > 1 "23/11/08" 2 > 1 "28/12/08" 3 > 1 "25/01/09" 4 > 1 "22/02/09" 5 > 1 "29/03/09" 6 > 1 "26/04/09" 32 > 1 "24/05/09" 23 > 1 "28/06/09" 32 > 2 "26/10/08" 45 > 2 "23/11/08" 46 > 2 "21/12/08" 90 > 2 "18/01/09" 54 > 2 "15/02/09" 65 > 2 "16/03/09" 77 > 2 "12/04/09" 7 > 2 "10/05/09" 6 > > > > > the start and end date of the time series for countries 1 and 2 are > different. For example, for country 1 the time series begins on > "23/11/08" while for country 2 the time series begins on "26-10-2008”. > > My data on prices are available every 28 days (or equivalently every 4 > weeks). But in some cases I have jumps (35 days or 29 days instead of > 28 days). For example from the above table we have such jumps: from > "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc > > My goal is to have a unified sequence of dates across countries. So, > to achieve this I want to apply the following solutions > > I want to take what I have and calculate monthly average prices and also > report how many prices those averages are based on. I suppose that I > will still have gaps and may well need to interpolate. > > Please, I would be grateful to you if you could provide the exact code > for doing this > > Here is a solution using zoo and aggregate.zoo: # dat is from Ken's post dat <- data.frame("country" = c(rep(1,8), rep(2, 8)), "date" = c("23/11/08","28/12/08","25/01/09","22/02/09", "29/03/09","26/04/09","24/05/09", "28/06/09", "26/10/08","23/11/08","21/12/08","18/01/09", "15/02/09","16/03/09","12/04/09","10/05/09"), "price" = c(2,3,4,5,6,32,23,32,45,46,90,54,65,77,7,6)) library(zoo) # split into columns by country z <- read.zoo(dat, index = 2, format = "%d/%m/%y", split = 1) # by month for each country aggregate(z, format(time(z), "%m"), mean, na.rm = TRUE) # by year and month for each country aggregate(z, as.yearmon, mean, na.rm = TRUE) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org 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] interpolation to montly data
Hi Ken, Stef, We can make your script more elegant like below: On Sun, Jun 17, 2012 at 12:52 AM, Ken wrote: > > stef salvez googlemail.com> writes: [snip] > #load library > library(plyr) > > # utility function > mean.var = function(df, var){ mean(df[[var]], na.rm = T)}; > > # create example data > dat <- data.frame("country" = c(rep(1,8), rep(2, 8)), > "date" = c("23/11/08","28/12/08","25/01/09","22/02/09", > "29/03/09","26/04/09","24/05/09", "28/06/09", > "26/10/08","23/11/08","21/12/08","18/01/09", > "15/02/09","16/03/09","12/04/09","10/05/09"), > "price" = c(2,3,4,5,6,32,23,32,45,46,90,54,65,77,7,6)) > # add month column to df > dat$month = substr(dat$date, 4,5) dat <- transform(dat, date=as.Date(date, "%d/%m/%y")) dat <- transform(dat, month=as.numeric(format(date, "%m"))) > > #calculate average price by month across all countries and calculate > monthly > #frequency and put output in one data frame > monthly.price = ddply(dat, .(month), mean.var, var = "price") > monthly.price = cbind(monthly.price, "month.freq" = > as.vector(table(df$month))) > names(monthly.price) = c("month", "average.price", "month.freq") # by country & month ddply(dat, .(country, month), function(x) c(avg.price=mean(x$price), freq=nrow(x))) # by country & year-month library(zoo) dat <- transform(dat, yearmon=as.yearmon(date)) ddply(dat, .(country, yearmon), function(x) c(avg.price=mean(x$price), freq=nrow(x))) Regards, - Jon __ R-help@r-project.org 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] interpolation to montly data
stef salvez googlemail.com> writes: > > I would like to clarify that since each observation is obtained every > 28 days, each such observation is a 4-week average > > thanks > > On 6/16/12, stef salvez googlemail.com> wrote: > > I have a panel data set (in MS excel) like the one below > > > > > > 1 "23/11/08"2 > > 1 "28/12/08" 3 > > 1"25/01/09" 4 > > 1 "22/02/09" 5 > > 1"29/03/09" 6 > > 1 "26/04/09" 32 > > 1 "24/05/09" 23 > > 1 "28/06/09" 32 > > 2 "26/10/08"45 > > 2 "23/11/08" 46 > > 2 "21/12/08" 90 > > 2 "18/01/09"54 > > 2 "15/02/09" 65 > > 2 "16/03/09" 77 > > 2 "12/04/09"7 > > 2 "10/05/09" 6 > > > > > > > > > > the start and end date of the time series for countries 1 and 2 are > > different. For example, for country 1 the time series begins on > > "23/11/08" while for country 2 the time series begins on "26-10-2008”. > > > > My data on prices are available every 28 days (or equivalently every 4 > > weeks). But in some cases I have jumps (35 days or 29 days instead of > > 28 days). For example from the above table we have such jumps: from > > "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc > > > > My goal is to have a unified sequence of dates across countries. So, > > to achieve this I want to apply the following solutions > > > > I want to take what I have and calculate monthly average prices and also > > report how many prices those averages are based on. I suppose that I > > will still have gaps and may well need to interpolate. > > > > Please, I would be grateful to you if you could provide the exact code > > for doing this > > > > > > thanks a lot > > > > __ > R-help r-project.org 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. > Hi Stef, I'm a little confused on how you want to break up the values in "4 week" bins, but if you wanted to keep it simple and do averages according to the month they fall in you could use the plyr package with a custom utility function: #load library library(plyr) # utility function mean.var = function(df, var){ mean(df[[var]], na.rm = T)}; # create example data dat <- data.frame("country" = c(rep(1,8), rep(2, 8)), "date" = c("23/11/08","28/12/08","25/01/09","22/02/09", "29/03/09","26/04/09","24/05/09", "28/06/09", "26/10/08","23/11/08","21/12/08","18/01/09", "15/02/09","16/03/09","12/04/09","10/05/09"), "price" = c(2,3,4,5,6,32,23,32,45,46,90,54,65,77,7,6)) # add month column to df dat$month = substr(dat$date, 4,5) #calculate average price by month across all countries and calculate monthly #frequency and put output in one data frame monthly.price = ddply(dat, .(month), mean.var, var = "price") monthly.price = cbind(monthly.price, "month.freq" = as.vector(table(df$month))) names(monthly.price) = c("month", "average.price", "month.freq") HTH, Ken __ R-help@r-project.org 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] interpolation to montly data
I would like to clarify that since each observation is obtained every 28 days, each such observation is a 4-week average thanks On 6/16/12, stef salvez wrote: > I have a panel data set (in MS excel) like the one below > > > 1 "23/11/08"2 > 1 "28/12/08" 3 > 1"25/01/09" 4 > 1 "22/02/09" 5 > 1"29/03/09" 6 > 1 "26/04/09" 32 > 1 "24/05/09" 23 > 1 "28/06/09" 32 > 2 "26/10/08"45 > 2 "23/11/08" 46 > 2 "21/12/08" 90 > 2 "18/01/09"54 > 2 "15/02/09" 65 > 2 "16/03/09" 77 > 2 "12/04/09"7 > 2 "10/05/09" 6 > > > > > the start and end date of the time series for countries 1 and 2 are > different. For example, for country 1 the time series begins on > "23/11/08" while for country 2 the time series begins on "26-10-2008”. > > My data on prices are available every 28 days (or equivalently every 4 > weeks). But in some cases I have jumps (35 days or 29 days instead of > 28 days). For example from the above table we have such jumps: from > "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc > > My goal is to have a unified sequence of dates across countries. So, > to achieve this I want to apply the following solutions > > I want to take what I have and calculate monthly average prices and also > report how many prices those averages are based on. I suppose that I > will still have gaps and may well need to interpolate. > > Please, I would be grateful to you if you could provide the exact code > for doing this > > > thanks a lot > __ R-help@r-project.org 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] interpolation to montly data
I have a panel data set (in MS excel) like the one below 1 "23/11/08"2 1 "28/12/08" 3 1"25/01/09" 4 1 "22/02/09" 5 1"29/03/09" 6 1 "26/04/09" 32 1 "24/05/09" 23 1 "28/06/09" 32 2 "26/10/08"45 2 "23/11/08" 46 2 "21/12/08" 90 2 "18/01/09"54 2 "15/02/09" 65 2 "16/03/09" 77 2 "12/04/09"7 2 "10/05/09" 6 the start and end date of the time series for countries 1 and 2 are different. For example, for country 1 the time series begins on "23/11/08" while for country 2 the time series begins on "26-10-2008”. My data on prices are available every 28 days (or equivalently every 4 weeks). But in some cases I have jumps (35 days or 29 days instead of 28 days). For example from the above table we have such jumps: from "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc My goal is to have a unified sequence of dates across countries. So, to achieve this I want to apply the following solutions I want to take what I have and calculate monthly average prices and also report how many prices those averages are based on. I suppose that I will still have gaps and may well need to interpolate. Please, I would be grateful to you if you could provide the exact code for doing this thanks a lot __ R-help@r-project.org 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] interpolation of climate data
Dear R-users, I am working on interpolating the station level temperature data to farm level data. I have z vector consisting of station level temperature observations and my x and y are latitude and longitude corresponding to a farm. My understanding is I can use raster combined with tps. While I am clear with the tps bit, I am not sure how I can construct the raster with teh data I have. Here is the reproducable example I made Many thanks in advance regards, Mintewab library(fields) x <-1:20 y<- runif(20) z<- c(11, 15, 17, 2, 18, 6, 7, NA, 12, 10,21, 25, 27, 12, 28, 16, 17, NA, 12, 10) mydataset<-data.frame(z, y, z) mydataset[complete.cases(mydataset),] tpsfit <- Tps(cbind(x, y), z, scale.type="unscaled") library(raster) r <- raster(system.file("external/test.grd", package="raster")) p <- raster(r) p <- interpolate(p, tpsfit) p <- mask(p, r) plot(p) se <- interpolate(p, tpsfit, fun=predict.se) se <- mask(se, r) plot(se) __ R-help@r-project.org 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] interpolation issue
On Wed, Apr 18, 2012 at 07:15:45AM -0700, uday wrote: > hi Petr , > Thanks for replay and sorry for typo mistake > approx(pres, sci.pre) its nothing but approx(pre2, pre1). > > so for more simplicity > x <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105, > 521.42712, 629.00446 ,729.95941, 827.86279, 921.55078, > 956.6) > y <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983, > 852.1671089, > 765.0037479,654.0372907, 526.7369169, 397.0581990, 279.9788079, > 229.5127059, > 185.2578164 ,147.2534510,115.1949457, 88.5712513, 66.7337287, > 49.0140828, > 23.3535195 , 0.6609724) > approx(x,y,xout=x,method="linear") > still I get error message > Error in xy.coords(x, y) : 'x' and 'y' lengths differ > > I saw the approx. function , but yet I do not know that how we can use that > for the data set which having different length Hi. Try to explain, what do you want to compute. A typical use of approx() needs three vectors. The first two have the same length and define a few points of a function, say f(x). The third vector is called "xout" and may have an arbitrary length. approx(x, y, xout) then computes an approximation of f() evaluated in the components of "xout". For, example x <- 1:4 y <- (1:4)^2 plot(x, y) xout <- runif(20, min=1, max=4) out <- approx(x=x, y=y, xout=xout) points(xout, out$y, pch=20) What do you want to compute, if you have only two vectors? Petr Savicky. __ R-help@r-project.org 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] interpolation issue
Your problem is that length(x) != length(y) approx uses linear interpolation but there's no way to make sense of that if you can't match up the x and y coordinates -- and you can't match up the x and y coordinates if there aren't the same number of them. Michael On Wed, Apr 18, 2012 at 10:15 AM, uday wrote: > hi Petr , > Thanks for replay and sorry for typo mistake > approx(pres, sci.pre) its nothing but approx(pre2, pre1). > > so for more simplicity > x <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105, > 521.42712, 629.00446 ,729.95941, 827.86279, 921.55078, > 956.6) > y <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983, > 852.1671089, > 765.0037479,654.0372907, 526.7369169, 397.0581990, 279.9788079, > 229.5127059, > 185.2578164 ,147.2534510,115.1949457, 88.5712513, 66.7337287, > 49.0140828, > 23.3535195 , 0.6609724) > approx(x,y,xout=x,method="linear") > still I get error message > Error in xy.coords(x, y) : 'x' and 'y' lengths differ > > I saw the approx. function , but yet I do not know that how we can use that > for the data set which having different length > > So I hope that my problem is bit more clear than before > > Cheers > Uday > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/interpolation-issue-tp4567362p4567826.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org 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@r-project.org 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] interpolation issue
hi Petr , Thanks for replay and sorry for typo mistake approx(pres, sci.pre) its nothing but approx(pre2, pre1). so for more simplicity x <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105, 521.42712, 629.00446 ,729.95941, 827.86279, 921.55078, 956.6) y <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983, 852.1671089, 765.0037479,654.0372907, 526.7369169, 397.0581990, 279.9788079, 229.5127059, 185.2578164 ,147.2534510,115.1949457, 88.5712513, 66.7337287, 49.0140828, 23.3535195 , 0.6609724) approx(x,y,xout=x,method="linear") still I get error message Error in xy.coords(x, y) : 'x' and 'y' lengths differ I saw the approx. function , but yet I do not know that how we can use that for the data set which having different length So I hope that my problem is bit more clear than before Cheers Uday -- View this message in context: http://r.789695.n4.nabble.com/interpolation-issue-tp4567362p4567826.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] interpolation issue
On Wed, Apr 18, 2012 at 03:55:07AM -0700, uday wrote: > This moment I got stuck with one interpolation issue > the sample data which I have is as follows > > pre1 <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105, > 521.42712, 629.00446 ,729.95941,827.86279, > 921.55078, 956.6) > pre2 <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983, > 852.1671089, 765.0037479, 654.0372907, > 526.7369169, 397.0581990, 279.9788079, 229.5127059,185.2578164 ,147.2534510 > ,115.1949457, 88.5712513, 66.7337287, 49.0140828, 23.3535195 , > 0.6609724) > > I have tried approx function > approx(pres, sci.pre) > Error in xy.coords(x, y) : 'x' and 'y' lengths differ Hi. What is "pres" and "sci.pre"? Probably, they are vectors of different lengths and they were interpreted as "x" and "y" in approx(), see ?approx. If "sci.pre" should be "xout" in approx(), then you have to specify some "y". The vectors "pre1" and "pre2" have lengths 12 and 20, but their relationshiop to "pres" and "sci.pre" is not clear. Petr Savicky. __ R-help@r-project.org 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] interpolation issue
This moment I got stuck with one interpolation issue the sample data which I have is as follows pre1 <- c(10.34615 , 52.02116, 146.17357, 243.28644, 347.41504, 431.67105, 521.42712, 629.00446 ,729.95941,827.86279, 921.55078, 956.6) pre2 <- c( 983.4477692, 973.6199013, 958.0722141, 938.8194208 ,915.1833983, 852.1671089, 765.0037479, 654.0372907, 526.7369169, 397.0581990, 279.9788079, 229.5127059,185.2578164 ,147.2534510 ,115.1949457, 88.5712513, 66.7337287, 49.0140828, 23.3535195 , 0.6609724) I have tried approx function approx(pres, sci.pre) Error in xy.coords(x, y) : 'x' and 'y' lengths differ I am looking for interpolated output with 1 x 19 demotions . does somebody knows how to deal with this issue ? Thanks Uday -- View this message in context: http://r.789695.n4.nabble.com/interpolation-issue-tp4567362p4567362.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] interpolation and extremum location of a surface
On Jun 1, 2011, at 9:24 AM, Clement LAUZIN wrote: Hello, I have a x,y,z file.Z is not corresponding to a simple analytical function of x and y (see below). I am trying to find the minimum location of this surface and the z value corresponding to this location by a spline interpolation or from a polynomial fit. I tried with the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not giving any answer. I do not think that is the reason akima::interp is failing. (For one thing the minimum is not outside the convex hull of x and y.) Note that the help page says that x and y cannot be collinear but yours appear to be so. > table(ZZ$x) 4.05 4.1 4.15 4.2 4.25 4.3 4.35 5555555 > table(ZZ$y) 60 67.5 75 82.5 90 77777 I took a shot at jittering the x and y and reapplying interpp ... and ended up with what appeared to be useless junk. If you look at the data with contourplot you can see it would place the minimum at around z=-175 at x=4.24, y=67. However, the contourplot and associated help pages say there is no documentation for the algorithm used. contourplot(z ~ x + y, data=ZZ, at=seq(-140, -180 , by= -0.5), interp=TRUE) If someone has any idea or any suggestion? Thank you in advance Pierre xyz 4.1 60 -152.1719593 4.1 75 -171.136801 4.1 90 -170.4604774 4.2 60 -168.7745552 4.2 75 -174.9667333 4.2 90 -172.1853334 4.3 60 -173.7736418 4.3 75 -171.6712745 4.3 90 -167.6662458 4.05 60 -137.8379387 4.15 60 -162.2264066 4.25 60 -172.4453286 4.35 60 -173.2123715 4.05 67.5 -158.8239625 4.1 67.5 -167.314534 4.15 67.5 -172.586182 4.2 67.5 -175.2217594 4.25 67.5 -175.7162683 4.3 67.5 -174.4890566 4.35 67.5 -171.8940061 4.05 75 -165.4388778 4.15 75 -174.1460392 4.25 75 -174.022344 4.35 75 -168.2149168 4.05 82.5 -166.4026077 4.1 82.5 -170.9199652 4.15 82.5 -172.9923449 4.2 82.5 -173.0803255 4.25 82.5 -171.5739101 4.3 82.5 -168.8024715 4.35 82.5 -165.0431276 4.05 90 -166.2592978 4.15 90 -172.2861302 4.25 90 -170.5383652 4.35 90 -163.8389615 __ R-help@r-project.org 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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org 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] interpolation and extremum location of a surface
Clement LAUZIN hotmail.com> writes: > Hello, > > Hello, > > I have a x,y,z file.Z is not corresponding to a simple analytical function > of x and y (see below). I am trying to find the minimum location of this > surface and the z value corresponding to this location by a spline > interpolation or from a polynomial fit. I tried with the akima package but > as the location of the point I am looking for (the minimum) is outside of > the convex hull it's not giving any answer. > If someone has any idea or any suggestion? > > Thank you in advance Pierre According to a 2-dimensional barycentric Lagrange interpolation that I am implementing right now in R, the minimum appears to be at x0 = (4.230490, 68.52776); fval = -175.7959 I certainly would be interested to hear from other reasonable locations of a minimum, as this may be a good test case. -- Hans Werner > xyz > 4.1 60 -152.1719593 > [ ... ] > 4.35 90 -163.8389615 > __ R-help@r-project.org 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] interpolation and extremum location of a surface
Hello, I have a x,y,z file.Z is not corresponding to a simple analytical function of x and y (see below). I am trying to find the minimum location of this surface and the z value corresponding to this location by a spline interpolation or from a polynomial fit. I tried with the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not giving any answer. If someone has any idea or any suggestion? Thank you in advance Pierre xyz 4.1 60 -152.1719593 4.1 75 -171.136801 4.1 90 -170.4604774 4.2 60 -168.7745552 4.2 75 -174.9667333 4.2 90 -172.1853334 4.3 60 -173.7736418 4.3 75 -171.6712745 4.3 90 -167.6662458 4.05 60 -137.8379387 4.15 60 -162.2264066 4.25 60 -172.4453286 4.35 60 -173.2123715 4.05 67.5 -158.8239625 4.1 67.5 -167.314534 4.15 67.5 -172.586182 4.2 67.5 -175.2217594 4.25 67.5 -175.7162683 4.3 67.5 -174.4890566 4.35 67.5 -171.8940061 4.05 75 -165.4388778 4.15 75 -174.1460392 4.25 75 -174.022344 4.35 75 -168.2149168 4.05 82.5 -166.4026077 4.1 82.5 -170.9199652 4.15 82.5 -172.9923449 4.2 82.5 -173.0803255 4.25 82.5 -171.5739101 4.3 82.5 -168.8024715 4.35 82.5 -165.0431276 4.05 90 -166.2592978 4.15 90 -172.2861302 4.25 90 -170.5383652 4.35 90 -163.8389615 __ R-help@r-project.org 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] interpolation and extremum location of a surface
Hello, I have a x,y,z file. Z is not corresponding to a simple analytical function of x and y. I am trying to find the minimum value of z by a spline interpolation or from a polynomial fit. I tried the akima package but as the location of the point I am looking for (the minimum) is outside of the convex hull it's not working. If someone has any idea or any suggestion? Thank you in advance Pierre __ R-help@r-project.org 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] Interpolation
Hi: Look into the na.approx() function in package zoo. The discussion below may be of help: http://r.789695.n4.nabble.com/Filling-in-missing-time-samples-with-na-approx-td3063682.html HTH, Dennis On Wed, Jan 5, 2011 at 10:17 PM, Rustamali Manesiya wrote: > Hello, > > > I am new to R and need some help. > > I have data in following format > > DATA matrix > > DateTime oh l c > 2009-01-01 07:30:00 2 3 4 5 > 2009-01-01 07:33:00 4 2 5 7 > > I am able to fill the gap using combination of seq and chron > 2009-01-01 07:30:00 > 2009-01-01 07:31:00 > 2009-01-01 07:32:00 > 2009-01-01 07:33:00 > > x <- as.numeric(index(DATA[,1])) > y <- x + 100 > zz <- seq(x,y,1) > > How can I refill a new matrix with the values from the corresponding values > So the data should look like this and then I can apply interpolation on > this > data. > DateTime oh l c > 2009-01-01 07:30:00 2 3 4 5 > 2009-01-01 07:31:00 NA NA NA NA > 2009-01-01 07:32:00 NA NA NA NA > 2009-01-01 07:33:00 4 2 5 7 > > Or is there a short cut to do direct linear interpolation on the original > data matrix? > > Rusty > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org 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. > [[alternative HTML version deleted]] __ R-help@r-project.org 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] Interpolation
Hello, I am new to R and need some help. I have data in following format DATA matrix DateTime oh l c 2009-01-01 07:30:00 2 3 4 5 2009-01-01 07:33:00 4 2 5 7 I am able to fill the gap using combination of seq and chron 2009-01-01 07:30:00 2009-01-01 07:31:00 2009-01-01 07:32:00 2009-01-01 07:33:00 x <- as.numeric(index(DATA[,1])) y <- x + 100 zz <- seq(x,y,1) How can I refill a new matrix with the values from the corresponding values So the data should look like this and then I can apply interpolation on this data. DateTime oh l c 2009-01-01 07:30:00 2 3 4 5 2009-01-01 07:31:00 NA NA NA NA 2009-01-01 07:32:00 NA NA NA NA 2009-01-01 07:33:00 4 2 5 7 Or is there a short cut to do direct linear interpolation on the original data matrix? Rusty [[alternative HTML version deleted]] __ R-help@r-project.org 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] Interpolation missing data
try packages: {yaImpute}, {impute}, etc. -- View this message in context: http://r.789695.n4.nabble.com/Interpolation-missing-data-tp2530871p2531288.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Interpolation missing data
Hi R experts, I have set of data consists of 50 data. some of them are missing. I would need a function in R that can estimate missing data using interpolation methods. If you know this kind of function, write me the name of the function and its library. Thanks very much in advance! abotaha -- View this message in context: http://r.789695.n4.nabble.com/Interpolation-missing-data-tp2530871p2530871.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Interpolation
The warning message simply indicates that you have more than one data point with the same "x" value. So, `approx' collapses over the dulicate x values by averaging the corresponding "y" values. I am not sure if this is your problem - it doesn't seem like it. It is doing what seems reasonable for a linear interpolation. If you have some idea of how the interpolation should look like, you may fit a model to the data and impute based on the model. Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ogbos okike Sent: Thursday, January 28, 2010 12:30 PM To: r-help@r-project.org Subject: [R] Interpolation Happy New Year. I have a data of four columns - year, month, day and count. The last column, count, contains some missing data which I have to replace with NA. I tried to use the method of interpolation to assign some values to these NA so that the resulting plot will be better. I used x to represent date and y to represent count. With the method below, I tried to interpolate on the NA's, but that resulted in the warning message below. I went ahead and plotted the graph of date against count (plot attached). The diagonal line between May and Jul is not looking good and I suspect that it is the result of the warning message. It would be appreciated if anybody could give me some help. Warmest regards Ogbos > y1<-approx(x,y,xout = x)$y Warning message: In approx(x, y, xout = x) : collapsing to unique 'x' values __ R-help@r-project.org 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] Interpolation
Why not look into the zoo package na.approx? And related functions. On Thu, Jan 28, 2010 at 11:29 AM, ogbos okike wrote: > Happy New Year. > I have a data of four columns - year, month, day and count. The last column, > count, contains some missing data which I have to replace with NA. I tried > to use the method of interpolation to assign some values to these NA so that > the resulting plot will be better. I used x to represent date and y to > represent count. With the method below, I tried to interpolate on the NA's, > but that resulted in the warning message below. I went ahead and plotted the > graph of date against count (plot attached). The diagonal line between May > and Jul is not looking good and I suspect that it is the result of the > warning message. > It would be appreciated if anybody could give me some help. > Warmest regards > Ogbos >> y1<-approx(x,y,xout = x)$y > Warning message: > In approx(x, y, xout = x) : collapsing to unique 'x' values > > __ > R-help@r-project.org 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. > > -- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ R-help@r-project.org 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] interpolation
On Jan 11, 2010, at 11:49 AM, René Mayer wrote: My problem is that x values increas with y x is mostly decreasing in the order you presented: plot(x, type="l") until some point then the pattern reverses. The whole line which line? is a kind of U-shape with a right-buttom to middel-top diagonal at the end of it (a look at the plot The starting values of x are the ones at the "top" of the plot you suggested. makes it clearer). The interpolation (approx, spline) makes a zick- zack aut of it. What I need is to interpolate some points which points? ... and as a function of what? You plotted x as a function of y. Are you interested in an approximation of the last 9 points where the mathematical definition of a "function" of one variable in terms of one other variable might have meaning. At most other points you don't really have a function (unless you make a two dimensional parametric function of z) because there are two values of x for each value of y. Your question asked for an approximation of y as a function of x over a range (1:600) where that is not particularly sensible.. If you want segments over that range success might be possible, but you need to clarify what you want and how the program is supposed to figure out which leg of the segment you desire when there are two possible values of y. -- David and to preserve the shape. thanks in andvance René Zitat von "David Winsemius" : On Jan 11, 2010, at 7:44 AM, René Mayer wrote: Dear R-users, I have a complex line by xy-values (ordered by z). And I would like to get interpolated y-values on the positions of x = 0:600. How do I get the correct points? x = c (790,790,790,790,790,786,783,778,778,766,763,761,761,761,715,628,521,350,160,134,134,129,108,101,93,111,161,249,288,243,139,45,7 ) y = c (606,606,606,606,606,612,617,627,627,640,641,641,641,641,689,772,877,1048,1240,1272,1272,1258,1242,1239,1239,1214,1122,959,770,479,273,133,45 ) z = c (0,29,58,87,116,145,174,203,232,261,290,319,348,377,406,435,464,493,522,551,580,609,638,667,696,725,754,783,812,841,870,899,928 ) plot(y,x,type="b") That would plot x as a function of y (the reverse of the usual convention. Is that what you want. If so, then the statement that these are ordered by z is misleading. Ordering by z would suggest that each series is a function of z. What sort of interpolation do you want and in how many dimensions? # this fails ? lines(approx(y,x),col="blue") # with xout = c(0:600) thanks in advance, René -- Dr. rer. nat. Dipl.-Psych. René Mayer Dresden University of Technology Department of Psychology Zellescher Weg 17 D-01062 Dresden Tel.: +49-351-4633-4568 Email: ma...@psychologie.tu-dresden.de __ R-help@r-project.org 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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] interpolation
My problem is that x values increas with y until some point then the pattern reverses. The whole line is a kind of U-shape with a right-buttom to middel-top diagonal at the end of it (a look at the plot makes it clearer). The interpolation (approx, spline) makes a zick-zack aut of it. What I need is to interpolate some points and to preserve the shape. thanks in andvance René Zitat von "David Winsemius" : On Jan 11, 2010, at 7:44 AM, René Mayer wrote: Dear R-users, I have a complex line by xy-values (ordered by z). And I would like to get interpolated y-values on the positions of x = 0:600. How do I get the correct points? x=c(790,790,790,790,790,786,783,778,778,766,763,761,761,761,715,628,521,350,160,134,134,129,108,101,93,111,161,249,288,243,139,45,7) y=c(606,606,606,606,606,612,617,627,627,640,641,641,641,641,689,772,877,1048,1240,1272,1272,1258,1242,1239,1239,1214,1122,959,770,479,273,133,45) z=c(0,29,58,87,116,145,174,203,232,261,290,319,348,377,406,435,464,493,522,551,580,609,638,667,696,725,754,783,812,841,870,899,928) plot(y,x,type="b") That would plot x as a function of y (the reverse of the usual convention. Is that what you want. If so, then the statement that these are ordered by z is misleading. Ordering by z would suggest that each series is a function of z. What sort of interpolation do you want and in how many dimensions? # this fails ? lines(approx(y,x),col="blue") # with xout = c(0:600) thanks in advance, René -- Dr. rer. nat. Dipl.-Psych. René Mayer Dresden University of Technology Department of Psychology Zellescher Weg 17 D-01062 Dresden Tel.: +49-351-4633-4568 Email: ma...@psychologie.tu-dresden.de __ R-help@r-project.org 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] interpolation
On Jan 11, 2010, at 7:44 AM, René Mayer wrote: Dear R-users, I have a complex line by xy-values (ordered by z). And I would like to get interpolated y-values on the positions of x = 0:600. How do I get the correct points? x = c (790,790,790,790,790,786,783,778,778,766,763,761,761,761,715,628,521,350,160,134,134,129,108,101,93,111,161,249,288,243,139,45,7 ) y = c (606,606,606,606,606,612,617,627,627,640,641,641,641,641,689,772,877,1048,1240,1272,1272,1258,1242,1239,1239,1214,1122,959,770,479,273,133,45 ) z = c (0,29,58,87,116,145,174,203,232,261,290,319,348,377,406,435,464,493,522,551,580,609,638,667,696,725,754,783,812,841,870,899,928 ) plot(y,x,type="b") That would plot x as a function of y (the reverse of the usual convention. Is that what you want. If so, then the statement that these are ordered by z is misleading. Ordering by z would suggest that each series is a function of z. What sort of interpolation do you want and in how many dimensions? # this fails ? lines(approx(y,x),col="blue") # with xout = c(0:600) thanks in advance, René -- Dr. rer. nat. Dipl.-Psych. René Mayer Dresden University of Technology Department of Psychology Zellescher Weg 17 D-01062 Dresden Tel.: +49-351-4633-4568 Email: ma...@psychologie.tu-dresden.de __ R-help@r-project.org 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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] interpolation
Dear R-users, I have a complex line by xy-values (ordered by z). And I would like to get interpolated y-values on the positions of x = 0:600. How do I get the correct points? x=c(790,790,790,790,790,786,783,778,778,766,763,761,761,761,715,628,521,350,160,134,134,129,108,101,93,111,161,249,288,243,139,45,7) y=c(606,606,606,606,606,612,617,627,627,640,641,641,641,641,689,772,877,1048,1240,1272,1272,1258,1242,1239,1239,1214,1122,959,770,479,273,133,45) z=c(0,29,58,87,116,145,174,203,232,261,290,319,348,377,406,435,464,493,522,551,580,609,638,667,696,725,754,783,812,841,870,899,928) plot(y,x,type="b") # this fails ? lines(approx(y,x),col="blue") # with xout = c(0:600) thanks in advance, René -- Dr. rer. nat. Dipl.-Psych. René Mayer Dresden University of Technology Department of Psychology Zellescher Weg 17 D-01062 Dresden Tel.: +49-351-4633-4568 Email: ma...@psychologie.tu-dresden.de __ R-help@r-project.org 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] Interpolation
Hi R community I need to interpolate precipitation data for a natural park. I have precipitation data from some climate stationts. (I know the table is not complete but I only need to show you X,Y, Altitude and PrepJul) X Y Altitude PrepJan PrepFeb PrepMar PrepAp PrepMay PrepJun PrepJul 597706 4093438 41 0 9 77,8 63,1 17,5 0 2,6 597535 4088967 202 0 11,3 67,9 70,8 12,1 0 0,6 572307 4064892 41 1 9,5 22 40,5 2,5 0 0 571059 4074743 50 2,4 13,9 31,3 63,3 8,1 0 1,4 570795 4091537 356 0 15 79 86 19,5 1 0 554563 4077703 20 5,2 15,6 43,4 64,5 15 0,2 0 575091 4089921 183 1,2 13,2 64,6 70,6 16,2 0,2 3,4 The area where this data must be interpolated in the natural park with an irregular shape inside of a grid of 2190 lines and 2282 columns with utm coordinates. I have tried "Krig" from "fields" package. A created a matrix with independant data (a) and a vector with dependant data (b). a<-matrix(c(clima$X,clima$Y,clima$Altitud),,3) b<-clima$PrepJul Interpolation<-Krig(a,b) mapa<-predict.surface(interpolacion, nx=2190, ny=2282) str(mapa) num [1:2190] 554563 554583 554602 554622 554642 ... $ y: num [1:2282] 4064892 4064905 4064917 4064930 4064942 ... $ z: num [1:2190, 1:2282] NA NA NA NA NA NA NA NA NA NA ... NA values are due to the fact that outside of the natural park there isn't precipitation registred. NA values are not a problem. I write the result to ENVI with "write.ENVI" from "Catools" package. And the result is an image but data interpolated don't follow the natural park limits, the image of interpolated data don't macht the area of the natural park. And I don't know how to solve this. If anyone know any possible reason or any suggestion to do an interpolation, I would be really grateful. Lucas _ [[alternative HTML version deleted]] __ R-help@r-project.org 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] interpolation to abscissa
It appears the answer to your goal after a discursive exploration of "interpolation", which was really extrapolation, is that you need to look at the predict methods for linear (and other sorts as well) models. ?predict ?predict.lm > y <- c(16,45,77,101,125) > x <- c(0,5,10,15,20) > > lmmod <- lm(y ~ x) > plot(x,y, ylim = c(0,125), xlim =c(-4,22)) #defaults would not allow estimates from plot > lines(x=seq(-4,22, by=.5), y=predict(lm(y ~ x), newdata = data.frame(x = seq(-4,22, by=. 5) ) ) ) -- David Winsemius On Jan 15, 2009, at 11:31 AM, e-letter wrote: snipped preceding excursion __ R-help@r-project.org 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] interpolation to abscissa
On Jan 15, 2009, at 11:31 AM, e-letter wrote: Perhaps a coding error on my part (or on your part). Perhaps different methods (none of which you describe)? I suspect that my method only used the first two points (I just checked by plotting and -2.7 is closer to the paper and pen result I get than is -3.28. Perhaps you made an extrapolation from a linear fit of a dataset that is not co-linear? lm(c(0,5) ~ c(16,45)) Call: lm(formula = c(0, 5) ~ c(16, 45)) Coefficients: (Intercept)c(16, 45) -2.7586 0.1724 It not that "R is different", it is merely that I used it differently than you used your other tools. Here's another method ( using all points and again reversing the roles of x and y) : lm(c(0,5,10,15,20) ~ c(16,45,77,101,125)) Call: lm(formula = c(0, 5, 10, 15, 20) ~ c(16, 45, 77, 101, 125)) Coefficients: (Intercept) c(16, 45, 77, 101, 125) -3.2332 0.1818 My understanding from gnuplot manual is that a marquart-levenberg algorithm is used, which I applied to the data to perform a least squares best fit linear curve. Gnuplot returns values for the intercept and gradient which I then apply to solve the linear equation y=mx+c. Similarly with scilab, where the regress(ion?) function was applied. Qtiplot performed non-weighted linear regression to output values similar to those from gnuplot. Why reverse the roles of x and y in your method? I accidentally switched x and y ad then realized I could get an intercept value without the labor of solving by hand. Although your revised value is closer to those from other programs, how do I understand and explain the discrepancy? The regression line for x ~ y is *not* the same as the regression line for y ~ x. If you want to check that the numbers from R agree with your other solutions, then take the regression equation from > lmmod Call: lm(formula = c(16, 45, 77, 101, 125) ~ c(0, 5, 10, 15, 20)) Coefficients: (Intercept) c(0, 5, 10, 15, 20) 18.00 5.48 ... and then solve for x = 0 as you apparently did with the other systems. -- David Winsemius __ R-help@r-project.org 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] interpolation to abscissa
> Perhaps a coding error on my part (or on your part). Perhaps different > methods (none of which you describe)? > > I suspect that my method only used the first two points (I just > checked by plotting and -2.7 is closer to the paper and pen result I > get than is -3.28. Perhaps you made an extrapolation from a linear fit > of a dataset that is not co-linear? > > > lm(c(0,5) ~ c(16,45)) > > Call: > lm(formula = c(0, 5) ~ c(16, 45)) > > Coefficients: > (Intercept)c(16, 45) > -2.7586 0.1724 > > It not that "R is different", it is merely that I used it differently > than you used your other tools. > > Here's another method ( using all points and again reversing the roles > of x and y) : > > lm(c(0,5,10,15,20) ~ c(16,45,77,101,125)) > > Call: > lm(formula = c(0, 5, 10, 15, 20) ~ c(16, 45, 77, 101, 125)) > > Coefficients: > (Intercept) c(16, 45, 77, 101, 125) > -3.2332 0.1818 My understanding from gnuplot manual is that a marquart-levenberg algorithm is used, which I applied to the data to perform a least squares best fit linear curve. Gnuplot returns values for the intercept and gradient which I then apply to solve the linear equation y=mx+c. Similarly with scilab, where the regress(ion?) function was applied. Qtiplot performed non-weighted linear regression to output values similar to those from gnuplot. Why reverse the roles of x and y in your method? Although your revised value is closer to those from other programs, how do I understand and explain the discrepancy? __ R-help@r-project.org 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] interpolation to abscissa
On Jan 15, 2009, at 10:04 AM, e-letter wrote: On 13/01/2009, David Winsemius wrote: It's fairly clear from the documentation that approxfun() will not extrapolate. help.search("extrapolate") library(Hmisc) ?approxExtrap Some sort of minimization approach: approxExtrap(x=c(0,5,10,15,20), y=c(16,45,77,101,125),xout=c(-4,0,4)) $x [1] -4 0 4 $y [1] -7.2 16.0 39.2 approxExtrap(x=c(0,5,10,15,20), y=c(16,45,77,101,125),xout=seq(-2.8,-2.6, by=0.01)) $x [1] -2.80 -2.79 -2.78 -2.77 -2.76 -2.75 -2.74 -2.73 -2.72 -2.71 -2.70 -2.69 -2.68 [14] -2.67 -2.66 -2.65 -2.64 -2.63 -2.62 -2.61 -2.60 $y [1] -0.240 -0.182 -0.124 -0.066 -0.008 0.050 0.108 0.166 0.224 0.282 0.340 [12] 0.398 0.456 0.514 0.572 0.630 0.688 0.746 0.804 0.862 0.920 How accurate do you need the answer? I tried Hmisc's inverseFunction(), but it returned 0 for an argument of zero: invF <- inverseFunction(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) invF(0) So I then hacked Harrell's inverseFunction by substituting approxExtrap in every in instance where approx appeared, creating invFunc2: then invF <- invFunc2(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) invF(0) [1] -2.758621 I have compared your answer to those obtained from gnuplot, scilab and qtiplot; all report a result of x=-3.28. Why is r different? Perhaps a coding error on my part (or on your part). Perhaps different methods (none of which you describe)? I suspect that my method only used the first two points (I just checked by plotting and -2.7 is closer to the paper and pen result I get than is -3.28. Perhaps you made an extrapolation from a linear fit of a dataset that is not co-linear? > lm(c(0,5) ~ c(16,45)) Call: lm(formula = c(0, 5) ~ c(16, 45)) Coefficients: (Intercept)c(16, 45) -2.7586 0.1724 It not that "R is different", it is merely that I used it differently than you used your other tools. Here's another method ( using all points and again reversing the roles of x and y) : > lm(c(0,5,10,15,20) ~ c(16,45,77,101,125)) Call: lm(formula = c(0, 5, 10, 15, 20) ~ c(16, 45, 77, 101, 125)) Coefficients: (Intercept) c(16, 45, 77, 101, 125) -3.2332 0.1818 __ R-help@r-project.org 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@r-project.org 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] interpolation to abscissa
On 13/01/2009, David Winsemius wrote: > It's fairly clear from the documentation that approxfun() will not > extrapolate. > > help.search("extrapolate") > library(Hmisc) > ?approxExtrap > > Some sort of minimization approach: > > > approxExtrap(x=c(0,5,10,15,20), y=c(16,45,77,101,125),xout=c(-4,0,4)) > $x > [1] -4 0 4 > > $y > [1] -7.2 16.0 39.2 > > > approxExtrap(x=c(0,5,10,15,20), > y=c(16,45,77,101,125),xout=seq(-2.8,-2.6, by=0.01)) > $x > [1] -2.80 -2.79 -2.78 -2.77 -2.76 -2.75 -2.74 -2.73 -2.72 -2.71 > -2.70 -2.69 -2.68 > [14] -2.67 -2.66 -2.65 -2.64 -2.63 -2.62 -2.61 -2.60 > > $y > [1] -0.240 -0.182 -0.124 -0.066 -0.008 0.050 0.108 0.166 0.224 > 0.282 0.340 > [12] 0.398 0.456 0.514 0.572 0.630 0.688 0.746 0.804 0.862 > 0.920 > > How accurate do you need the answer? > > I tried Hmisc's inverseFunction(), but it returned 0 for an argument > of zero: > > > invF <- inverseFunction(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) > > invF(0) > > So I then hacked Harrell's inverseFunction by substituting > approxExtrap in every in instance > where approx appeared, creating invFunc2: > > then > > > invF <- invFunc2(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) > > > > invF(0) > [1] -2.758621 I have compared your answer to those obtained from gnuplot, scilab and qtiplot; all report a result of x=-3.28. Why is r different? __ R-help@r-project.org 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] interpolation to abscissa
It's fairly clear from the documentation that approxfun() will not extrapolate. help.search("extrapolate") library(Hmisc) ?approxExtrap Some sort of minimization approach: > approxExtrap(x=c(0,5,10,15,20), y=c(16,45,77,101,125),xout=c(-4,0,4)) $x [1] -4 0 4 $y [1] -7.2 16.0 39.2 > approxExtrap(x=c(0,5,10,15,20), y=c(16,45,77,101,125),xout=seq(-2.8,-2.6, by=0.01)) $x [1] -2.80 -2.79 -2.78 -2.77 -2.76 -2.75 -2.74 -2.73 -2.72 -2.71 -2.70 -2.69 -2.68 [14] -2.67 -2.66 -2.65 -2.64 -2.63 -2.62 -2.61 -2.60 $y [1] -0.240 -0.182 -0.124 -0.066 -0.008 0.050 0.108 0.166 0.224 0.282 0.340 [12] 0.398 0.456 0.514 0.572 0.630 0.688 0.746 0.804 0.862 0.920 How accurate do you need the answer? I tried Hmisc's inverseFunction(), but it returned 0 for an argument of zero: > invF <- inverseFunction(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) > invF(0) So I then hacked Harrell's inverseFunction by substituting approxExtrap in every in instance where approx appeared, creating invFunc2: then > invF <- invFunc2(x=c(0,5,10,15,20), y=c(16,45,77,101,125)) > > invF(0) [1] -2.758621 -- David Winsemius On Jan 13, 2009, at 10:57 AM, e-letter wrote: What is the problem that you are trying to solve? From the data I provided: x=c(0,5,10,15,20) y=c(16,45,77,101,125); I want to obtain the value of x when y=0. __ R-help@r-project.org 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@r-project.org 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] interpolation to abscissa
> > What is the problem that you are trying to solve? > >From the data I provided: x=c(0,5,10,15,20) y=c(16,45,77,101,125); I want to obtain the value of x when y=0. __ R-help@r-project.org 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] interpolation to abscissa
approxfun returns a function; that is not an error message: > x=c(0,5,10,15,20) > y=c(16,45,77,101,125) > > approx(x,y,method="linear") $x [1] 0.000 0.4081633 0.8163265 1.2244898 1.6326531 2.0408163 2.4489796 2.8571429 3.2653061 [10] 3.6734694 4.0816327 4.4897959 4.8979592 5.3061224 5.7142857 6.1224490 6.5306122 6.9387755 [19] 7.3469388 7.7551020 8.1632653 8.5714286 8.9795918 9.3877551 9.7959184 10.2040816 10.6122449 [28] 11.0204082 11.4285714 11.8367347 12.2448980 12.6530612 13.0612245 13.4693878 13.8775510 14.2857143 [37] 14.6938776 15.1020408 15.5102041 15.9183673 16.3265306 16.7346939 17.1428571 17.5510204 17.9591837 [46] 18.3673469 18.7755102 19.1836735 19.5918367 20.000 $y [1] 16.0 18.36735 20.73469 23.10204 25.46939 27.83673 30.20408 32.57143 34.93878 37.30612 [11] 39.67347 42.04082 44.40816 46.95918 49.57143 52.18367 54.79592 57.40816 60.02041 62.63265 [21] 65.24490 67.85714 70.46939 73.08163 75.69388 77.97959 79.93878 81.89796 83.85714 85.81633 [31] 87.77551 89.73469 91.69388 93.65306 95.61224 97.57143 99.53061 101.48980 103.44898 105.40816 [41] 107.36735 109.32653 111.28571 113.24490 115.20408 117.16327 119.12245 121.08163 123.04082 125.0 > > z <- approxfun(x,y) > z(0) [1] 16 > z(12) [1] 86.6 > On Tue, Jan 13, 2009 at 9:22 AM, e-letter wrote: > On 08/01/2009, Greg Snow wrote: >> If you want to just linearly interpolate, then use the functions approx or >> approxfun from the stats package (one of those that is loaded by default). > I have read the guide for approx and approxfun functions. Below is my data. > > x=c(0,5,10,15,20) > y=c(16,45,77,101,125) > > approx(x,y,method="linear") > $x > [1] 0.000 0.4081633 0.8163265 1.2244898 1.6326531 2.0408163 > [7] 2.4489796 2.8571429 3.2653061 3.6734694 4.0816327 4.4897959 > [13] 4.8979592 5.3061224 5.7142857 6.1224490 6.5306122 6.9387755 > [19] 7.3469388 7.7551020 8.1632653 8.5714286 8.9795918 9.3877551 > [25] 9.7959184 10.2040816 10.6122449 11.0204082 11.4285714 11.8367347 > [31] 12.2448980 12.6530612 13.0612245 13.4693878 13.8775510 14.2857143 > [37] 14.6938776 15.1020408 15.5102041 15.9183673 16.3265306 16.7346939 > [43] 17.1428571 17.5510204 17.9591837 18.3673469 18.7755102 19.1836735 > [49] 19.5918367 20.000 > > $y > [1] 16.0 18.36735 20.73469 23.10204 25.46939 27.83673 30.20408 > [8] 32.57143 34.93878 37.30612 39.67347 42.04082 44.40816 46.95918 > [15] 49.57143 52.18367 54.79592 57.40816 60.02041 62.63265 65.24490 > [22] 67.85714 70.46939 73.08163 75.69388 77.97959 79.93878 81.89796 > [29] 83.85714 85.81633 87.77551 89.73469 91.69388 93.65306 95.61224 > [36] 97.57143 99.53061 101.48980 103.44898 105.40816 107.36735 109.32653 > [43] 111.28571 113.24490 115.20408 117.16327 119.12245 121.08163 123.04082 > [50] 125.0 > > So my task is to find the value of x when y=0. I couldn't find > guidance to use the xout function; any help with this please? > > approxfun(x,y,rule=2,method="linear") > function (v) > .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), >as.integer(length(v)), as.integer(method), as.double(yleft), >as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout > > > Where do I go to find out the meaning of these errors and how to resolve? > > Yours, > > rh...@conference.jabber.org > > r 251 (27-06-07) > mandriva 2008 > > __ > R-help@r-project.org 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org 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] interpolation to abscissa
On 08/01/2009, Greg Snow wrote: > If you want to just linearly interpolate, then use the functions approx or > approxfun from the stats package (one of those that is loaded by default). I have read the guide for approx and approxfun functions. Below is my data. x=c(0,5,10,15,20) y=c(16,45,77,101,125) approx(x,y,method="linear") $x [1] 0.000 0.4081633 0.8163265 1.2244898 1.6326531 2.0408163 [7] 2.4489796 2.8571429 3.2653061 3.6734694 4.0816327 4.4897959 [13] 4.8979592 5.3061224 5.7142857 6.1224490 6.5306122 6.9387755 [19] 7.3469388 7.7551020 8.1632653 8.5714286 8.9795918 9.3877551 [25] 9.7959184 10.2040816 10.6122449 11.0204082 11.4285714 11.8367347 [31] 12.2448980 12.6530612 13.0612245 13.4693878 13.8775510 14.2857143 [37] 14.6938776 15.1020408 15.5102041 15.9183673 16.3265306 16.7346939 [43] 17.1428571 17.5510204 17.9591837 18.3673469 18.7755102 19.1836735 [49] 19.5918367 20.000 $y [1] 16.0 18.36735 20.73469 23.10204 25.46939 27.83673 30.20408 [8] 32.57143 34.93878 37.30612 39.67347 42.04082 44.40816 46.95918 [15] 49.57143 52.18367 54.79592 57.40816 60.02041 62.63265 65.24490 [22] 67.85714 70.46939 73.08163 75.69388 77.97959 79.93878 81.89796 [29] 83.85714 85.81633 87.77551 89.73469 91.69388 93.65306 95.61224 [36] 97.57143 99.53061 101.48980 103.44898 105.40816 107.36735 109.32653 [43] 111.28571 113.24490 115.20408 117.16327 119.12245 121.08163 123.04082 [50] 125.0 So my task is to find the value of x when y=0. I couldn't find guidance to use the xout function; any help with this please? approxfun(x,y,rule=2,method="linear") function (v) .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), as.integer(length(v)), as.integer(method), as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout Where do I go to find out the meaning of these errors and how to resolve? Yours, rh...@conference.jabber.org r 251 (27-06-07) mandriva 2008 __ R-help@r-project.org 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] interpolation to abscissa
If you want to just linearly interpolate, then use the functions approx or approxfun from the stats package (one of those that is loaded by default). See the function TkApprox in the TeachingDemos package for an interactive way to plot the approximations with the interpolations plotted. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > project.org] On Behalf Of e-letter > Sent: Thursday, January 08, 2009 9:22 AM > To: r-help@r-project.org > Subject: [R] interpolation to abscissa > > Readers, > > I have looked at various documents hosted on the web site; I couldn't > find anything on interpolation. So I started r and accessed the help > (help.start()). (by the way is it possible to configure r to open help > in opera instead of firefox?) Initially I read the help for the akima > package but couldn't understand it. Next I tried the asplines package > help. > > I tried to copy the example: x<-c(-3,-2,... > > I realised that the 'n=...' parameter determines the resolution of the > line, so I practised the following subsequent commands: > > > x<-c(-3,-2,-1,0,1,2,2.5,3) > > y<-c(0,0,0,0,-1,-1,0,2) > > plot(x,y,ylim=c(-3,3)) > > I get the graph as expected > > Then I enter further commands: > > lines(spline(x,y,n=200),col="blue") > lines(spline(x,y,n=20),col="blue") > lines(spline(x,y,n=2),col="blue") > lines(spline(x, y, n=5), col="blue") > > >From this I learn that n corresponds to line resolution. :) > > However I could not find a way to remove the last 3 commands and then > show only the first line. How do I achieve this please? > > I am learning this package in order to perform my next task; > interpolation. > > If I have a linear relationship between two variables and plot the > results, how do I manipulate the graph to be able to show a value of > the abscissa, especially for negative values, i.e. where the linear > line intersects the x axis left of the y axis? > > There are 4 packages that claim interpolation (akima, aspline, interp, > interpp) but they seem far to complicated, especially the latter two. > Is there a simpler package I could use? > > Yours, > > rh...@conference.jabber.org > > r 251 (27-06-07) > mandriva 2008 > > __ > R-help@r-project.org 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@r-project.org 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] interpolation to abscissa
Readers, I have looked at various documents hosted on the web site; I couldn't find anything on interpolation. So I started r and accessed the help (help.start()). (by the way is it possible to configure r to open help in opera instead of firefox?) Initially I read the help for the akima package but couldn't understand it. Next I tried the asplines package help. I tried to copy the example: x<-c(-3,-2,... I realised that the 'n=...' parameter determines the resolution of the line, so I practised the following subsequent commands: > x<-c(-3,-2,-1,0,1,2,2.5,3) > y<-c(0,0,0,0,-1,-1,0,2) > plot(x,y,ylim=c(-3,3)) I get the graph as expected Then I enter further commands: lines(spline(x,y,n=200),col="blue") lines(spline(x,y,n=20),col="blue") lines(spline(x,y,n=2),col="blue") lines(spline(x, y, n=5), col="blue") >From this I learn that n corresponds to line resolution. :) However I could not find a way to remove the last 3 commands and then show only the first line. How do I achieve this please? I am learning this package in order to perform my next task; interpolation. If I have a linear relationship between two variables and plot the results, how do I manipulate the graph to be able to show a value of the abscissa, especially for negative values, i.e. where the linear line intersects the x axis left of the y axis? There are 4 packages that claim interpolation (akima, aspline, interp, interpp) but they seem far to complicated, especially the latter two. Is there a simpler package I could use? Yours, rh...@conference.jabber.org r 251 (27-06-07) mandriva 2008 __ R-help@r-project.org 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] Interpolation Function f(y)
Thank you very much, You have helped me to resolve the problem. Thank you!! A greetings, Luismi Henrique Dallazuanna wrote: > > I think that you can use the splinefun function: > > f <- splinefun(x, y) > > f(15) > > On Thu, Sep 4, 2008 at 1:52 PM, ermimi <[EMAIL PROTECTED]> wrote: > >> >> Hello friends!!! >> >> I have a list of values called y. >> The list is y=c(221.0, 212.0, 206.0, 202.7, 198.4, 195.1, 192.2, 189.7, >> 187.6, 185.8); >> y is f(x) and x=c(10,20,30,40,50,60,70,80,90,100). >> >> I only have x and y. I don´t know f(x). I would like interpolate f(x) to >> obtain other values as f(15), f(25), f(35) and if it was possible obtain >> f(110), f(120). >> >> is there any function that allow me obtain this values?? >> >> Thank you very much, Luismi >> >> >> >> >> -- >> View this message in context: >> http://www.nabble.com/Interpolation-Function-f%28y%29-tp19314985p19314985.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@r-project.org 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. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org 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. > > -- View this message in context: http://www.nabble.com/Interpolation-Function-f%28y%29-tp19314985p19315377.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Interpolation Function f(y)
I think that you can use the splinefun function: f <- splinefun(x, y) f(15) On Thu, Sep 4, 2008 at 1:52 PM, ermimi <[EMAIL PROTECTED]> wrote: > > Hello friends!!! > > I have a list of values called y. > The list is y=c(221.0, 212.0, 206.0, 202.7, 198.4, 195.1, 192.2, 189.7, > 187.6, 185.8); > y is f(x) and x=c(10,20,30,40,50,60,70,80,90,100). > > I only have x and y. I don´t know f(x). I would like interpolate f(x) to > obtain other values as f(15), f(25), f(35) and if it was possible obtain > f(110), f(120). > > is there any function that allow me obtain this values?? > > Thank you very much, Luismi > > > > > -- > View this message in context: > http://www.nabble.com/Interpolation-Function-f%28y%29-tp19314985p19314985.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org 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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org 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] Interpolation Function f(y)
Hello friends!!! I have a list of values called y. The list is y=c(221.0, 212.0, 206.0, 202.7, 198.4, 195.1, 192.2, 189.7, 187.6, 185.8); y is f(x) and x=c(10,20,30,40,50,60,70,80,90,100). I only have x and y. I don´t know f(x). I would like interpolate f(x) to obtain other values as f(15), f(25), f(35) and if it was possible obtain f(110), f(120). is there any function that allow me obtain this values?? Thank you very much, Luismi -- View this message in context: http://www.nabble.com/Interpolation-Function-f%28y%29-tp19314985p19314985.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Interpolation Problems
Hi Steve, It could be the case that you are trying to find values that are not in the range of values you are providing. For example, x <- c(1,2,3,4,5) y <- c(10,11,12,13,14) xout <- c(0.01,0.02) approx(x,y,xout,method="linear") R's output: $x [1] 0.01 0.02 $y [1] NA NA If you want to see the value of 10 when you Xs are below 1 and 14 when the Xs are above 5, then code below may help. Regards, Pedro interpolation_test <- function(data,cum_prob,xout) { y <- vector(length=length(xout)) for(i in 1:length(xout)) { ValueToCheck <- xout[i] j <-1 while(cum_prob[j] < ValueToCheck && j < length(cum_prob) -2) { j <- j + 1 } y0 <- data[j] x0 <- cum_prob[j] y1 <- data[j+1] x1 <- cum_prob[j+1] if(x0==ValueToCheck) { y[i]<- y0 } else { y[i]<- y0 + (ValueToCheck-x0)*(y1-y0)/(x1-x0) } } return(y) } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Murray Sent: Monday, September 01, 2008 6:17 PM To: r-help@r-project.org Subject: [R] Interpolation Problems Dear all, I'm trying to interpolate a dataset to give it twice as many values (I'm giving the dataset a finer resolution by interpolating from 1 degree to 0.5 degrees) to match that of a corresponding dataset. I have the data in both a data frame format (longitude column header values along the top with latitude row header values down the side) or column format (in the format latitude, longitude, value). I have used Google to determine 'approxfun' the most appropriate command to use for this purpose - I may well be wrong here though! Nevertheless, I've tried using it with the default arguments for the data frame (i.e. interp <- approxfun(dataset) ) but encounter the following errors: > interp <- approxfun(JanAv) Error in approxfun(JanAv) : need at least two non-NA values to interpolate In addition: Warning message: In approxfun(JanAv) : collapsing to unique 'x' values However, there are no NA values! And to double-check this, I did the following: > JanAv[is.na(JanAv)] <- 0 ...to ensure that there really are no NAs, but receive the same error message each time. With regard to the latter 'collapsing to unique 'x' values', I'm not sure what this means exactly, or how to deal with it. Any words of wisdom on how I should go about this, or whether I should use an alternative command (I want to perform a simple (e.g. linear) interpolation), would be much appreciated. Many thanks for any advice offered, Steve __ R-help@r-project.org 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@r-project.org 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] Interpolation Problems
Steve Murray hotmail.com> writes: > > > Thanks Duncan - a couple of extra points... I should have perhaps pointed > out that the data are on a *regular* > 'box' grid (with each value currently spaced at 1 degree intervals). Also, > I'm looking for something > fairly simple, like a bilinear interpolation (where each new point is > created based on the values of the > four points surrounding it). > > In answer to your question, JanAv is simply the data frame of values. > And yes, you're right, I think I'll need > a 2D interpolation as it's a grid with latitude and longitude values > (which as an aside, I guess these need > to be interpolated differently? In a 1D format??). I think you're also > right in that the 'akima' package > isn't suitable for this job, as it's designed for irregular grids. Yes, interp() is not intended to points on grid lines. My suggestion would be to review the Spatial task view on CRAN, and possibly to post to the R-sig-geo list. Note that the metric may need to be spherical if you are close to the Poles. If you convert JanAv into a SpatialPointsDataFrame, with an appropriate CRS("+proj=longlat") coordinate reference system, and define a SpatialPixels object for the new grid, you may be able to use idw() in gstat with a very limited search radius to do a simple interpolation on the sphere. Roger > > Do you, or does anyone, have any suggestions as to what my best option > should be? > > Thanks again, > > Steve > __ R-help@r-project.org 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] Interpolation Problems
Thanks Duncan - a couple of extra points... I should have perhaps pointed out that the data are on a *regular* 'box' grid (with each value currently spaced at 1 degree intervals). Also, I'm looking for something fairly simple, like a bilinear interpolation (where each new point is created based on the values of the four points surrounding it). In answer to your question, JanAv is simply the data frame of values. And yes, you're right, I think I'll need a 2D interpolation as it's a grid with latitude and longitude values (which as an aside, I guess these need to be interpolated differently? In a 1D format??). I think you're also right in that the 'akima' package isn't suitable for this job, as it's designed for irregular grids. Do you, or does anyone, have any suggestions as to what my best option should be? Thanks again, Steve > Date: Mon, 1 Sep 2008 18:45:35 -0400 > From: [EMAIL PROTECTED] > To: [EMAIL PROTECTED] > CC: r-help@r-project.org > Subject: Re: [R] Interpolation Problems > > On 01/09/2008 6:17 PM, Steve Murray wrote: >> Dear all, >> >> I'm trying to interpolate a dataset to give it twice as many values (I'm >> giving the dataset a finer resolution by interpolating from 1 degree to 0.5 >> degrees) to match that of a corresponding dataset. >> >> I have the data in both a data frame format (longitude column header values >> along the top with latitude row header values down the side) or column >> format (in the format latitude, longitude, value). >> >> I have used Google to determine 'approxfun' the most appropriate command to >> use for this purpose - I may well be wrong here though! Nevertheless, I've >> tried using it with the default arguments for the data frame (i.e. interp <- >> approxfun(dataset) ) but encounter the following errors: >> >>> interp <- approxfun(JanAv) >> Error in approxfun(JanAv) : >> need at least two non-NA values to interpolate >> In addition: Warning message: >> In approxfun(JanAv) : collapsing to unique 'x' values >> >> >> However, there are no NA values! And to double-check this, I did the >> following: >> >>> JanAv[is.na(JanAv)] <- 0 >> >> ...to ensure that there really are no NAs, but receive the same error >> message each time. >> >> With regard to the latter 'collapsing to unique 'x' values', I'm not sure >> what this means exactly, or how to deal with it. >> >> >> Any words of wisdom on how I should go about this, or whether I should use >> an alternative command (I want to perform a simple (e.g. linear) >> interpolation), would be much appreciated. > > What is JanAv? approxfun needs to be able to construct x and y values > to interpolate; it may be that your JanAv object doesn't allow it to do > that. (The general idea is that it will consider y to be a function of > x, and will construct a function that takes arbitrary x values and > returns y values matching those in the dataset, with some sort of > interpolation between values.) > > If you really have longitude and latitude on some sort of grid, you > probably want a two-dimensional interpolation, not a 1-d interpolation > as done by approxfun. The interp() function in the akima() package does > this, but maybe not in the format you need. > > Duncan Murdoch __ R-help@r-project.org 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] Interpolation Problems
On 01/09/2008 6:17 PM, Steve Murray wrote: Dear all, I'm trying to interpolate a dataset to give it twice as many values (I'm giving the dataset a finer resolution by interpolating from 1 degree to 0.5 degrees) to match that of a corresponding dataset. I have the data in both a data frame format (longitude column header values along the top with latitude row header values down the side) or column format (in the format latitude, longitude, value). I have used Google to determine 'approxfun' the most appropriate command to use for this purpose - I may well be wrong here though! Nevertheless, I've tried using it with the default arguments for the data frame (i.e. interp <- approxfun(dataset) ) but encounter the following errors: interp <- approxfun(JanAv) Error in approxfun(JanAv) : need at least two non-NA values to interpolate In addition: Warning message: In approxfun(JanAv) : collapsing to unique 'x' values However, there are no NA values! And to double-check this, I did the following: JanAv[is.na(JanAv)] <- 0 ...to ensure that there really are no NAs, but receive the same error message each time. With regard to the latter 'collapsing to unique 'x' values', I'm not sure what this means exactly, or how to deal with it. Any words of wisdom on how I should go about this, or whether I should use an alternative command (I want to perform a simple (e.g. linear) interpolation), would be much appreciated. What is JanAv? approxfun needs to be able to construct x and y values to interpolate; it may be that your JanAv object doesn't allow it to do that. (The general idea is that it will consider y to be a function of x, and will construct a function that takes arbitrary x values and returns y values matching those in the dataset, with some sort of interpolation between values.) If you really have longitude and latitude on some sort of grid, you probably want a two-dimensional interpolation, not a 1-d interpolation as done by approxfun. The interp() function in the akima() package does this, but maybe not in the format you need. Duncan Murdoch __ R-help@r-project.org 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] Interpolation Problems
Dear all, I'm trying to interpolate a dataset to give it twice as many values (I'm giving the dataset a finer resolution by interpolating from 1 degree to 0.5 degrees) to match that of a corresponding dataset. I have the data in both a data frame format (longitude column header values along the top with latitude row header values down the side) or column format (in the format latitude, longitude, value). I have used Google to determine 'approxfun' the most appropriate command to use for this purpose - I may well be wrong here though! Nevertheless, I've tried using it with the default arguments for the data frame (i.e. interp <- approxfun(dataset) ) but encounter the following errors: > interp <- approxfun(JanAv) Error in approxfun(JanAv) : need at least two non-NA values to interpolate In addition: Warning message: In approxfun(JanAv) : collapsing to unique 'x' values However, there are no NA values! And to double-check this, I did the following: > JanAv[is.na(JanAv)] <- 0 ...to ensure that there really are no NAs, but receive the same error message each time. With regard to the latter 'collapsing to unique 'x' values', I'm not sure what this means exactly, or how to deal with it. Any words of wisdom on how I should go about this, or whether I should use an alternative command (I want to perform a simple (e.g. linear) interpolation), would be much appreciated. Many thanks for any advice offered, Steve __ R-help@r-project.org 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] Interpolation of data
Does this thread solve your problem? -> https://stat.ethz.ch/pipermail/r-help/2007-July/136814.html On 10-Jul-08, at 3:15 AM, [EMAIL PROTECTED] wrote: Hello, I have the data whcih are not balanced (several missing observations), and one possibility is t use interpolation method to get the information missing in this series from other series. Does anybody know how I can program interpolation of series1 (which ahs missing observations) and series 2-6, for example. Thanks a lot in advance, Silke __ R-help@r-project.org 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@r-project.org 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] Interpolation of data
Try help.search('interpolate') and help.search('impute') (most of the responses to the latter come from packages that you may not have installed, such as Hmisc) -Don At 8:15 AM +0200 7/10/08, [EMAIL PROTECTED] wrote: Hello, I have the data whcih are not balanced (several missing observations), and one possibility is t use interpolation method to get the information missing in this series from other series. Does anybody know how I can program interpolation of series1 (which ahs missing observations) and series 2-6, for example. Thanks a lot in advance, Silke __ R-help@r-project.org 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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org 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] Interpolation of data
if it is a time series the interpolation methods in zoo are an option. On Thu, Jul 10, 2008 at 6:41 AM, Daniel Malter <[EMAIL PROTECTED]> wrote: > > Please do read the posting guide. Please provide self-contained code (e.g. > to > randomly generate data) and illustrate (e.g. in a small table) what you > want > to do and also illustrate (with the self-contained code if any) what you > currently do so that we know why you fail. After reading your message, I > have only a very vague idea of what you are trying to do. You are trying to > fill in some data cells in a column with data from some other columns I > guess. But how precisely? > > Best, > Daniel > > > > sprohl wrote: > > > > Hello, > > > > I have the data whcih are not balanced (several missing observations), > > and one possibility is t use interpolation method > > to get the information missing in this series from other series. > > Does anybody know how I can program interpolation of > > series1 (which ahs missing observations) and series 2-6, > > for example. > > Thanks a lot in advance, > > Silke > > > > __ > > R-help@r-project.org 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. > > > > > > -- > View this message in context: > http://www.nabble.com/Interpolation-of-data-tp18378381p18380125.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org 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. > -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis [[alternative HTML version deleted]] __ R-help@r-project.org 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] Interpolation of data
Please do read the posting guide. Please provide self-contained code (calls to randomly generated data) and illustrate (e.g. in a small table) what you want to do and also illustrate (with the self-contained code) where your current approach (if any) fails. After reading your message, I have only a very vague idea of what you are trying to do. Best, Daniel sprohl wrote: > > Hello, > > I have the data whcih are not balanced (several missing observations), > and one possibility is t use interpolation method > to get the information missing in this series from other series. > Does anybody know how I can program interpolation of > series1 (which ahs missing observations) and series 2-6, > for example. > Thanks a lot in advance, > Silke > > __ > R-help@r-project.org 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. > > -- View this message in context: http://www.nabble.com/Interpolation-of-data-tp18378381p18380125.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Interpolation of data
Hello, I have the data whcih are not balanced (several missing observations), and one possibility is t use interpolation method to get the information missing in this series from other series. Does anybody know how I can program interpolation of series1 (which ahs missing observations) and series 2-6, for example. Thanks a lot in advance, Silke __ R-help@r-project.org 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] Interpolation between 2 vectors
Hello, I tried the approx() and it worked. Now, I have a list named "interpol" resulting from the interpolation. I would like to append the values in interpol$y in the position specified by interpol$x in a existing vector "spect1". I tried with append() and the following code: spect1 <- c(1:10909) for(i in 1:length(interpol$x)){ append(spect1,interpol$y[i],interpol$x[i]) } but it didn't work. Any idea? Best, Dani Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 En/na jim holtman ha escrit: > check out the 'approx' function. > > On Feb 19, 2008 12:44 PM, Dani Valverde <[EMAIL PROTECTED]> wrote: > >> Hello, >> I have two vectors, one with 13112 points and the other one with 10909. >> I wonder if there is a way to interpolate the data so the shorter >> vectors has the same number of points as the longer one. >> Best, >> Dani >> >> -- >> Daniel Valverde Saubí >> >> Grup de Biologia Molecular de Llevats >> Facultat de Veterinària de la Universitat Autònoma de Barcelona >> Edifici V, Campus UAB >> 08193 Cerdanyola del Vallès- SPAIN >> >> Centro de Investigación Biomédica en Red >> en Bioingeniería, Biomateriales y >> Nanomedicina (CIBER-BBN) >> >> Grup d'Aplicacions Biomèdiques de la RMN >> Facultat de Biociències >> Universitat Autònoma de Barcelona >> Edifici Cs, Campus UAB >> 08193 Cerdanyola del Vallès- SPAIN >> +34 93 5814126 >> >> __ >> R-help@r-project.org 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@r-project.org 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] Interpolation between 2 vectors
check out the 'approx' function. On Feb 19, 2008 12:44 PM, Dani Valverde <[EMAIL PROTECTED]> wrote: > Hello, > I have two vectors, one with 13112 points and the other one with 10909. > I wonder if there is a way to interpolate the data so the shorter > vectors has the same number of points as the longer one. > Best, > Dani > > -- > Daniel Valverde Saubí > > Grup de Biologia Molecular de Llevats > Facultat de Veterinària de la Universitat Autònoma de Barcelona > Edifici V, Campus UAB > 08193 Cerdanyola del Vallès- SPAIN > > Centro de Investigación Biomédica en Red > en Bioingeniería, Biomateriales y > Nanomedicina (CIBER-BBN) > > Grup d'Aplicacions Biomèdiques de la RMN > Facultat de Biociències > Universitat Autònoma de Barcelona > Edifici Cs, Campus UAB > 08193 Cerdanyola del Vallès- SPAIN > +34 93 5814126 > > __ > R-help@r-project.org 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org 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] Interpolation between 2 vectors
Hello, I have two vectors, one with 13112 points and the other one with 10909. I wonder if there is a way to interpolate the data so the shorter vectors has the same number of points as the longer one. Best, Dani -- Daniel Valverde Saubí Grup de Biologia Molecular de Llevats Facultat de Veterinària de la Universitat Autònoma de Barcelona Edifici V, Campus UAB 08193 Cerdanyola del Vallès- SPAIN Centro de Investigación Biomédica en Red en Bioingeniería, Biomateriales y Nanomedicina (CIBER-BBN) Grup d'Aplicacions Biomèdiques de la RMN Facultat de Biociències Universitat Autònoma de Barcelona Edifici Cs, Campus UAB 08193 Cerdanyola del Vallès- SPAIN +34 93 5814126 __ R-help@r-project.org 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] Interpolation across merged zoo columns
Maybe arima with the xreg= argument. On 10/11/07, Creighton, Sean <[EMAIL PROTECTED]> wrote: > Hi > > I have a collection of about 16 time series with occasional missing > data. A few of these time-series start later than the rest. There is a > relatively high correlation between them (they are hourly temps at > various locations around the UK). The longest series contains about > 4 points > > I have constructed each time series into a zoo object and then merged > each of these objects in to one (zoo is great!). Using na.approx I can > interpolate through a single column for the occasional missing data. Now > I would like to cross interpolate those series which start later than > the rest. > > I thought of reducing the collated zoo object down to a time span where > all columns where defined, then calculating a correlation matrix. Then > taking this matrix back to the larger collated zoo object and then > interpolating the missing values based on the correlations I have found. > I'm assuming correlation is stationary year to year. > > Has anybody tried anything like this? Is a function out there that could > help? > > Thanks > Sean > > > > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org 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@r-project.org 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] Interpolation across merged zoo columns
Hi I have a collection of about 16 time series with occasional missing data. A few of these time-series start later than the rest. There is a relatively high correlation between them (they are hourly temps at various locations around the UK). The longest series contains about 4 points I have constructed each time series into a zoo object and then merged each of these objects in to one (zoo is great!). Using na.approx I can interpolate through a single column for the occasional missing data. Now I would like to cross interpolate those series which start later than the rest. I thought of reducing the collated zoo object down to a time span where all columns where defined, then calculating a correlation matrix. Then taking this matrix back to the larger collated zoo object and then interpolating the missing values based on the correlations I have found. I'm assuming correlation is stationary year to year. Has anybody tried anything like this? Is a function out there that could help? Thanks Sean [[alternative HTML version deleted]] __ R-help@r-project.org 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.