similar to: extracting information from an object

Displaying 20 results from an estimated 50000 matches similar to: "extracting information from an object"

2013 Oct 14
1
Extracting elements of model output
I am having difficulty extracting specific results from the model object. The following code shows where I am stuck. I want to run resamplings of a data set. For each I want to extract a particular F for the contrasts. If I run a very simple model (e.g. model1 <- aov(time~group) ) I can get the relevant coefficients, for example, by using "model1$coefficients". That's fine.
2010 Apr 01
2
Adding regression lines to each factor on a plot when using ANCOVA
Dear R users, i'm using a custom function to fit ancova models to a dataset. The data are divided into 12 groups, with one dependent variable and one covariate. When plotting the data, i'd like to add separate regression lines for each group (so, 12 lines, each with their respective individual slopes). My 'model1' uses the group*covariate interaction term, and so the coefficients
2007 Jun 29
1
extracting df and MS values from aov
Dear R users, I would like to extract df and Mean Sq values. I tried several things (e.g., str(model1), names(model1)) but I can't find a way to extract these values. I also tried to search using RSiteSearch. Any help will be appreciated. Thanks Taka, model1<-aov(dv~iv.1*iv.2*iv.3) summary(model1) Df Sum Sq Mean Sq iv.1 1 3.200 3.200
2011 Sep 23
2
converting object elements to variable names and making subsequent assignments thereto
This has got to be incredibly simple but I nevertheless can't figure it out as I am apparently brain dead. I just want to convert the elements of a character vector to variable names, so as to then assign formulas to them, e.g: z = c("model1","model2"); I want to assign formulas, such as lm(y~x[,1]) and lm(y~x[,2]), to the variables "model1" and
2011 Sep 16
3
Help writing basic loop
Hello, I would like to write a loop to 1) run 100 linear regressions, and 2) compile the slopes of all regression into one vector. Sample input data are: y1<-rnorm(100, mean=0.01, sd=0.001) y2<-rnorm(100, mean=0.1, sd=0.01) x<-(c(10,400)) #I have gotten this far with the loop for (i in 1:100) { #create the linear model for each data set model1<-lm(c(y1[i],y2[i])~x)
2009 Apr 20
7
Fitting linear models
I am not sure if this is an R-users question, but since most of you here are statisticians, I decided to give it a shot. I am using the lm() function in R to fit a dependent variable to a set of 3 to 5 independent variables. For this, I used the following commands: >model1<-lm(function=PBW~SO4+NO3+NH4) Coefficients: (Intercept) SO4 NO3 NH4 0.01323 0.01968
2006 Sep 12
4
variables in object names
Is there any way to put an argument into an object name. For example, say I have 5 objects, model1, model2, model3, model4 and model5. I would like to make a vector of the r.squares from each model by code such as this: rsq <- summary(model1)$r.squared for(i in 2:5){ rsq <- c(rsq, summary(model%i%)$r.squared) } So I assign the first value to rsq then cycle through models 2 through
2008 Aug 25
1
How to run a model 1000 times, while saving coefficients each time?
Hello, We have written a program (below) to model the effect of a covariate on observed values of a response variable (using only 80% of the rows in our dataframe) and then use that model to calculate predicted values for the remaining 20% of the rows. Then, we compare the observed vs. predicted values using a linear model and inspect that model's coefficients and its R2 value. We wish
2012 Sep 14
2
when to use "I", "as is" caret
Dear community, I've check it while working, but just to reassure myself. Let's say we have 2 models: model1 <- lm(vdep ~ log(v1) + v2 + v3 + I(v4^2) , data = mydata) model2 <- lm(vdep ~ log(v1) + v2 + v3 + v4^2, data = mydata) So in model1 you really square v4; and in model2, v4*^2 *doesn't do anything, does it? Model2 could be rewritten: model2b <- lm(vdep ~
2011 Aug 15
2
MCMC regress, using runif()
Hello, just to follow up a question from last week. Here what I've done so far (here an example): library(MCMCpack) Y=c(15,14,23,18,19,9,19,13) X1=c(0.2,0.6,0.45,0.27,0.6,0.14,0.1,0.52) X2a=c(17,22,21,18,19,25,8,19) X2b=c(22,22,29,34,19,26,17,22) X2 <- function()runif(length(X2a), X2a, X2b) model1 <- MCMCregress(Y~X1+X2()) summary(model1) but I am not sure if my X2-function is
2009 Dec 18
1
linear contrasts for trends in an anova
Hi everybody, I'm trying to construct contrasts for an ANOVA to determine if there is a significant trend in the means of my groups. In the following example, based on the type of 2x3 ANOVA I'm trying to perform, does the linear polynomial contrast generated by contr.poly allow me to test for a linear trend across groups? doi=data.frame( Group=c( rep(1, 5), rep(2, 5), rep(3, 5),
2012 Mar 01
2
identifying a column name correctly to use in a formula
Hi, I have a large matrix (SNPs) that I want to cycle over with logistic regression with interaction terms. I have made a loop but I am struggling to identify to the formula the name of the column in a way which is meaningful to the formula. It errors becasue it is not evaluated proporly. (below is a pilot with only 7 to 33 columns, my actual has 200,000 columns) My attempts: for (i in 7:33)
2011 Oct 17
1
Plotting GEE confidence bands using "predict"
Hello Fellow R Users,I have spent the last week trying to find a work around to this problem and I can't seem to solve it. I simply want to plot my GEE model result with 95% confidence bands. I am using the geepack package to run a basic GEE model involving nestling weights, to a Gaussian distribution, with "exchangeable" error structure. I am examining how nestling weight varies
2009 Sep 17
1
Problems with the commands FUNCTION and DERIV to build a polynomial
Hi all, I need to automate a process in order to prepare a a big loop in the future but I have a problem with the *command function* First I fit a model with lm > model1<-lm(data2[,2]~data2[,1]+I(data2[,1]^2)+I(data2[,1]^3)+I(data2[,1]^4)) I extract the coefficients to build the polynomial. coef<-as.matrix(model1$coefficients) In the next step I need to define the polynomial to
2011 Feb 02
1
update not working
R-help, I'm using the "update" command for a multiple regression model and it is just not working: > update(model1, . ~ . – temp:wind:rad,data=ozone.pollution) Error: unexpected input in "model2<-update(model1, . ~ . –" > summary(model1) Call: lm(formula = ozone ~ temp * wind * rad + I(rad^2) + I(temp^2) + I(wind^2), data = ozone.pollution) Residuals:
2007 Mar 03
2
format of summary.lm for 2-way ANOVA
Hi, I am performing a two-way ANOVA (2 factors with 4 and 5 levels, respectively). If I'm interpreting the output of summary correctly, then the interaction between both factors is significant: ,---- | ## Two-way ANOVA with possible interaction: | > model1 <- aov(log(y) ~ xForce*xVel, data=mydataset) | | > summary(model1) | Df Sum Sq Mean Sq F value Pr(>F) |
2010 Oct 03
5
How to iterate through different arguments?
If I have a model line = lm(y~x1) and I want to use a for loop to change the number of explanatory variables, how would I do this? So for example I want to store the model objects in a list. model1 = lm(y~x1) model2 = lm(y~x1+x2) model3 = lm(y~x1+x2+x3) model4 = lm(y~x1+x2+x3+x4) model5 = lm(y~x1+x2+x3+x4+x5)... model10. model_function = function(x){ for(i in 1:x) { } If x =1, then the list
2008 Aug 22
1
filtering out data
Greetings, Apologies for such a simple question, but I have been trying to figure this out for a few days now (I'm quite new to R), have read manuals, list posts, etc., and not finding precisely what I need. I am accustomed to working in Stata, but I am currently working through the multilevel package right now. In Stata, I would include the statement "if model1 == 1" at the end
2012 Jun 19
1
Possible bug when using encomptest
Hello R-Help, ----------------------------------------------------------------------------------------------------------------------------------------- Issues (there are 2): 1) Possible bug when using lmtest::encomptest() with a linear model created using nlme::lmList() 2) Possible modification to lmtest::encomptest() to fix confusing fail when models provided are, in fact, nested. I have
2008 Aug 01
5
drop1() seems to give unexpected results compare to anova()
Dear all, I have been trying to investigate the behaviour of different weights in weighted regression for a dataset with lots of missing data. As a start I simulated some data using the following: library(MASS) N <- 200 sigma <- matrix(c(1, .5, .5, 1), nrow = 2) sim.set <- as.data.frame(mvrnorm(N, c(0, 0), sigma)) colnames(sim.set) <- c('x1', 'x2') # x1 & x2 are