When I'm fitting a generalized linear model, I use the  function like this:  fit &lt;- glm(formula=y ~ x,             data=someFrame,             family=gaussian(link="log"))   But I don't know, what does the name of the family mean. It's described like this in the :  Family objects provide a convenient way to specify the details of the models used by functions such as glm. See the documentation for glm for the details on how such model fitting takes place.   But still, I don't know, what is it exactly. Is it an estimated distribution of observed data?
94280
When modeling data sampled in the field, I often come across the problem of determining the Family of the dependent variable for GLM (or GLMM). An example: in an ecological study, I have ~ 60 patches.  I have sampled territories of an animal species within these patches as well as a set of explanatory variables.  The number of territories per patch (NTP) is the dependent variable in a GLM.   NTP is integer with values between 0 and 14:      How can I test for the family of NTP?  Any help appreciated as this is an issue many ecologists come across each time they conduct statistical analysis.
26061
Suppose I have a $2 \times 2$ table that looks like:             Disease       No Disease Treatment         55                67 Control           42                34  I would like to do a logistic regression in R on this table. I understand that the standard way is to use the glm function with a cbind function in the response. In other words, the code looks like: glm(formula = cbind(c(55,67),c(42,34)) ~ as.factor(c(1, 0)), family = binomial())  I am wondering why R requires us to use the cbind function and why simply using proportions is not sufficient. Is there a way to write this out explicitly as a formula? What would it look in the form of: $$ log\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1X $$ where $X = 1$ if we have treatment and $X=0$ for control? Right now it seems like I am regressing on a matrix for the dependent value.
41443
As the title to my question says, I am confused as to when the $R^2$ of a model fit does not equal the slope of the regression between observed and predicted values.   I am trying to present model prediction statistics in a similar way to those presented in the summary figures of the Globcolor validation report () - (e.g. figure from page 53 of the .pdf):    Here we see that they present the plot of observed versus predicted Chlorophyll concentrations, as well as statistics relating to its regression (e.g. the dashed line: $R^2$, $RMS$, $\alpha$ - intercept, and $\beta$ - slope).   My issue is that in my comparisons, I always get exactly the same value for the overall model fit $R^2$ and $\beta$-slope of the observed versus predicted regression.  Basic question: When (if ever) can these be different?  I have included a basic example of my problem in the following R script:  set.seed(1) n &lt;- 100 x &lt;- runif(n) e &lt;- rnorm(n) a &lt;- 3 b &lt;- 5 y &lt;- a + x*b + e  #fit model fit &lt;- lm( y ~ x )  #plot regression plot(x,y) abline(fit)  #plot predicted versus observed png("plot.png", units="in", width=5, height=5, res=400) par(mar=c(5,5,1,1)) pred &lt;- predict(fit) plot(y, pred, xlim=range(c(y,pred)), ylim=range(c(y,pred)), xlab="observed", ylab="predicted") abline(0,1, lwd=2, col=8)  #add regression fit2 &lt;- lm(pred ~ y) lgd &lt;- c(     paste("R^2 =", round(summary(fit2)$r.squared,3)),     paste("Offset =", round(coef(fit2)[1],3)),     paste("Slope =", round(coef(fit2)[2],3)) ) legend("topleft", legend=lgd) abline(fit2, lwd=2) legend("bottomright", legend=c("predicted ~ observed", "1:1"), col=c(1,8), lty=1, lwd=2)  dev.off()  cor(pred, y)^2 # also the same
113453
I'm taking an intro to statistics class and currently we are covering linear regression. The course is good but unfortunately it doesn't always gives all the information that is needed. For example it gives formulas for the slope and y-intercept as  $b=(r)\frac{s_Y}{s_X}=\frac{n \sum{xy} - \sum{x} \sum{y}}{n \sum{x^2} - (\sum{x})^2}$ , where  $r$ is the correlation coefficient  $s_Y$ is the standard deviation of the $Y$ scores  $s_X$ is the standard deviation of the $X$ scores   and  $a = \bar{y} - b \bar{x} = \frac{\sum{y} - b \sum{x}}{n}$  However it doesn't explain why the formulas are what they are. In other words it doesn't explain how these formulas where derived. Can someone show the derivation, especially the one for the slope, $b$, i.e. why $b=(r) \frac{s_Y}{s_X}$?  Any help is appreciated.
119408
I am trying to fit generalized linear model for weibull family, but when I try it in R, it gives an error. I know that weibull does not fit in exponential family, but I have read some research articles about fitting GLM for weibull family. If anyone can help me with this, I really appreciate.  It gives the following error.   &gt; data(lung) &gt; glm(time ~ age+sex+ph.ecog+ wt.loss, family = weibull(link='log'), data = lung) Error in glm(time ~ age + sex + ph.ecog + wt.loss, family = weibull(link = "log"),  :    could not find function "weibull"
27355
Let's take the following example:  set.seed(342) x1 &lt;- runif(100) x2 &lt;- runif(100) y &lt;- x1+x2 + 2*x1*x2 + rnorm(100) fit &lt;- lm(y~x1*x2)   This creates a model of y based on x1 and x2, using a OLS regression.  If we wish to predict y for a given x_vec we could simply use the formula we get from the summary(fit).  However, what if we want to predict the lower and upper predictions of y? (for a given confidence level).  How then would we build the formula?
43248
How should I define a model formula in R, when one (or more) exact linear restrictions binding the coefficients is available. As an example, say that you know that b1 = 2*b0 in a simple linear regression model.
34138
Say I have some historical data e.g., past stock prices, airline ticket price fluctuations, past financial data of the company...  Now someone (or some formula) comes along and says "let's take/use the log of the distribution" and here's where I go WHY?  Questions:   WHY should one take the log of the distribution in the first place? WHAT does the log of the distribution 'give/simplify' that the original distribution couldn't/didn't? Is the log transformation 'lossless'? I.e., when transforming to log-space and analyzing the data, do the same conclusions hold for the original distribution? How come? And lastly WHEN to take the log of the distribution? Under what conditions does one decide to do this?   I've really wanted to understand log-based distributions (for example lognormal) but I never understood the when/why aspects - i.e., the log of the distribution is a normal distribution, so what? What does that even tell and me and why bother? Hence the question!  UPDATE: As per @whuber's comment I looked at the posts and for some reason I do understand the use of log transforms and their application in linear regression, since you can draw a relation between the independent variable and the log of the dependent variable. However, my question is generic in the sense of analyzing the distribution itself - there is no relation per se that I can conclude to help understand the reason of taking logs to analyze a distribution. I hope I'm making sense :-/  In regression analysis you do have constraints on the type/fit/distribution of the data and you can transform it and define a relation between the independent and (not transformed) dependent variable. But when/why would one do that for a distribution in isolation where constraints of type/fit/distribution are not necessarily applicable in a framework (like regression). I hope the clarification makes things more clear than confusing :)  This question deserves a clear answer as to "WHY and WHEN"
26802
I am looking for guidelines on how to interpret residual plots of glm models.  Especially poisson, negative binomial, binomial models.  What can we expect from these plots when the models are "correct"? (for example, we expect the variance to grow as the predicted value increases, for when dealing with a Poisson model)  I know the answers depend on the models.  Any references (or general points to consider) will be helpful/appreciated.
83737
I have developed different non-linear models, all of them follow the following formula: y=b0 + b1*(x1)^b2 + b3*(x2)^b4 where y is the dependent variable;x1 and x2 are independent variables;b0, b1, b2, b3, and b4 are the estimated regression coefficients. different values of b0, b1, b2, b3, and b4 have been estimated with different R-square and adjusted R-square. All estimated regression coefficients in all models are positive, the range of all estimated values are between 0.001-5 the difference only in the combinations of regression coefficient values in the models. by example : model 1 : y= 2.5 + 0.01*(x1)^2 + 0.2*(x2)^0.5 model 2 : y= 2.3 + 0.005*(x1)^3 + 0.25*(x2)^0.4 I estimated the regression coefficients based on the Gauss-newton method and by assuming different initial values for the regression coefficient for each run (model). how to select the best model based on anything except R-square? how to determine the goodness of fit for these models?
78696
I always have a hard time explaining statistical techniques to audience with no statistical background. If I wanted to explain what GLM is to such audience (without throwing out statistical jargon), what would be the best or most effective way?  I usually explain GLM with three parts -- (1) the random component which is response variable, (2) the systematic component which is linear predictors, and (3) the link function which is the "key" to connecting (1) and (2). Then I would give an example of linear or logistic regression and explain how the link function is selected based on the response variable. Hence it acts as the key connecting two components.
59799
Let's say I have an outcome that is exponentially distributed, so $p(y|\lambda_i) = \lambda_i e^{-\lambda_i y}$. However, we also know that $\log{\lambda_i} = \beta_0+\beta_1x_i$. If we want to estimate the MLE's for $\beta_0$ and $\beta_1$, what's the best way to do it given data?  I was thinking of using the following code:  summary(glm(y~x,family=Gamma(link="log")))   Not 100% sure what the various arguments are going though.
74005
Top is Poisson, bottom is Binomial Source of variation is different people observed over a week long period. 118 people to be exact.  want to make predictions about the proportion of days/week one exercises if they wake up at a given time.  &gt; summary(FMR7)  Call: glm(formula = No.Days.Ex ~ WaketimeStand, family = poisson, data = PSD)  Deviance Residuals:       Min        1Q    Median        3Q       Max   -2.99043  -0.64677  -0.03492   0.67393   1.51943    Coefficients:               Estimate Std. Error z value Pr(&gt;|z|)     (Intercept)    1.36991    0.04689  29.218   &lt;2e-16 *** WaketimeStand -0.08309    0.04806  -1.729   0.0839 .   --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  (Dispersion parameter for poisson family taken to be 1)      Null deviance: 124.55  on 115  degrees of freedom Residual deviance: 121.51  on 114  degrees of freedom AIC: 479.71  Number of Fisher Scoring iterations: 4  &gt; summary(FMR6)  Call: glm(formula = cbind(No.Days.Ex, No.Days.NotEx) ~ WaketimeStand,      family = quasibinomial(link = logit), data = PSD)  Deviance Residuals:      Min       1Q   Median       3Q      Max   -3.7483  -0.9585  -0.0625   1.0428   2.9739    Coefficients:               Estimate Std. Error t value Pr(&gt;|t|)   (Intercept)     0.2595     0.1009   2.571   0.0114 * WaketimeStand  -0.1869     0.1020  -1.832   0.0695 . --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1  (Dispersion parameter for quasibinomial family taken to be 2.015388)      Null deviance: 288.42  on 115  degrees of freedom Residual deviance: 281.57  on 114  degrees of freedom AIC: NA  Number of Fisher Scoring iterations: 4  Quite clear that there is much more overdispersion on the quasibinomial than the poisson. The response variable is no.days exercise per week and so my original thought was to analyse with binomial GLM as it is the proportion of days in a week someone exercises. However, when modelled with a Poisson GLM it is much less overdispersed. Is this a sign I am using the wrong distribution.
54503
I have been discussing with several lab members about this one, and we have gone to several sources but still don't quite have the answer:  When we say a GLM has a family of poisson let's say are we talking about the distribution of the residuals or the response variable?  Points of contention   Reading  article it states that the assumptions of the GLM are The statistical independence of observations, the correct specification of the link and variance function (which makes me think about the residuals, not the response variable), the correct scale of measurement for response variable and lack of undue influence of single points  question has two answers with two points each, the one that appears first talks about the residuals, and the second one about the response variable, which is it? In this , when talking about assumptions, they state "The distribution of the residuals can be other, eg, binomial" At the beginning of  chapter they say that the structure of the errors has to be Poisson, but the residuals will surely have positive and negative values, how can that be Poisson?  question, which often is cited in questions such as this one to make them duplicated does not have an accepted answer  question the answers talk about response and not residuals In  course description from the University of Pensilvania they talk about the response variable in the assumptions, not  the residuals
74312
uses generalised linear models (both binomial and negative binomial error distributions) to analyse data. But then in the statistical analysis section of the methods, there is this statement:     ...and second by modelling the presence data using Logistic Regression   Models, and the foraging time data using a Generalized Linear Model   (GLM). A negative binomial distribution with a log link function was   used to model the foraging time data (Welsh et al. 1996) and model   adequacy was verified by examination of resi- duals (McCullagh &amp;   Nelder 1989). Shapiro–Wilk or Kolmogorov–Smirnov tests were used to   test for normality depending on sample size; data were log-transformed   before analyses to adhere to normality.   If they assume binomial and negative binomial error distributions, then surely they shouldn't be checking for normality of residuals?
40303
I am trying to model vegetation spectral signatures (grey lines) using a two-part piecewise function (black dotted lines). In it, I am trying to use only a few points (red dots) to fit a linear (first part) and logistic function (second part). Basically, the linear part of the function stretches a bit further than the second point (how much it stretches, it will depend on &quot;unknown&quot; parameters, but as a rule of thumb I use 35 &quot;X&quot; units). I currently defined an ifelse function and I am applying a constrained optimization (optim, method=&quot;L-BFGS-B&quot;), to find the best parameter values. This has a few handicaps, as the parameters are not normalized/scaled (which makes the search routine less efficient) logistic.fun&lt;- function(K, C, ro, b, Z, a, lambda){       ifelse(test = lambda &lt;= Seq_Bands[2]+25,             yes = a + b*((Seq_Bands[2]+25)- lambda),            no = ((ro*K)/((ro + (K-ro)*exp(-C*(lambda-Seq_Bands[2]+Z))))))}  I would be keen to use nls and fit a 3 parameters logistic regression and also use a fourth parameter to estimate the breakpoint of the linear part (Z parameter code above). Also, I would be keen to avoid jumps such as those seen on left plot below. This means that the functions would have to be differentiable (?) at this breakpoint. I am unsure how to code it. Cheers and thanks!   UPDATE: It was correctly pointed out that the number of variables is higher than the data points presented; which would render the problem under-determined. Consequently, the logistic equation can only be parameterized using 3 variables (Fig 2: R_0_ , K and r. My understanding is that, necessarily, the breakpoint (Z) cannot be estimated, and should be set prior to the optimization process. In context, it is also important to state that the R_0_, and K are not &quot;truly&quot; unknowns, as they are expressed by the measurements (second and fourth red datapoints).
719
I have made a generalised linear model with a single response variable (continuous/normally distributed) and 4 explanatory variables (3 of which are factors and the fourth is an integer). I have used a Gaussian error distribution with an identity link function. I am currently checking that the model satisfies the assumptions of the generalised linear model, which are:   independence of Y correct link function correct scale of measurement of explanatory variables no influential observations   My question is: how can I check that the model satisfies these assumptions? The best starting point would seem to be plotting the response variable against each explanatory variable. However, 3 of the explanatory variables are categorical (with 1-4 levels), so what should I be looking for in the plots?  Also, do I need to check for multicollinearity and interactions amongst explanatory variables? If yes, how do I do this with categorical explanatory variables?