gam

xlim not working in plot.gam in mgcv

南笙酒味 提交于 2019-12-13 04:42:09
问题 The mgcv package in R lets you estimate smooth regressions on multiple variables. Here is an example: library(mgcv) set.seed(2) ## simulate some data... dat = gamSim(1,n=400,dist="normal",scale=2) mod = gam(y~te(x0, x1),data=dat) par(mfrow = c(2,1)) plot(mod) plot(mod, xlim = c(0, 0.5)) When I run this, the two plots look exactly the same. Why doesn't xlim = c(0, 0.5) restrict the range of the horizontal axis? How can I achieve this? Update on my session info: > sessionInfo() R version 3.0.1

Custom Link function works for GLM but not mgcv GAM

老子叫甜甜 提交于 2019-12-12 13:15:49
问题 Apologies if the answer is obvious but I've spent quite some time trying to use a custom link function in mgcv.gam In short, I want to use a modified probit link from package psyphy ( I want to use psyphy.probit_2asym, I call it custom_link ) I can create a {stats}family object with this link and use it in the 'family' argument of glm. m <- glm(y~x, family=binomial(link=custom_link), ... ) It does not work when used as an argument for {mgcv}gam m <- gam(y~s(x), family=binomial(link=custom

How to use 2 different functions in 2 different libraries that have the same name

泪湿孤枕 提交于 2019-12-11 06:14:45
问题 I'm trying to explore the difference in how the "gam" function works in the mgcv package versus the gam package. But, I'm not able to run both gam functions in one R session. I thought if I preface with mgcv::gam or gam::gam it would be able to run the right function, but it looks like I have to detach mgcv in order to run the gam function in the gam package. library(ISLR) library(mgcv) library(gam) # I get an error message when it runs this gam.m3 <- gam::gam(wage~s(year,4)+s(age,5)

Rough thin-plate spline fitting (thin-plate spline interpolation) in R with mgcv

泪湿孤枕 提交于 2019-12-11 04:37:27
问题 Background I am trying to replicate figure 2.6 in the book An Introduction to Statistical Learning: A rough thin-plate spline fit to the Income data from Figure 2.3. This fit makes zero errors on the training data. What have I tried so far? I tried to replicate the previous figure 2.5, a smooth thin-plate spline fit, not sure if succesfully. income_2 <- read.csv("http://www-bcf.usc.edu/~gareth/ISL/Income2.csv") library(mgcv) model1 <- gam(Income ~ te(Education, Seniority, bs=c("tp", "tp")),

GAM with “gp” smoother: how to retrieve the variogram parameters?

我们两清 提交于 2019-12-11 01:46:13
问题 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") Here I am using an exponential covariance function with range = 10 and power = 1 ( m=c(2,10,1) ). How can I retrieve from the results the variogram parameters (nugget, sill)? I couldn't find anything

Namespace specifier on gam package does not work

假装没事ソ 提交于 2019-12-10 23:07:59
问题 I don't understand why the below two gam models produce different results. The only difference is in one of the models I added the namespace specifier gam:: before the functions gam and s . I want to do this because I am exploring the differences between running the gam function in the gam package and in the mgcv package. library(ISLR) library(gam) gam.m3 <- gam::gam(wage ~ gam::s(year,4) + gam::s(age,5) + education,data=Wage) gam.m3.orig <- gam(wage ~ s(year,4) + s(age,5) + education, data

Error in gam function in names(x) <- value: 'names' attribute must be the same length as the vector

依然范特西╮ 提交于 2019-12-10 17:32:18
问题 I am using the mgcv package to model the ozone pollution concentration according to some environmental covariates. The model takes the form : model1 <- gam(O3 ~ s(X, Y, bs = "tp", k = 10) + wd + s(date, bs = "cc", k = 100) + district, data = mydata, family = gaussian(link ="log"), na.action = "na.omit", method = "REML") And here is the structure of covariates: > str(mydata) 'data.frame': 7100 obs. of 286 variables: $ date : Date, format: "2016-01-01" "2016-01-01" "2016-01-01" ... $ O3 : num 0

Error in 1:object$nsdf : argument of length 0 when using plot.gam [duplicate]

蹲街弑〆低调 提交于 2019-12-10 14:14:07
问题 This question already has answers here : R plot.gam Error “Error in 1:object$nsdf : argument of length 0” (2 answers) Closed last year . I am seeing the error message when trying to plot a gam object in R: Error in 1:object$nsdf : argument of length 0 I am using the basic command: plot(myGamObject) This error is not specific to any data I am using as it also comes up at the end of the routine: example(gam) For completeness, here is some sample code: library(ISLR) library(gam) gam7 <- gam(wage

Getting adjusted r-squared value for each line in a geom_smooth gam

耗尽温柔 提交于 2019-12-09 23:56:01
问题 I produced the below graph using ggplot2. PlotEchi = ggplot(data=Echinoidea, aes(x=Year, y=mean, group = aspect, linetype = aspect, shape=aspect)) + geom_errorbar(aes(ymin=mean-se, ymax=mean+se), width=.025, position=pd) + geom_point(position=pd, size=2) + geom_smooth(method = "gam", formula = y~s(x, k=3), se=F, size = 0.5,colour="black") + xlab("") + ylab("Abundance (mean +/- SE)") + facet_wrap(~ species, scales = "free", ncol=1) + scale_y_continuous(limits=c(min(y=0), max(Echinoidea$mean

Error returned predicting new data using GAM with periodic smoother

我只是一个虾纸丫 提交于 2019-12-08 04:07:38
问题 Apologies if this is better suited in CrossValidated. I am fitting GAM models to binomial data using the mgcv package in R. One of the covariates is periodic, so I am specifying the bs = "cc" cyclic cubic spline. I am doing this in a cross validation framework, but when I go to fit my holdout data using the predict function I get the following error: Error in pred.mat(x, object$xp, object$BD) : can't predict outside range of knots with periodic smoother Here is some code that should replicate