Re: [R] Create a function problem

2021-05-14 Thread Mathew Guilfoyle
Have you tried putting the a,b, and c column names you are passing in quotes i.e. as strings? Currently your function is expecting separate objects with those names. The select function itself can accept unquoted column names, as can others in R, because specific processing they do in the backg

Re: [R] change frequency of wind data correctly

2020-12-06 Thread Mathew Guilfoyle
Hi Stefano I think either of these does what you need... 1: This gets the interval column as you want it, but utilises the lubridate package: library(lubridate) mydf$interval = ceiling_date(mydf$data_POSIX, unit="30 minutes”) 2: Alternative in base R is a bit more long winded: convert the da

Re: [R] struggling with apply

2020-05-27 Thread Mathew Guilfoyle
A bit quicker: t(pmin(t(somematrix), UB)) > On 27 May 2020, at 20:56, Bert Gunter wrote: > > Jeff: Check it! > >> somematrix <- matrix(c(1,4,3,6,3,9,12,8,5,7,11,11),nrow=3,ncol=4) >> UB=c(2.5, 5.5, 8.5, 10.5) >> apply( somematrix, 2, function( x ) pmin( x, UB ) ) > [,1] [,2] [,3] [,4] >

[R] mgcv::gamm error when combining random smooths and correlation/autoregressive term

2018-04-18 Thread Mathew Guilfoyle
I am having difficulty fitting a mgcv::gamm model that includes both a random smooth term (i.e. 'fs' smooth) and autoregressive errors. Standard smooth terms with a factor interaction using the 'by=' option work fine. Both on my actual data and a toy example (below) I am getting the same error

Re: [R] R help

2018-03-31 Thread Mathew Guilfoyle
When i increments to 6 (during the fifth iteration) the subsequent test of x[i]<=5 will produce an error since x has only five elements. > On 31 Mar 2018, at 14:45, Henri Moolman wrote: > > Could you please provide help with something from R that I find rather > puzzling? In the small program b

[R] mgcv::gam is it possible to have a 'simple' product of 1-d smooths?

2018-01-17 Thread Mathew Guilfoyle
I am trying to test out several mgcv::gam models in a scalar-on-function regression analysis. The following is the 'hierarchy' of models I would like to test: (1) Y_i = a + integral[ X_i(t)*Beta(t) dt ] (2) Y_i = a + integral[ F{X_i(t)}*Beta(t) dt ] (3) Y_i = a + integral[ F{X_i(t),t} dt ]

[R] mgcv::gam is it possible to have a 'simple' product of 1-d smooths?

2018-01-17 Thread Mathew Guilfoyle
I am trying to test out several mgcv::gam models in a scalar-on-function regression analysis. The following is the 'hierarchy' of models I would like to test: (1) Y_i = a + integral[ X_i(t)*Beta(t) dt ] (2) Y_i = a + integral[ F{X_i(t)}*Beta(t) dt ] (3) Y_i = a + integral[ F{X_i(t),t} dt ]

Re: [R] correlation between nominal and ordinal

2017-09-01 Thread Mathew Guilfoyle
Any of the usual rank correlation methods should be fine if you're expecting a monotonic relationship e.g. Spearman's rho or Kendall's tau. > On 1 Sep 2017, at 21:25, merlinverde...@infomed.sld.cu wrote: > > I would be very grateful if you would tell me how I can find the degree of > correlatio

Re: [R] R Programming help needed - Returning dataframes + 2 Variables dynamically

2017-07-28 Thread Mathew Guilfoyle
The returned values are in the list you assign to test_data, the original x and y are not modified, i.e the returned value for x will be test_data[[1]] and for y will be test_data[[2]]. Using the same variable names in the function and test is perhaps what is leading to confusion. > On 28 Jul

Re: [R] Problem in shiny writing a .txt file

2017-07-19 Thread Mathew Guilfoyle
Is res.path usually empty? If the res.path directory is empty (i.e. dir(res.path) is an empty vector) the file.remove operation will remove the directory. This behaviour is documented in the help for file.remove. When your subsequent function tries to write to that directory it does not exist

[R] mgcv gam/bam model selection with random effects and AR terms

2017-04-08 Thread Mathew Guilfoyle
Would be grateful for advice on gam/bam model selection incorporating random effects and autoregressive terms. I have a multivariate time series recorded on ~500 subjects at ~100 time points. One of the variables (A) is the dependent and four others (B to E) are predictors. My basic formula i

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Mathew Guilfoyle
This does the summation you want in one line: #create example data and column selection d = as.data.frame(matrix(rnorm(50),ncol=5)) cols = c(1,3) #sum selected columns and put results in new row d[nrow(d)+1,cols] = colSums(d[,cols]) However, I would agree with the sentiments that this is a bad i

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-18 Thread Mathew Guilfoyle
If you are strict about your data formatting then the following is a fast way of calculating the differences, based on reshaping the data column: A = matrix(mydata$rslt, nrow=2) data.frame(exp=1:ncol(A), diff=A[2,]-A[1,]) alternatively, if the 'exp' values are not guaranteed to be sequential you

Re: [R] Matrix

2017-03-06 Thread Mathew Guilfoyle
Effectively you want a circulant matrix but filled by column. Example input vector and number of columns x = c(1:8,19:20) nc = 5 For the result you specifically describe, the following generalises for any vector and any arbitrary number of columns 'nc', padding with zeros as necessary. matrix

[R] gamm problem/error fitting smooth by factor

2016-12-26 Thread Mathew Guilfoyle
I have a (unbalanced) dataset of time series collected across several subjects (n~500, ~6 observations). I would like to model the overall smooth time trend of a variable and how this trend differs by various categorical factors, with the subject as a random effect. My baseline model m1