mgcv

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")),

Error in if (more || nchar(output) > 80) when using mgcv

南楼画角 提交于 2019-12-11 02:43:02
问题 I have the same problem with this one but no solutions found yet . Error in if (more || nchar(output) > 80) { : missing value where TRUE/FALSE needed I am conducting analysis using the mgcv package. model1<-gam(fm_xsetz~total_pm2.5, data=analysis) I can get the results by using the summary(). But when I try to open the model in the global environment, I get the warning: Error in if (more || nchar(output) > 80) { : missing value where TRUE/FALSE needed Is anyone has the same problem? FYI,when

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

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

How to get confidence interval for smooth.spline?

孤者浪人 提交于 2019-12-06 08:44:35
问题 I have used smooth.spline to estimate a cubic spline for my data. But when I calculate the 90% point-wise confidence interval using equation, the results seems to be a little bit off. Can someone please tell me if I did it wrongly? I am just wondering if there is a function that can automatically calculate a point-wise interval band associated with smooth.spline function. boneMaleSmooth = smooth.spline( bone[males,"age"], bone[males,"spnbmd"], cv=FALSE) error90_male = qnorm(.95)*sd

Determining derivatives from GAM smooth object

只愿长相守 提交于 2019-12-06 05:28:53
问题 I have a quite simple time series data set consisting of annual averages of a singe variable ("AVERAGE"). I wish to investigate the rate of change (1st derivative) and acceleration (2nd derivative) and associated standard errors of the "trend" component of the time series. I have obtained the "trend" using the GAM and PREDICT functions of MGCV simply as follows: A <- gam(AVERAGE ~ s(YEAR), data=DF, na.action=na.omit) B <- predict(A, type="response", se.fit=TRUE) I have determined derivatives

How to get only the plots from gam.check

佐手、 提交于 2019-12-06 00:36:54
问题 This question was migrated from Cross Validated because it can be answered on Stack Overflow. Migrated 5 years ago . When applying gam.check in the mgcv package, R produces some residual plots and basis dimension output. Is there a way to only produce the plots and not the printed output? library(mgcv) set.seed(0) dat <- gamSim(1,n=200) b <- gam(y~s(x0)+s(x1)+s(x2)+s(x3), data=dat) plot(b, pages=1) gam.check(b, pch=19, cex=.3) 回答1: There are four plots, from top left, moving down and across

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

余生长醉 提交于 2019-12-04 18:24:28
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+Echinoidea$se))) + scale_x_continuous(limits=c(min(Echinoidea$Year-0.125), max(Echinoidea$Year+0.125)))