mgcv

Assign polygon to data point in R dataframe

喜欢而已 提交于 2021-02-08 04:04:10
问题 I have a two data frames: points contains a series of points with x, y coordinates. poly contains coordinates of two polygons (I have over 100 in reality, but keeping it simple here). I want to be able to add to the dataframe points an extra column called Area which contains the name of the polygon the point is in. poly <- data.frame( pol= c("P1", "P1","P1","P1","P1","P2","P2","P2","P2", "P2"), x=c(4360, 7273, 7759, 4440, 4360, 8720,11959, 11440,8200, 8720), y=c(1009, 9900,28559,28430,1009

mgcv: How to use 'exclude' argument in predict.gam?

微笑、不失礼 提交于 2020-11-28 08:26:19
问题 I have a model structured as follows, and I would like to extract the predicted values while ignoring the random effect. As specified in ?predict.gam and here, I am using the exclude argument, but I am getting an error. Where is my mistake? dt <- data.frame(n1 = runif(500, min=0, max=1), n2 = rep(1:10,50), n3 = runif(500, min=0, max=2), n4 = runif(500, min=0, max=2), c1 = factor(rep(c("X","Y"),250)), c2 = factor(rep(c("a", "b", "c", "d", "e"), 100))) mod = gam(n1 ~ s(n2, n3, n4, by=c1) + s(c2

mgcv: How to use 'exclude' argument in predict.gam?

北战南征 提交于 2020-11-28 08:23:37
问题 I have a model structured as follows, and I would like to extract the predicted values while ignoring the random effect. As specified in ?predict.gam and here, I am using the exclude argument, but I am getting an error. Where is my mistake? dt <- data.frame(n1 = runif(500, min=0, max=1), n2 = rep(1:10,50), n3 = runif(500, min=0, max=2), n4 = runif(500, min=0, max=2), c1 = factor(rep(c("X","Y"),250)), c2 = factor(rep(c("a", "b", "c", "d", "e"), 100))) mod = gam(n1 ~ s(n2, n3, n4, by=c1) + s(c2

Caret package - cross-validating GAM with both smooth and linear predictors

独自空忆成欢 提交于 2020-08-21 18:37:06
问题 I would like to cross validate a GAM model using caret. My GAM model has a binary outcome variable, an isotropic smooth of latitude and longitude coordinate pairs, and then linear predictors. Typical syntax when using mgcv is: gam1 <- gam( y ~ s(lat , long) + x1 + x2, family = binomial(logit) ) I'm not quite sure how to specify this model using the train function in caret. This is my syntax more or less: cv <- train(y ~ lat + long + x1 + x2, data = data, method = "gam", family = "binomial",

Why is bam from mgcv slow for some data?

删除回忆录丶 提交于 2020-05-25 18:39:18
问题 I am fitting the same Generalized Additive Model on multiple data sets using the bam function from mgcv . While for most of my data sets the fit completes within a reasonable time between 10 and 20 minutes. For a few data sets the run take more than 10 hours to complete. I cannot find any similarities between the slow cases, the final fit is neither exceptionally good nor bad, nor do they contain any noticeable outliers. How can I figure out why the fit is so slow for these instances? And how

Why is bam from mgcv slow for some data?

ぐ巨炮叔叔 提交于 2020-05-25 18:38:35
问题 I am fitting the same Generalized Additive Model on multiple data sets using the bam function from mgcv . While for most of my data sets the fit completes within a reasonable time between 10 and 20 minutes. For a few data sets the run take more than 10 hours to complete. I cannot find any similarities between the slow cases, the final fit is neither exceptionally good nor bad, nor do they contain any noticeable outliers. How can I figure out why the fit is so slow for these instances? And how

GAM with “gp” smoother: predict at new locations

不羁的心 提交于 2020-01-30 08:04:40
问题 I am using the following geoadditive model library(gamair) library(mgcv) data(mack) mack$log.net.area <- log(mack$net.area) gm2 <- gam(egg.count ~ s(lon,lat,bs="gp",k=100,m=c(2,10,1)) + s(I(b.depth^.5)) + s(c.dist) + s(temp.20m) + offset(log.net.area), data = mack, family = tw, method = "REML") How can I use it to predict the value of egg.count at new locations (lon/lat) where I don't have covariate data, as in kriging ? For example say I want to predict egg.count at these new locations lon

Are there known compatibility issues with R package mgcv? Are there general rules for compatibility?

旧街凉风 提交于 2020-01-03 13:04:12
问题 I use R version 2.15.1 (2012-06-22) and mgcv version 1.7-22 I load the following set of packages in R: library(sqldf) library(timeDate) library(forecast) library(xts) library(tseries) library(MASS) library(mgcv) It happens that I can not run a simple model (I omit the code). Even the sample code taken from the help pages: dat = gamSim(1,n=400,dist="normal",scale=2) b = gam(y~s(x0)+s(x1)+s(x2)+s(x3),data=dat) gives an error: Error in qr.qty(qrc, sm$S[[l]]) : NA/NaN/Inf in foreign function call

Using broom and tidyverse to summarise r squared gams

穿精又带淫゛_ 提交于 2020-01-02 11:16:12
问题 I posted a question here and was able to reproduce Claus' answer to calculate multiple r-squared values for each species in an additive model using tidyverse on iris data. However, an update occurred for packages and now R-sq values are not being calculated. Not sure why... Here are clause response and output library(tidyverse) library(broom) iris %>% nest(-Species) %>% mutate(fit = map(data, ~mgcv::gam(Sepal.Width ~ s(Sepal.Length, bs = "cs"), data = .)), results = map(fit, glance), R.square

mgcv gam() error: model has more coefficients than data

末鹿安然 提交于 2020-01-01 07:13:43
问题 I am using GAM (generalized additive models) for my dataset. This dataset has 32 observations, with 6 predictor variables and a response variable (namely power). I am using gam() function of the mgcv package to fit the models. Whenever, I try to fit a model I do get an error message as: Error in gam(formula.hh, data = data, na.action = na.exclude, : Model has more coefficients than data From this error message, I infer that I have more predictor variables as compared to the number of