[R] For each entry type in column?

2017-11-06 Thread mviljamaa
How can I do a for loop that does to a data.frame column what: for x in xs: does in Python? Obviously the data.frame column in question holds "levels". What if the data.frame is in matrix form? BR, Matti __ R-help@r-project.org mailing list -- To

[R] How to solve "nlm() non-finite value supplied by 'nlm'" and how to constrain parameters to (0, 1)?

2017-04-02 Thread mviljamaa
So I'm getting: Error in nlm(neglikhood, p = c(0.1, 0.1), hessian = T, x = elinajat) : non-finite value supplied by 'nlm' In addition: There were 50 or more warnings (use warnings() to see the first 50) with the following (neglikelihood of 1-param. Weibull): neglikhood <- function(theta,x)

[R] How is label parameter used in text() when passing it a vector?

2016-10-20 Thread mviljamaa
I have a slight doubt with using text() with the label parameter having to contain a vector of of integers (specifically integers in the range [1, 21] corresponding to factors of my categorical variable that I want to numbers to tell). What I'm currently plotting is the following command:

[R] How to use predict() so that one retains the rows that they're associated with?

2016-10-20 Thread mviljamaa
I'm using predict() for my glm() logistic model, but I'm having trouble relating the predicted results to the rows that produced them. I want to be able to plot predictions along some categorical variables. So what can I do in order to get predicted values but also know what variable values

[R] How to read prediction intervals given by predict()?

2016-10-15 Thread mviljamaa
My conception of prediction intervals is the following: "a prediction interval gives an interval within which we expect next y_i to lie with a specified probability" So when using predict() for my model: predict(fit4, interval="prediction")[1:20,] I get: fit lwr upr 1

[R] What does lm() output coefficient mean when it's been given a categorical predictor of string values?

2016-10-04 Thread mviljamaa
I'm using lm() for a model that has a predictor that has two values {poika, tyttö} (boy and girl in Finnish). I make a model with this categorical variable: fit1 <- lm(dta$X.U.FEFF..mpist. ~ dta$sukup + dta$HISEI + dta$SES) and while the variable/vector is here named as dta$sukup, what lm()

[R] Can I get odd ratios from lm() model or only glm()?

2016-10-02 Thread mviljamaa
I'm doing logistic regression and I need to infer the coefficients as odds ratios. I first did my model using lm(), but now that I need odd ratios, then should I have used glm() like displayed here: http://r.789695.n4.nabble.com/Odds-ratio-from-Logistic-model-in-R-td2630277.html

Re: [R] curve() doesn't seem to use the whole range of x? And Error: longer object length is not a multiple of shorter object length

2016-09-25 Thread mviljamaa
-reproducible-example -- Sent from my phone. Please excuse my brevity. On September 25, 2016 8:36:49 AM PDT, mviljamaa <mvilja...@kapsi.fi> wrote: On 2016-09-25 18:30, Duncan Murdoch wrote: On 25/09/2016 9:10 AM, Matti Viljamaa wrote: Writing: bs["(Intercept)"]+bs["mies&quo

Re: [R] curve() doesn't seem to use the whole range of x? And Error: longer object length is not a multiple of shorter object length

2016-09-25 Thread mviljamaa
On 2016-09-25 18:30, Duncan Murdoch wrote: On 25/09/2016 9:10 AM, Matti Viljamaa wrote: Writing: bs["(Intercept)"]+bs["mies"]*0+bs["kouluB"]+bs["lka"]*lka+bs["kouluB:clka"]*clka i.e. without that being inside curve produces a vector of length 375. So now it seems that curve() is really

[R] Why removing the (Intercept) from lm is done by adding -1?

2016-09-21 Thread mviljamaa
So I found out that to remove the (Intercept) term from lm's model one can add -1 to the predictors. I.e. do lm(resp ~ x1 + x2 - 1) Another way is to add 0, e.g. lm(resp ~ 0 + x1 + x2). Adding (or setting the (Intercept) term) zero seems more logical than subtracting one, but why is there the

[R] Using lm's subset parameter results in Error in xj[i] : invalid subscript type 'list'

2016-09-20 Thread mviljamaa
I'm trying to take lm on a subset of my dataset and to do this I believe I need to pass my subset of the data as the subset parameter of lm. So I do my subsetting: firstkids <- kidmomhsage[0:234,], i.e. the first 234 rows of the data frame. Then construct the model: fit4 <-

[R] Overlapping axis numbering and labels when using par(new=TRUE)?

2016-09-19 Thread mviljamaa
I'm trying to plot two data sets on the same plot by using par(new=TRUE). However this results in the axis numbering and labels being plotted twice as seen in the following picture: http://i.imgur.com/4b1sNIc.png How can I get the axis numbering and labels to not overlap? I could also

Re: [R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-19 Thread mviljamaa
Do you mean that the red line is a regression line? Why is the regression (line) weighted? On 2016-09-19 14:41, S Ellison wrote: What are the red line and cut line in lm's Residuals vs Fitted plot? The dotted line is at 0 and the red line is a locally weighted regression calculated using

Re: [R] How are interaction terms computed in lm's result / problems with interaction terms in lm?

2016-09-18 Thread mviljamaa
On Sep 18, 2016, at 11:01 AM, mviljamaa <mvilja...@kapsi.fi> wrote: Also if you, rather than doing what's done below, do: fit3 <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age * kidmomhsage$mom_hs) Then this gives the result: Call: l

Re: [R] How are interaction terms computed in lm's result / problems with interaction terms in lm?

2016-09-18 Thread mviljamaa
391? On 2016-09-18 20:41, mviljamaa wrote: I'm trying to use interaction terms in lm and for the following types of models: fit3_hs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age * 1) fit3_nohs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + ki

[R] How are interaction terms computed in lm's result / problems with interaction terms in lm?

2016-09-18 Thread mviljamaa
I'm trying to use interaction terms in lm and for the following types of models: fit3_hs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age * 1) fit3_nohs <- lm(kidmomhsage$kid_score ~ kidmomhsage$mom_age + kidmomhsage$mom_hs + kidmomhsage$mom_age *

[R] How to plot the regression line of multivariable linear model?

2016-09-18 Thread mviljamaa
I'm having a bit of trouble plotting the regression line of multivariable linear model. Specifically my model has one response and two predictors, i.e. it's of the form Y = b_0+b_1*X_1+b_2*X_2 Plotting the regression line for a single predictor model Y = b_0+b_1*X_1 is simple enough, just

[R] What are the red line and cut line in lm's Residuals vs Fitted plot?

2016-09-18 Thread mviljamaa
What are the red line and cut line in lm's Residuals vs Fitted plot? As seen in e.g.: http://i.imgur.com/QvZ6oeT.png __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

[R] Is this kind of removing of elements from data.frame (in)efficient?

2016-09-13 Thread mviljamaa
So I'm a beginner in R and I was testing the removal of elements from a data.frame. The way I remove the element(s) with the minimum value in kid_score variable is to do: kidmomhs <- data[kidmomhs$kid_score != min(kidmomhs$kid_score),] So now kidmomhs is the same data, but without the

[R] Where to get quantiles (1st parameter q) for pnorm? (Normal approximation to binomial distribution)

2016-01-20 Thread mviljamaa
I'm doing Normal approximation to binomial distribution. My variables are generated by rbinom. Here: http://msemac.redwoods.edu/~darnold/math15/spring2013/R/Activities/ApproxBinomWithNorm.html it's claimed that normal approximation is done using the command pnorm. Question: Where to get

[R] Separating lines in ts.plot()?

2015-11-29 Thread mviljamaa
I'm using ts.plot() to plot a matrix of time series (each column is a ts). What I noticed is that ts.plot() creates a lot of overlapping lines which makes it difficult to distinguish different series. What options exist for making the series more easily read?

[R] Using uniroot on c(0, 1) when the function does not change sign in this interval?

2015-11-28 Thread mviljamaa
How can I use uniroot to find a root in the interval (0,1) when my function does not change sign in this interval. I've tried plugging in some values and seems like e.g. f(50) < 0 and then I can pick c(0,50). But this sounds really weird, given that I need to find a root in (0,1). So what