#2개년(use: df_3 , MSE: 0.02313121)
#선형회귀모델
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% step(direction = "both")
Error in length(obj) : class name too long in 'length'
Once the code has been executed, it will be executed normally. However, if you change the data set and run it again, the same error occurs when you run the first code again. What's the problem? I went to the registry editing window and changed the value of 'LongPathsEnabled' to 1, but it was not resolved. Please solve the problem.
I had the sample problem when using stepwise regression with the step function. In my case there was some package conflict and all was fine after I specified stats::step(...) as follows:
lm2 <- lm(data = df_3, formula = OPS_y1 ~ (OPS_y2+OPS_y3 + AVG_y2+AVG_y3 + G_y2+G_y3 + GW.RBI_y2+GW.RBI_y3 + H_y2+H_y3 + SAC_y2+SAC_y3)^2) %>% stats::step(direction = "both")
As pointed out by user12282991, the problem may be due to package conflicts. The error most probably results from attaching the package recipes, which masks "step" from package:stats. Thus, stepAIC from package MASS or stats::step works.
library(recipes)
step(subclass = paste(rep("A",1000),collapse=""))
gives
Error in (function (x, ...) : class name too long in 'print'.
Related
I'm trying to run a path analysis using the piecewiseSEM package. When I try to run summary or coefs(), I get this error:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
or:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
I have no idea what "object ret is. There is nothing in my code named "ret". My spelling is correct. All I have is a model list I called "mod" with two mixed models. The codes I tried to use are below:
mod <- psem(modn, modm)
summary(mod, standardize = "scale", conserve = TRUE)
#####
coefs(mod)
I have to run this as soon as possible and there is no one else to help me. I would really appreciate any comments. Please remember I'm not a skilled programmer so, I'll quote Michael Scott: "Explain this to me like I'm five." lol
Thank you.
modn<-lmer(Nestedness ~ (Category+Prop_ex+Connectance+Assimetry+N_Pol+N_Pla+Dist_eq) + (1|Eco_code), data = sem)
modm<-lmer(Modularity ~ (Category+Connectance+Assimetry+Prop_ex+Dist_eq+N_Pla+N_Pol) + (1|Eco_code),data = sem)
#try 1
mod <- psem(
lmer(Nestedness ~ (Category+Prop_ex+Connectance+Assimetry+N_Pol+N_Pla+Dist_eq) + (1|Eco_code), data = sem),
lmer(Modularity ~ (Category+Connectance+Assimetry+Prop_ex+Dist_eq+N_Pla+N_Pol) + (1|Eco_code),data = sem),
data = sem)
coefs(mod)
#try2
mod <- psem(modn, modm)
summary(mod, standardize = "scale", conserve = TRUE)
Resulting error:
Error in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
in cbind(ret, isSig(ret[, 5])) : object 'ret' not found
I'm trying to run a functional data analysis model with scalar-on-function and on scalar regression in R. But by removing the intercept I'm getting the following error (the example is based on this discussion),
library(refund)
data(DTI)
DTI1 <- DTI[DTI$visit==1 & complete.cases(DTI),]
par(mfrow=c(1,2))
fit_af <- pfr(pasat ~ -1 +sex + case + af(cca, k=c(5, 8), bs="ps"), data = DTI1)
#Error in str2lang(x) : <text>:1:9: unexpected symbol
#1: pasat~0 sex
# ^
#Calls: pfr -> formula -> formula.character -> str2lang
How can I remove the intercept from a pfr model?
This is a bug. Running prf() in the debugging mode identifies the problem. When there is no intercept, it does:
if (!attr(tf, "intercept")) {
newfrml <- paste(newfrml, "0", sep = "")
}
which I think should be fixed to
if (!attr(tf, "intercept")) {
newfrml <- paste(newfrml, "0 +", sep = "")
}
Consider reporting this Stack Overflow thread, i.e., https://stackoverflow.com/q/72856108 to package maintainer Julia Wrobel: julia.wrobel#cuanschutz.edu
Note: This was tested using the latest refund_0.1-26 to date (released to CRAN on 2022-04-16).
This data is from an excel CSV file.
I want to see if a transformation is necessary, but my problem is that I keep getting this message:
Error in model.frame.default(formula = comment$Number.of.Comments ~ comment$Character.Count + : 'data' must be a data.frame, environment, or list
The following is my code:
comment <- read.csv('AdAnalysis3.csv', header = TRUE, fileEncoding = "UTF-8-BOM")
commentfit <- lm(comment$Number.of.Comments ~ comment$Character.Count + comment$Number.of.Shares + comment$Number.of.Likes + comment$Type.of.Ad + comment$Dealing.with.Life + comment$Christlike.Attributes + comment$Spiritual.Learning, data = comment)
library(car)
boxCox(commentfit)
I get the following message immediately after boxCox(commentfit):
Any suggestions?
You haven't given us a reproducible example, but my guess is that you have confused car::boxCox() by including comment$ in your formula. In general it's better (for a number of reasons including clarity) to specify a linear model with just the variable names, i.e.:
commentfit <- lm(Number.of.Comments ~ Character.Count + Number.of.Shares +
Number.of.Likes + Type.of.Ad + Dealing.with.Life +
Christlike.Attributes + Spiritual.Learning,
data = comment)
I am trying to implement a new nonlinear function to use in nlmer function in lme4 package. But I'm not sure what the problem is. This is the first time I'm trying to use nlmer but I'm following all the instructions I've found on the internet. The first error is about my dataframe.
data <- read.csv(paste("C:/Users/oguz/Desktop/Runs4SiteModels/db/", "DB4NLSiteModel", Periods[i],".txt", sep=""), sep = "", header = TRUE)
psa_rock <- data$PSAr
nparams <- c("c")
nonl_fn <- deriv(~ log(( psa_rock + c)/c),
namevec = c("c"),
function.arg=c("c", psa_rock))
fm <- nlmer(log(data$PSAm) ~ nonl_fn(c, psa_rock) ~ 1 + data$M1 + data$M3 + data$M85 + data$Nflag + data$Rflag + data$FDepth +
data$Dist1 + data$Dist3 + data$VN + (exp(-1*exp(2*log(data$Vs)- 11)) * log((data$PSAr + c) / c) ) +
(1|data$EQID) + (1|data$STID), data=data, start=c(c=0.1))
When I run this code, I'm getting the following error:
Error in model.frame.default(data = data, drop.unused.levels = TRUE, formula = log(data$PSAm) ~ :
invalid type (list) for variable 'data'
which I wasn't getting it while using lmer function (of course without the nonlinear function). That's why I'm thinking my problem is not about my dataframe.
Other issue that I couldn't stop thinking about, the part in the fixed-effects:
(exp(-1*exp(2*log(data$Vs)- 11)) * log((data$PSAr + c) / c) )
as you can see my nonlinear function also takes a part in my fixed-effects formula and I'm not quite sure how to implement that. I hope my way is correct but because of my first problem, I couldn't find an opportunity to test that.
I have been trying to do stepwise selection on my variables with R. This is my code:
library(lattice)#to get the matrix plot, assuming this package is already installed
library(ftsa) #to get the out-of sample performance metrics, assuming this package is already installed
library(car)
mydata=read.csv("C:/Users/jgozal1/Desktop/Multivariate Project/Raw data/FINAL_alldata_norowsunder90_subgroups.csv")
names(mydata)
str(mydata)
mydata$country_name=NULL
mydata$country_code=NULL
mydata$year=NULL
mydata$Unemployment.female....of.female.labor.force...modeled.ILO.estimate.=NULL
mydata$Unemployment.male....of.male.labor.force...modeled.ILO.estimate.=NULL
mydata$Life.expectancy.at.birth.male..years.= NULL
mydata$Life.expectancy.at.birth.female..years. = NULL
str(mydata)
Full_model=lm(mydata$Fertility.rate.total..births.per.woman. + mydata$Immunization.DPT....of.children.ages.12.23.months. + mydata$Immunization.measles....of.children.ages.12.23.months. + mydata$Life.expectancy.at.birth.total..years. + mydata$Mortality.rate.under.5..per.1000.live.births. + mydata$Improved.sanitation.facilities....of.population.with.access. ~ mydata$Primary.completion.rate.female....of.relevant.age.group. + mydata$School.enrollment.primary....gross. + mydata$School.enrollment.secondary....gross. + mydata$School.enrollment.tertiary....gross. + mydata$Internet.users..per.100.people. + mydata$Primary.completion.rate.male....of.relevant.age.group. + mydata$Mobile.cellular.subscriptions..per.100.people. + mydata$Foreign.direct.investment.net.inflows..BoP.current.US.. + mydata$Unemployment.total....of.total.labor.force...modeled.ILO.estimate., data= mydata)
summary(Full_model) #this provides the summary of the model
Reduced_model=lm(mydata$Fertility.rate.total..births.per.woman. + mydata$Immunization.DPT....of.children.ages.12.23.months. + mydata$Immunization.measles....of.children.ages.12.23.months. + mydata$Life.expectancy.at.birth.total..years. + mydata$Mortality.rate.under.5..per.1000.live.births. + mydata$Improved.sanitation.facilities....of.population.with.access. ~1,data= mydata)
step(Reduced_model,scope=list(lower=Reduced_model, upper=Full_model), direction="forward", data=mydata)
step(Full_model, direction="backward", data=mydata)
step(Reduced_model,scope=list(lower=Reduced_model, upper=Full_model), direction="both", data=mydata)
This is the link to the dataset that I am using: http://speedy.sh/YNXxj/FINAL-alldata-norowsunder90-subgroups.csv
After setting the scope for my stepwise I get this error:
Error in step(Reduced_model, scope = list(lower = Reduced_model, upper = Full_model), :
number of rows in use has changed: remove missing values?
In addition: Warning messages:
1: In add1.lm(fit, scope$add, scale = scale, trace = trace, k = k, :
using the 548/734 rows from a combined fit
2: In add1.lm(fit, scope$add, scale = scale, trace = trace, k = k, :
using the 548/734 rows from a combined fit
I have looked at other posts with the same error and the solutions usually is to omit the NAs from the data used, but that hasn't solved my problem and I am still getting exactly the same error.